Register Guide

RISC-V t0 / x5 Register: Temporary Values, Call Clobbering, and Alternate Link Register

t0 is a psABI temporary register and is not preserved across calls; values that must survive a call cannot live only in t0. The RISC-V ISA also notes that the standard calling convention uses x1 for the return address, with x5 available as an alternate link register.

psABI: x5-x7 / t0-t2 are temporary registers and are not preserved across calls.
ISA: x5 is available as an alternate link register.
Beginner rule: use t0 for short-lived temporaries and save it yourself before a call if needed.
Physical Name x5ABI Name t0Save Rule Caller

t0 is caller-saved. Using x5 as an alternate link register does not change that preservation rule; if it must survive a call, the caller must save it.

Role
Temporary / alternate link register
Convention
Caller-saved
Remember This First
The psABI marks t0 as a temporary register that is not preserved across calls.
psABI Reference

Temporary register

The psABI marks t0-t6 as temporary registers. They are not callee-saved; callers must save any value that needs to survive a call.

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

t0 / x5 belongs to the t0-t6 temporary-register group. The psABI marks it not preserved across calls; callers must save any value that needs to survive a call.

t0-t6 are temporary registers and are not preserved across calls.
The ISA notes x5 as an alternate link register, but the psABI still classifies t0 as a temporary register.

When It Fits Best

  • - Hold short-lived temporary values that do not need to be automatically preserved across function calls.
  • - In hand-written assembly, manage its lifetime explicitly according to the calling convention.
  • - Understand the ISA note that x5 is available as an alternate link register.

When Not To Use It This Way

  • - Do not assume t0 keeps its old value after a function call.
  • - Do not assume a value in t0 survives across a function call (unless the caller explicitly saves it).

What Happens Around A Call

1

The psABI marks t0 as a temporary register that is not preserved across calls.

2

If the caller needs a t0 value after a call, the caller must save it first.

3

The ISA notes that x5 is available as an alternate link register, but that does not change t0's ABI preservation rule.

Two Typical Uses of t0

Examples explain the rule, not a complete program
# Use 1: as an ordinary temporary
add  t0, a0, a1     # t0 = a0 + a1
slli t0, t0, 2      # t0 = t0 << 2
# If the result must survive a call, save it to an ABI-valid location first
# Use 2: understand x5 as an available alternate link register
# exact syntax depends on the call sequence and assembler pseudoinstructions

Relationship With Other Registers

t0 vs ra (Alternate vs Primary Link Register)

The RISC-V ISA says the standard calling convention uses x1 as the return address register and that x5 is available as an alternate link register. The psABI still names x1 as ra and x5 as t0, a temporary register; neither is preserved across calls. In hand-written assembly, the call sequence must make clear which register a later return sequence will read.

Why You Cannot Use It As A Scratch Register

Although the ISA notes x5 as an available alternate link register, the psABI still classifies t0 as a temporary register that is not preserved across calls. If later code still needs the value in t0, the caller must save it before the call; if it is used for a return address, make sure the return sequence reads t0 rather than ra.

FAQ

Is t0 / x5 preserved across calls?

No. t0-t6 are temporary registers and are not preserved across calls.

What if a t0 value is needed after a call?

The caller must save it before the call, usually to the stack or another suitable location, and restore it afterward.