For the Java statements on the left provide the correspondin

For the Java statements on the left, provide the corresponding MIPS assembly code in the corresponding space on the right. Assume f, g, and j are assigned to registers $s0, $s1, and $s2 respectively, and h is assigned to register $v0. Also assume that the starting address of the array A (which is an array of 15 words) is in register ra C statements MIPS Assembly code =(g+h) +0+13) [12] = h + A[8] (f- 0) f=f+j; if(j=h) f= g+h; else f= g-h; f= f+ A[2]; if(j-h ) f= f+1 ; f=g+h;

Solution

a)add $t0, $s1, $v0
addi $t1, $s2, 13 // addi add immediate constant
add $s0, $t0, $t1

b)la $t3,$ra # load address of start of array A
lw $t0, 32($t3) # load contents of A[8]
add $t0, $v0, $t0
sw $t0, 48($t3)

c)beq $s0, $zero, LabEnd #if equal to zero then jump to LabEnd
add $s0, $s0,$s2
addi $s2, $s2,-1 #subtract 1 from $s2 value
LabEnd:

d)bne $s2, $v0, Lab1 # compare j, h
add $s0, $s1, $v0 # f = g + h
j Lab2 # skip false part
Lab1:
sub $s0, $s1, $v0 # f = g -h
Lab2:
la $t2, $ra # load address of start of array A
lw $t1, 8($t2) # load contents of A[2]
add $s0, $s0, $t1 # f=f+A[2]

e)beq $s2, $v0, Lab1 # compare j, h   
addi $s0, $s0,1 # f = f + 1
j LabEnd# skip false part
Lab1:
  add $s0, $s1, $v0 # f = g +h
LabEnd:

 For the Java statements on the left, provide the corresponding MIPS assembly code in the corresponding space on the right. Assume f, g, and j are assigned to r

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site