Given the following high level Instructions convert Into MIP
Given the following high level Instructions, convert Into MIPS Instructions a) Convert the for loop Into MIPS Instructions. Use the sit instruction to determine the branch. Be sure to Initialize I properly. for (Int i = 1; i
Solution
Solution 1 : i is in $t0 and Value is in $s0
addi $t0, $zero, 1
Loop: stli $t1, $t0, 7
beq $t1, $zero, exit
add $s0, $s0, $t0
addi $t0, $t0, 1
j Loop
exit:
==========================================
Solution 2:
slt $t3, $t1, $t0 # if $t1 < $t0 then $t3 = 1, else $t3 = 0
slt $t4, $t0, $t2 # if $t0 < $t2 then $t4 = 1, else $t4 = 0
beq $t3, $0, else #if (i<=min) go to else
beq $t4, $0, else #if (i>=max) go to else
sll $a0, $t0, 2 #multiply i by 4 to get to that memory location
add $a1,$s0,$a0 #$a1 = (base address of A + that location (i))
sw 1,0($a1) #A[i] = 1
j exit
else: sll $a0, $t0, 2 #multiply i by 4 to get to that memory location
add $a1,$s0,$a0 #$a1 = (base address of A + that location (i))
sw $zero,0($a1) #A[i] = 0
exit:
