i.
MIPS loop: g = g B[8] +A[i]; i = i +j; if (i!=h) goto loop;
A is an array of 80 elements. Variables g, h, i and j are associated with registers $S1, $S2, $S3 and $S4 respectively. Base of array A is $S5 and that of B is $S6.
Answer: Rewriting this: Do { g = g B [8] + A [i]; i = i + j; } while (i! =h) go to loop; Using the following mapping: g = $S1 , h =$S2 , i = $S3 and j = $S4 base address of A = $S5, Base address of B =$S6 Final Compiled MIPS Code: lw $t0 32($S6) add $t1 $S3 $S3 add $t2 $S1 $t1 add $t3 $s5 $t2 lw $t4 0($t3) add $t5 $to $t4 sub $s1 $s1 $t5 add $S3 $S3 $S4 bne $S3 $S2 Loop # $t0 =B[8] #$t1 = i+i #$t2 = 2i +2i #$t3 = Ba + $t2 # Load word # $t5 = B [8] + A [i]; # SS1 = B [8] + A [i] # $S3 = i + j # Go to loop #If (i!=h)
lw $t0,32($s6) add $t1,$s3,$s3 add $t2,$s1,$t1 add $t3,$s5,$t2 lw $t4,0($t3) add $t5,$t0,$t4 L1: j exit sub $s1,$s1,$t5 add $s3,$s3,$s4 bne $s3,$s2,L1 exit: