Write the MIPS assembly code that corresponds to the pseudo
Write the MIPS assembly code that corresponds to the pseudo code below. Assume that the address for integer i is baseaddress+4 and the address for a[0] is baseaddress+8. Assume that the baseaddress is stored in $gp. The code initializes i to 0; it then iterates from i=0 to i=4, setting a[i] = 2i in each iteration. To make your code efficient, i must be loaded into a register at the start, and it must be updated in memory only after you\'ve finished the for loop. for (i=0; i
Solution
li $to,0 #i=0
loop:
slti $t1,$t0,5 #$t1=1 iff $t0<5
beq $t1,$zero,end # if result of slti is 0 then end loop
lw $t0,0($gp) #base address of array a is in $gp loaded to register $t3
sll $t2,$t0,2 # $t0= 4*i
add $t2,$t2,$gp
sw $t2,0($gp) #a[i]=
add $t2,$t0,$t0 #2*i
addi $t0,$t0,1 #i++
j loop
end:
![Write the MIPS assembly code that corresponds to the pseudo code below. Assume that the address for integer i is baseaddress+4 and the address for a[0] is base Write the MIPS assembly code that corresponds to the pseudo code below. Assume that the address for integer i is baseaddress+4 and the address for a[0] is base](/WebImages/34/write-the-mips-assembly-code-that-corresponds-to-the-pseudo-1099570-1761580672-0.webp)