Question

IN RISC-V

a) Consider the RISC-V code below. Indicate what is the value in register x20 after the code below is executed, and explain why; ori x18 x0 16 addi x20 x18 0 beq x20, x18, HERE add x20 x20, x20 b) Assume that the code above is part of a procedure called by main. What happens with the stack pointer during the procedure execution and why? Draw and explain. c) Add instructions to the above code to implement your answer in question b). Problem 5 (20 points) Translate the code below into RISC-V, assuming that the declaration for function h is h(int b, int c) and function f is int f (int a, int b, int c, int d) return h (h (b,c) , a+d); Note that stack pointers must remain multiple of 16.

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

a)

There are 4 instructions in this code

1) ori x18 x0 16

This will or the x0 with 16 value and the result will be stored in x18.

the operation will be

x18 = x0 | 16

2) addi x20 x18 0

this will sum up the new x18 value we get after or and the result will be stored in x20.

basically

x20 = x18 + 0

3)

beq is a branch if equal instruction this will check the value of x20 and x18.

if the value are equal then it will go to HERE statement.

so a comparison wioll happen here.

4)

add x20 x20 x20

this will double the value stored in x20 register. so x20 = x20+x20.

b)

The stack pointer will be incremented with each instrcuction call. In this case the stack pointer value will be updated by one as soon as the branch instruction is incountered.

c)

The stack pointer value is generally stored in a register in a CPU. After every instruction you can read the value of the stack pointer and check the value.

This can be done by a simple mov instruction.

mov x5 , x28 assuming x28 is the stack register.

Add a comment
Know the answer?
Add Answer to:
IN RISC-V a) Consider the RISC-V code below. Indicate what is the value in register x20...
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