ISA & Assembly
In the RISC-V calling convention, s0-s11 are callee-saved registers. What does that mean?
- AIf the called function uses them, it must save the old values and restore them before returning
- BThe calling function must clear them all to 0 before the call
- COnly the OS may use them; user programs cannot
Show answer and explanation
Answer: A. If the called function uses them, it must save the old values and restore them before returning
Callee-saved registers are guaranteed to keep their values across a call. If the called function wants to use s0 or another s register, it saves it on the stack at entry and restores it before returning. The caller can keep values it still needs after the call in s registers without saving them itself. Loop variables are often placed there.
- A. Correct. To the caller their values appear preserved.
- B. There is no rule to clear them.
- C. User programs use them normally.