



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




Name: ___________________________ Student Number: ______________________ 1) Given 4 bits to represent data in memory, what is the range of signed integers that can be represented if two’s complement representation is used? (5 points) Also, what is the binary representation for -9? ( points) range: (-8) – 7 -9 can’t be represented using only 4 bits and using 2’s complement representation 2) Given 4 bits to represent data in memory, what is the range of signed integers that can be represented if sign-and-magnitude representation is used? (5 points) Also, what is the binary representation for -1? ( points) range: (-7) – 7 -1 = 1001 3) Give the 8-bit representation of the numbers -10 and 100 in sign-and-magnitude and two’s complement representations and show how each representation is sign-extended to 16 bits. (10 points) sign-and-magnitude (-10): 1000 1010 sign extended: 1000 0000 0000 1010 two’s complement (-10): 1111 0110 sign extended: 1111 1111 1111 0110 sign-and-magnitude (100): 0110 0100 sign extended: 0000 0000 0110 0100 two’s complement (100): 0110 0100 sign extended: 0000 0000 0110 0100 4) Given that a program executes on computer A in 7 seconds. This particular program performs both floating point and integer operations. The floating point operations make up 40% of the total execution time of the program on machine A. Machine B incorporates new floating point hardware that can improve the time for floating point operations. By what amount does machine B need to improve the floating point operations of machine A in order to achieve a new execution time of 5 seconds? (10 points)
5) Draw a 1-bit ALU capable of performing or supporting the instructions AND, OR, ADD, SUB, SLT. Show all data and control lines. (10 points) Then, draw a 4-bit ALU using an abstraction for the 1-bit
device you designed in part one of this question. Again, show all data and control lines. (10 points) Finally, complete a table showing all the values for the control signals needed to implement each of the instructions. (5 points)
So, machine 1 is 1.36 times faster than machine 2. 8) Reverse engineer the MIPS assembly code from the following machine code given in hexadecimal. ( points) 01 0C 80 24 and $s0, $t0, $t 9) Given the following C code and the assumptions, write the MIPS assembly for the calling function and the subroutine. Assume that variable a is allocated to register $s1, variable b is allocated to register $s2, variable c is allocated to register $s3, variable max is allocated to register $s4, variable m is allocated to register $s1, all input and output parameters are allocated according to the conventions used in MIPS assembly, and finally that any temporary registers needed will be allocated to a temporary register ($t0 - $t9). Preserve only those registers that must be preserved across the subroutine call. The MIPS assembly must be CORRECT assembly language instructions. NO Pseudo-instructions are allowed. (20 points) int maximum (int x, int y, int z) { int m; if ((x >= y) && (x >= z)) m = x; else if ((y >= x) && (y >= z)) m = y; else if ((z >= x) && (z >= y)) m = z; return (m); } void main (void) { int a, b, c, max; … max = maximum(a, b, c) … } main: add $a0, $zero, $s add $a1, $zero, $s add $a2, $zero, $s jal maximum add $s4, $zero, $v j done maximum: addi $sp, $sp, - sw $s1, 0($sp) slt $t0, $a0, $a slt $t1, $a0, $a or $t2, $t0, $t beq $t2, $zero, returnx
slt $t0, $a1, $a slt $t1, $a1, $a or $t2, $t0, $t beq $t2, $zero, returny slt $t0, $a2, $a slt $t1, $a2, $a or $t2, $t0, $t beq $t2, $zero, returnz returnx: add $v0, $a0, $zero j exit returny: add $v0, $a1, $zero j exit returnz: add $v0, $a2, $zero j exit exit: lw $s1, 0($sp) addi $sp, $sp, 4 jr $ra done:
11) Identify which addressing mode is used by each of the following instructions, and describe how the addressing mode creates the address of the operand(s). (4 points each) a) j label Pseudodirect addressing; 26 bits of immediate data in instructions is concatenated with top 4 bits of PC to create jump destination (word relative) b) ori $s0, $s1, 4 Immediate addressing; operand is in the instruction itself c) lw $s0, 0 ($s1) Base/displacement addressing; contents of base register ($s1) are added to immediate data in the instruction to get address of operand d) bne $t0, $t1, label PC-relative addressing; PC + 4 is added to immediate data in instructions to create address for branch (word relative)