Register Guide

RISC-V s9 / x25 Register: Saved register

Callee-saved register 9; must be preserved across function calls.

ABI name: s9; physical register: x25.
Save rule: Callee.
Read it through its psABI role first, then inspect how each instruction reads or writes it.
Physical Name x25ABI Name s9Save Rule Callee
Role
Saved register
Convention
Callee-saved
Remember This First
s* registers are callee-saved: if a function borrows them, it must restore them before return.
psABI Reference

Saved register

The psABI marks s0-s11 as preserved across calls. A callee that modifies them must restore their original values before returning; s0 may also serve as the frame pointer.

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

s9 / x25 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 s9 must restore its original value before returning.

When It Fits Best

  • - Keep values that still matter after calling another function.
  • - Preserve data that must remain available after nested calls.
  • - s9 is an ordinary saved register and does not have the s0/fp frame-pointer alias role.

When Not To Use It This Way

  • - Do not modify s* and return without restoring it.
  • - Prefer t* for short-lived temporaries instead of occupying s* for brief calculations.

What Happens Around A Call

1

s* registers are callee-saved: if a function borrows them, it must restore them before return.

2

Callers may assume s* remain unchanged after the call returns.

3

Changing s* usually implies save-on-entry and restore-on-exit.

Save And Restore callee-saved Registers On RV64

Examples explain the rule, not a complete program
addi sp, sp, -16
sd   s9, 0(sp)
addi s9, a0, 0
call foo
# s9 still keeps the value needed after the call
ld   s9, 0(sp)
addi sp, sp, 16
ret

FAQ

Why is s9 / x25 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 s9 if a function modifies it?

The callee restores it before returning.