Question

Problem 1 (15 points) Translate the C code below into RISC-V, knowing that the values of i and j are in registers x28 and x29, respectively. The base address of array B is in register x30, and the base address of array C is in register x31.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer:

Consider the C code statement:

C[4] = B[i+j]

Translate C code to RISC-V code as follows:


add r0, x28, x29 lw rl, r0 (x30) sw rl,16 (x31) #r0 gets i+j value #load rl to get B[i+] value #stor e the value of B[i+j]in

Explanation:

  • Assume r0, and r1 are the registers to hold the pointers of B and C.
  • Add i+j values and store in r0 register.
  • Load the r0 register represented as an index in the register r1.
  • Store the value in the register at the index of each byte represent as 4bits, so 4bytes represented as16bits.
  • Hence the statement represents as C[4]->4*4=>16(x31)
Add a comment
Know the answer?
Add Answer to:
Problem 1 (15 points) Translate the C code below into RISC-V, knowing that the values of...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT