In: Computer Science
Question:
Consider the following C language instruction.
A[10] = ((f+g) – (h+A[5])) + 100;
Translate the above code into MIPS assembly language code. Assume variables f, g, and h are associated
with registers $S0, $S1, and $S2 respectively. The base address of A is associated with register $S5.
Please find the answer below.
Please do comments in case of any issue. Also, don't forget to rate
the question. Thank You So Much.
code snippet
copy to code
.text
#f is in $s0
#g is in $s1
#h is in $s2
#Base address of A is in $s5
#get f+g
add $t0,$s0,$s1
#get A[5] using 20, Because int is of 4 byte in size
#hence 5th element will be at 20th position
lw $t1,20($s5)
#get h+A[5]
add $t1,$t1,$s2
#get f+g - (h+A[5])
sub $t0,$t0,$t1
#get f+g - (h+A[5])+100
add $t0,$t0,100
#now store the result at location A[10]
sw $t0,40($s5)