In: Computer Science
-If we assume we place the following MIPS code starting at location 8000 in memory, what is the MIPS machine code for this code? Show the machine codes in decimal. Please explain each instruction and specify its type ( R format, I format, or J format). k corresponds to register $s4, j corresponds to register $s1, i corresponds to register $s0, and the base of the array v is in $a0
addi $s1,$s0,-1
label2: slti $t0, $s1, 0
bne $t0, $zero, label1
sll $t1, $s1, 2
add $t2, $a0, $t1
lw $t3, 0($t2)
beq $t3, $zero, label1
subi $s4, $s4, 1
addi $s1, $s1, –1
j label2
label1:
addi $s1,$s0,-1 (I type)//j = i-1
label 2:
slti $t0, $s1, 0 (I type)//if (j<0) then $t0 = 1
bne $t0, $zero, label1(I type) //if($t0 =1) branch to
label1
sll $t1, $s1, 2 (R type) //$t1 = 4*j
add $t2, $a0, $t1 (R type) //$t2 = address of
v[j]
lw $t3, 0($t2) (I type) //$t3 = v[j]
beq $t3, $zero, label1(I type) //if(v[j] == 0) branch to
label1
subi $s4, $s4, 1 (I type) // k = k-1
addi $s1, $s1, –1 (I type) // j = j-1
j label2 (J type) //jump to label2
label1: