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

Consider this C code that defines five integer variables and assigns a result to

ID: 3666319 • Letter: C

Question

Consider this C code that defines five integer variables and assigns a result to a. Assume the values of variables w, x y, and z have already been loaded from memory into registers $s0, $sl, $s2, and $s3, respectively. Assume we are associating variable a with register $t0. Write the MIPS instructions not a complete program that implements the assignment statement. Store temporary values in unused $t registers. Your solution will require eight assembly language instructions: two div, two mflo, one mul, one addi, one sub, and one add. For full credit, document each line of code by writing a comment that explains what the instruction is doing.

Explanation / Answer

div   $s0, $s1
mflo $t1           # $t1 = w / x
div $s2, $s3
mfhi $t2           # $t2 = y % z
addi $t3, $r0, 5   # $t3 = 0 + 5 = 5
sub $t3, $t3, $s0   # $t3 = 5 - w
mult $t1, $t2
mflo $t1           # $t1 = $t1 * $t2 = (w / x) * (y % z)
add $t0, $t1, $t3   # $t0(a) = $t1 + t3 = (w / x) * (y % z) + (5 - w)