Convert C loop to MIPS instructions while ai 100 i assume
Convert C loop to MIPS instructions
while( a[i] < 100 ) i++; assume i in $s3, 100 in $s5, address of save in $s6
Solution
The given C loop can be further written as:
L1: if( a[i]<100) {
i++;
goto L1;
}
Now, MIPS instructions will be like this:
L1: lw $s7, 0($s6) # $s7 = a[i]
bge $s7, $s5, DONE # branch if !(a[i] < 100)
addi $s3, $s3, 1 # i++
addi $s6, $s6, 4 # move array pointer
j L1 # goto L1
DONE:
Hope it helps, do give your response.
![Convert C loop to MIPS instructions while( a[i] < 100 ) i++; assume i in $s3, 100 in $s5, address of save in $s6SolutionThe given C loop can be further writt Convert C loop to MIPS instructions while( a[i] < 100 ) i++; assume i in $s3, 100 in $s5, address of save in $s6SolutionThe given C loop can be further writt](/WebImages/43/convert-c-loop-to-mips-instructions-while-ai-100-i-assume-1133221-1761605901-0.webp)