Write the MIPS assesmbly code corresponding to the following

Write the MIPS assesmbly code corresponding to the following C code segment. Assume that f is assigned to register $s0. If possible. can you leave comments so I can follow what is actually being done, thanks!

int Example (int i, int j, int k)

{

int f;

f = i + j - k;

return f;

}

Solution

The variabl f is assigned to $s0.
assign remaining variables i,j,k to $s1,$s2,$s3.
i:   .word 3       //declare storage for i; initial value is 3
j:   .word 4       //declare storage for j; initial value is 4
k:   .word 1       //declare storage for k; initial value is 1
f:   .word        //declare storage for f
lw $s1,i       //load contents of RAM location into register $s1: $s1 = i
lw $s2,j       //load contents of RAM location into register $s2: $s2 = j
lw $s3,k       //load contents of RAM location into register $s3: $s3 = k
add t0,$s1,$s2 //adding i and j and storing the result in temporary register t0
sub $s0,t0,$s3       //substracting k value from t0 and storing in f means in s0 register
sw $s0,f       //store contents of register $s0 into RAM: f = $s0
  
done

Write the MIPS assesmbly code corresponding to the following C code segment. Assume that f is assigned to register $s0. If possible. can you leave comments so I

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site