ISA & Assembly

In the standard RISC-V calling convention, when calling a function with ten integer arguments, where are the ninth and tenth passed?

  1. AIn s0 and s1
  2. BIn t0 and t1
  3. COn the stack
Show answer and explanation

Answer: C. On the stack

There are only eight argument registers, a0-a7, so from the ninth argument on the caller places them on the stack and the callee reads them at fixed positions relative to the stack pointer. The extra memory accesses make functions with very many arguments a little slower. Passing a pointer to a struct instead of many separate values is a common way to keep the argument count down.

  • A. s registers are callee-saved, not for arguments.
  • B. t registers are temporaries, not for arguments.
  • C. Correct. Whatever does not fit in registers goes on the stack.
Practice this topic Back to topic

More ISA & Assembly questions

  1. In the RISC-V calling convention, s0-s11 are callee-saved registers. What does that mean?
  2. 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?
  3. A function that calls no other functions (a leaf function) often does not need to save ra on the stack. Why?
  4. What is the purpose of executing "addi sp, sp, -16" at the start of a RISC-V function?
  5. The standard RISC-V calling convention requires sp to be a multiple of 16 bytes on function entry. What is the main reason?