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

4) This problem deals with translating from MIPS to C. Assume that the variables

ID: 2267881 • Letter: 4

Question

4) This problem deals with translating from 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. For the assembly instructions below, what is the corresponding C statement(s)? sll $to, $s0, 2 add $t0, $s6, $t0 sll $tl, $s1, 2 add $tl, $s7, $tl lw $so, $0 ($t0) addi $t2, $to, 4 add $t0, to, $sO b. Rewrite the above MIPS assembly code to minimize the number of assembly instructions (to the extent possible) to implement the same function. c. Compare the number of registers being used between the given code and the code which you attempted to minimize for its instruction count.

Explanation / Answer

a) C code:

f=A[f]

f=A[f+1]+A[f]

B[g]=f

b). sll $t0,$s0,2

add $t0,$s6,$t0

sll $t1,$s1,2

add $t1,$s7,$t1

lw $s0,0($t0)

lw $t0,4($t0)

add $t0,$t0,$s0

sw $t0,0($t1)

C). $t2 register is not used in the modified instructions. there are 7 registers used in the given MIPS instructions, but in the modified instructions 6 registers only used.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote