ISA & Assembly

In the standard RISC-V calling convention, which registers pass integer arguments and return values?

  1. AArguments in s0-s7; return value in ra
  2. BArguments in a0-a7; return value in a0 (and a1)
  3. CAll arguments on the stack; return value in sp
Show answer and explanation

Answer: B. Arguments in a0-a7; return value in a0 (and a1)

In the standard RISC-V calling convention, up to eight integer arguments are passed in a0-a7 (x10-x17), and the return value comes back in a0, or in a0 and a1 for values such as 64-bit integers on RV32. Passing through registers, which are faster than memory, keeps call overhead low. Arguments beyond eight go on the stack. Floating-point arguments use fa0-fa7.

  • A. s registers are saved registers; ra is the return address.
  • B. Correct. The a stands for argument.
  • C. Up to eight go in registers; sp is the stack position.
Practice this topic Back to topic

More ISA & Assembly questions

  1. In the standard RISC-V calling convention, when calling a function with ten integer arguments, where are the ninth and tenth passed?
  2. In the RISC-V calling convention, s0-s11 are callee-saved registers. What does that mean?
  3. 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?
  4. A function that calls no other functions (a leaf function) often does not need to save ra on the stack. Why?
  5. What is the purpose of executing "addi sp, sp, -16" at the start of a RISC-V function?