Assume we have an array int* arr = {1,21,32,43,54}. The values in arr store in the memory of 0(x27), 8(x27), …, 32(x27). Convert the following RISC-V code into a C program.
ld x5, 24(x27)
addi x8, x0, 0(x27)
srl x5, x5, x6
sd x5, 0(x27)
Answer.
Step 1
RISC-V is an assembly language. It contains 32 bit integer
registers and 32 bit floating point registers. It is compose
through simple instructions to do a single task. In this language,
data can be store in two ways, store on main memory or store on
registers.
In the given problem following commands are used:
Step 2
RISC-V code | C-code | Explanation |
ld x5, 24(x27) | x5=arr[3] or x5=43 | sets x5 equal to arr[3] |
addi x8, x0, 0(x27) | x8=x1+arr[0] or x8=x1+1 | Add 1 to x0 and store in x8 |
srl x5, x5, x6 | x5=x5<<x6 | Logical right shifts x5 by x6 and store in x5 |
sd x5, 0(x27) | x5=arr[0] or x5=1 | store double word, initialize x5 by 1 |
Kindly upvote please,
Thank you.
Get Answers For Free
Most questions answered within 1 hours.