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

a. f = f + g + h + i + j + 2; b. f = g - (f + 5); a) For the C statements above,

ID: 3616681 • Letter: A

Question

a. f = f + g + h + i + j + 2; b. f = g - (f + 5); a) For the C statements above, what is the corresponding MIPSassembly code? Use a minimal number of MIPS assemblyinstructions. b) For the C statements above, how many MIPS assemblyinstructions are needed to perform the C statement? c) If the variables f, g, h, i, and j have values 1, 2, 3, 4,and 5, respectively, what is the end value of f? a. f = f + g + h + i + j + 2; b. f = g - (f + 5); a) For the C statements above, what is the corresponding MIPSassembly code? Use a minimal number of MIPS assemblyinstructions. b) For the C statements above, how many MIPS assemblyinstructions are needed to perform the C statement? c) If the variables f, g, h, i, and j have values 1, 2, 3, 4,and 5, respectively, what is the end value of f?

Explanation / Answer

a) add t0, f, g    #temporary variable t0contains f+g

   add t1, h, i    #temporary variablet1 contains h+i

addi t2, j, 2   #temporary variable t2 containsj+2

add t1, t1, t2 #t1 contains t1+t2 which is (h + i)+(j + 2)

     addi t2, j, 2  

    add t1, t1, t2

    add f, t0, t1

f = f + g + h + i + j +2

t0 = f + g = 1 + 2 = 3

t1 = h + i = 3 + 4 = 7

t2 = j + 2 = 5 + 2 = 7

t1 = t1+ t2 = 7 + 7 =14

f =t0 + t1 = 3 + 14 = 17

    sub f, g, t0

f = g - (f + 5)

t0 = f + 5 = 1 + 5 = 6

f = g- (f+5) = 2 – (1+ 5)

f = -4

Therefore the final value of f is -4