2. Suppose we have 3 arrays A, B, and C, array A’s base address is in $S3, B’s base address is in $S4, C’s base address is in $S5. You can only use two temporal registers $t0 and $t1. Convert the following code into MIPS assembly language code. Suppose every array element occupies 1 word in MIPS (32 bits).
A[21] = B[0] + C[16];
lw $t0, ($s4) # t0= B[0]
#calculate offset and fetch C[16]
li $t1, 16
mul $t1, $t1, 4
add $t1, $t1, $s5
lw $t1, ($t1) #t1 = C[16]
#add t0 and t1 and store in t0
add $t0, $t0, $t1
#calculate offset for A[21]
li $t1, 21
mul $t1, $t1, 4
add $t1, $t1, $s3
#store tthe value from t0 into A[21]
sw $t0, ($t1)
Get Answers For Free
Most questions answered within 1 hours.