Register Guide

RISC-V a0 / x10 Register: Arguments, Return Values, and Calling Convention

a0 is one of the RISC-V psABI argument registers; the psABI also uses a0 for return values. It is not preserved across calls, so do not assume its post-call value is the pre-call argument.

psABI: a0-a7 are argument registers, with a0-a1 also used for return values.
psABI: a0 is not preserved across calls.
Beginner rule: save the old a0 before a call if you still need it afterward.
Physical Name x10ABI Name a0Save Rule Not preserved across calls
Role
Argument / Return value
Convention
Not preserved across calls
Remember This First
The psABI marks a0-a7 as not preserved across calls.
psABI Reference

Argument/return-value register

The standard psABI uses a0-a7 as argument registers, with only a0-a1 also used for return values. They are not preserved across calls.

Preserved across calls: No
RISC-V psABI integer register convention
Quick Understanding & Search Notes

a0 / x10 belongs to the a0-a7 argument-register group. The psABI uses a0-a7 for arguments and a0-a1 for return values; these registers are not preserved across calls.

a0-a7 are argument registers, and a0-a1 are also used for return values.
a0 is not preserved across calls, so a callee may overwrite it.

When It Fits Best

  • - a0 is one of the psABI a0-a7 integer argument registers.
  • - a0 is one of the first two argument registers that the psABI also uses for return values.
  • - Read a0-a7 first as function argument registers under the psABI.

When Not To Use It This Way

  • - Do not assume a* registers keep their old values after a call.
  • - If the original a* value is needed after a call, do not leave it in a* across that call.

What Happens Around A Call

1

The psABI marks a0-a7 as not preserved across calls.

2

a0 / a1 are the first two argument registers that the psABI also uses for return values; after a call, do not assume they retain old arguments.

3

For a scalar of at most XLEN bits, the psABI passes it by value on the stack when no argument register is available.

Arguments And Return Values

Examples explain the rule, not a complete program
addi a0, zero, 3  # write a0
# The psABI also uses a0 for return values

FAQ

Does a0 / x10 keep its old argument value after a call?

Do not assume so. a0-a7 are not preserved across calls, and the callee may overwrite them.

Which a registers carry return values?

The psABI uses a0-a1 for return values as well as arguments.