For the following C statement what is the corresponding MIPS
For the following C statement, what is the corresponding MIPS assembly code? Assume that the variables f, g, h, and k are assigned to registers $s0, $s1, $s2, and $s3, respectively. f = g + (h - 5); k = f
Solution
Assuming
$s0 = f
$s1 = g
$s2 = h
$s3 = k
MIPS instructions for the C statement : f = g + (h - 5)
ADDI $s2, $s2, -5 //signed immediate addition. It is equivalent to h=h-5.
ADD $s0, $s1, $s2 //adds content of two registers $s1 and $s2 and stores in $s0. f = g +h
MIPS instructions for the statement : k = f
ADDI $s3, $s0, 0 //adding a constant value to the content of register. Adding zero is equivalent to k=f.
