ISA & Assembly
In the standard RISC-V calling convention, when calling a function with ten integer arguments, where are the ninth and tenth passed?
- AIn s0 and s1
- BIn t0 and t1
- 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.