Exam Questions and CORRECT Answers
For the following C statement, what is the corresponding MIPS assembly code? Assume that the
variables f, g, h, and i are given and could be considered 32-bit integers as declared in a C
program. Use a minimal number of MIPS assembly instructions.
f = g + (h − 5); - CORRECT ANSWER addi i ,h, -5
add f, g, i
For the following MIPS assembly instructions above, what is a corresponding C statement?
add f, g, h add f, i, f - CORRECT ANSWER add f,g,h
add f,i,f
For the following C statement, what is the corresponding MIPS assembly code? Assume that the
variables f, g, h, i, and j are assigned to registers $s0, $s1, $s2, $s3, and $s4, respectively.
Assume that the base address of the arrays A and B are in registers $s6 and $s7, respectively.
B[8] = A[i−j]; - CORRECT ANSWER sub $s5, $s2, $s3
sll $s5,$s5,2
add $s5,$s6,$s5
lw $s6, 0($s5)
św $s6, 32 $(s7)
For the MIPS assembly instructions below, what is the corresponding C statement? Assume that
the variables f, g, h, i, and j are assigned to registers $s0, $s1, $s2, $s3, and $s4, respectively.
Assume that the base address of the arrays A and B are in registers $s6 and $s7, respectively.
sll $t0, $s0, 2 # $t0 = f * 4
add $t0, $s6, $t0 # $t0 = &A[f]
sll $t1, $s1, 2 # $t1 = g * 4
add $t1, $s7, $t1 # $t1 = &B[g]
lw $s0, 0($t0) # f = A[f]
, addi $t2, $t0, 4
lw $t0, 0($t2)
add $t0, $t0, $s0
sw $t0, 0($t1) - CORRECT ANSWER B[g] = A[f] + A[1+f];
For the following C statement, write a minimal sequence of MIPS assembly instructions that
does the identical operation. Assume $t1 = A, $t2 = B, and $s1 is the base address of C.
A = C[0] << 4; - CORRECT ANSWER lw $t3, 0($s1)
sll $t1, $t3, 4
Assume $t0 holds the value 0x00101000. What is the value of $t2 after the following
instructions?
slt $t2, $0, $t0
bne $t2, $0, ELSE
j DONE
ELSE: addi $t2, $t2, 2
DONE: - CORRECT ANSWER $t2 = 3
What is 5ED4 - 07A4 when these values represent unsigned 16- bit hexadecimal numbers? The
result should be written in hexadecimal. Show your work. - CORRECT ANSWER 5730
Convert 5ED4 into a binary number. What makes base 16 (hexadecimal) an attractive numbering
system for representing values in computers? - CORRECT ANSWER 0101 1110 1101 0100
What is 4365 - 3412 when these values represent unsigned 12-bit octal numbers? The result
should be written in octal. Show your work. - CORRECT ANSWER 7777 = 111 111 111 111
Assume 185 and 122 are unsigned 8-bit decimal integers. Calculate 185 - 122. Is there overflow,
underflow, or neither? - CORRECT ANSWER 63, Neither.