Register Guide

RISC-V s5 / x21 Register: Saved register

Callee-saved register 5 in the standard psABI; a callee that modifies it restores its entry value before returning.

ABI name: s5; physical register: x21.
Save rule: Callee.
Read it through its psABI role first, then inspect how each instruction reads or writes it.
Physical Name x21ABI Name s5Save Rule Callee
Role
Saved register
Convention
Callee-saved
Remember This First
The standard psABI marks s0-s11 as preserved across calls.
psABI Reference

Saved register

The psABI marks s0-s11 as preserved across calls. A callee that modifies them must restore their entry values before returning. s5 has no frame-pointer alias; the optional frame-pointer rule applies only to x8/s0.

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

s5 / x21 belongs to the s0-s11 saved-register group. The psABI marks it preserved across calls; a callee that modifies it must restore it before returning.

s0-s11 are saved registers preserved across calls.
A callee that modifies s5 must restore its original value before returning.

When It Fits Best

  • - Recognize it as a register preserved across calls in the standard psABI.
  • - Restore its entry value before returning when a procedure modifies it.
  • - s5 is a saved register; the frame-pointer alias belongs only to x8/s0.

When Not To Use It This Way

  • - Do not modify s* and return without restoring it.
  • - Do not describe s5 as a frame pointer; that optional role belongs only to x8/s0.

What Happens Around A Call

1

The standard psABI marks s0-s11 as preserved across calls.

2

A callee that modifies s* must restore its entry value before returning.

3

s5 has no frame-pointer alias.

Standard psABI Preservation Rule

Examples explain the rule, not a complete program
# s5 is a register preserved across calls
# A procedure that modifies s5 must restore its entry value before returning

FAQ

Why is s5 / x21 suitable for values that survive calls?

s0-s11 are preserved across calls; a callee that modifies them must restore them, so callers can rely on their values after return.

Who restores s5 if a function modifies it?

The callee restores it before returning.