In: Computer Science
What are these C Codes in MIPS?
A[R[j]] = -645 -j /4
A[32] = R[9j] - 4j
Please find the answer below.
Please do comments in case of any issue. Also, don't forget to rate
the question. Thank You So Much.
A)
#A base address -> s0
#R base address -> s1
#j -> t1
div $t0,$t1,4 #get j/4
li $t2,-645
sub $t2,$t2,$t0 # get j/4 - 645
mul $t0,$t1,4 #get address of j
add $t0,$t0,$s1#get address of R[j]
lw $t0,($t0) #get value of R[j]
mul $t0,$t0,4 #get address of R[j]
add $t0,$t0,$s1#get address of A[R[j]]
sw $t2($t0) #get value of R[j]
B)
#A base address -> s0
#R base address -> s1
#j -> t1
mul $t0,$t1,9 #get 9j
mul $t0,$t0,4 #get address of 9j
add $t0,$t0,$s1 #get address of R[9j]
lw $t0,($t0)#get value of R[9j]
mul $t2,$t1,4 #get 4j
sub $t0,$t0,$t2 #get R[9j]-4j
sw $t0,128($s0) #store value at address A[32]