ISA & Assembly

In the RISC-V calling convention, s0-s11 are callee-saved registers. What does that mean?

  1. AIf the called function uses them, it must save the old values and restore them before returning
  2. BThe calling function must clear them all to 0 before the call
  3. 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.
Practice this topic Back to topic

More ISA & Assembly questions

  1. In the RISC-V calling convention, t0-t6 are caller-saved. If a function wants to keep using a value in t0 after calling another function, what should it do?
  2. A function that calls no other functions (a leaf function) often does not need to save ra on the stack. Why?
  3. What is the purpose of executing "addi sp, sp, -16" at the start of a RISC-V function?
  4. The standard RISC-V calling convention requires sp to be a multiple of 16 bytes on function entry. What is the main reason?
  5. The code above is the start (prologue) of a function. What does it do?