addi $t0, $t1,-5
add $t2, $t0, $t3
A is in $S6, B is in $S7
Solution:
I am assuming variables f, g, h, i, and j are assigned to registers x1, x2, x3, x4, and x5, and the base address of the arrays A and B are in registers s6 and s7, respectively.
1. RISC-V assembly code for f = g + (h − 5);
addi x0, x3, -5 #equivalent to x0 = h - 5 where x0 is temporary register
add x1, x2, x0 #equivalent to x1 = x2 + x0 that is f = g + ( h - 5)
2. RISC-V assembly code for B[8] = A[i−j];
sub s0, x4, x5 #equivalent to x0 = i - j where s0 is temporary register
add s1, s6, s0 #equivalent to s1 = &A[i-j] where s1 is temporary register
lw s2, 0(s1) #equivalent to s2 = A[i-j] where s2 is temporary register
sw s2, 32(s7) #equivalent to B[8] = A[i-j]
Please give thumbsup, if you like it. Thanks.
Get Answers For Free
Most questions answered within 1 hours.