Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The following problems deal with translating MIPS to C. Assume that the variable

ID: 3647593 • Letter: T

Question

The following problems deal with translating MIPS to C. 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.

a. slli $s2, $s4, 1
add $s0, $s2, $s3
add $s0, $s0, $s1

b. add $t0, $s6, $s0
add $t1, $s7, $s1
lw $s0, 0($t0)
addi $t2, $t0, 4
lw $t0, 0($t2)
add $t0, $t0, $s0
sw $t0, 0($t1)

How many registers are needed to carry out the MIPS assembly written above? If you could rewrite the code above, what is the minimal number of registers needed?

Explanation / Answer

Equivalent C code: f=f+g f=f+h f=f+i f=f+j f=A(1)