Assume that the integer variables f g and i are assigned to
Solution
1. Once we get B[A[i]], the job becomes easy. Note that, sll is shift logical left operator.
sll $t0, $s2, 2 #calculate i*4
add $t0, $s3, $t0 #find address to load A[i]
lw $t1, 0($t0) #A[i] loaded into t1 register
sll $t0, $t1, 2 #t0 register contains A[i]*4
add $t0, $s4, $t0
lw $t1, 0($t0) #B[A[i]] loaded into t1 register
sub $s0, $t1, $s1 #subtracted g from B[A[i]] and store in f
2.
move $f0, 0 # set a = 0
move $s0, 10 # i = 10
while_label:
ble $s0, 0, Exit # if i <= 0, exit while loop
sub $s0, $s0, 1 # i = i - 1
sll $t0, $s0, 2
add $t0, $s1, $t0 #find base_add( B ) + 4*i
ls $f1, 0($t0) #load single precision floating pointe in f1 register
mul.s $f0, $f0, $f1 #multiply it by a
j while_label #continue next iteration
Exit:
