Answered You can hire a professional tutor to get the answer.

QUESTION

For the following C statement, write the corresponding RISC-V assembly code. Assume that the variables i, and j are assigned to registers x28, and...

For the following C statement, write the corresponding RISC-V assembly code.

Assume that the variables i, and j are assigned to registers x28, and x29, respectively.

Assume that the base address of the arrays A and B are in registers x10 and x11,

respectively.

B[8] = A[i - j]

here is the solution:

Sub x5, x28, x29 // temp x5 gets i-j

Sll x5, x5, 3 // temp x5 gets (i-j)*8

Add x5, x10, x5 // temp x5 gets base_add A + (i-j)*8

Ld x9, 0(x5) // load from A[i-j] to temp x9

Sd x9, 64(x11) // store x9 to B[8] (mem[ base_add B + 8*8])

I dont understand that why we need get (i-j)*8 in the second command line.

Show more
LEARN MORE EFFECTIVELY AND GET BETTER GRADES!
Ask a Question