Register Guide

RISC-V s0 / fp / x8 Register: Saved Register and Optional Frame Pointer

s0 is a callee-saved register in the psABI: if a function modifies it, the function must restore it before returning. The psABI also says that if code uses a frame pointer, it must reside in x8, namely s0/fp.

psABI: x8-x9 / s0-s1 are callee-saved registers.
psABI: a frame pointer is optional; if present, it must reside in x8/s0.
Beginner rule: restore s0 after borrowing it; if it is used as fp, do not modify it casually.
Physical Name x8ABI Name s0Save Rule Preserved across calls
Role
Saved register / Frame pointer
Convention
Preserved across calls
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. A frame pointer is optional; if present, the psABI requires it to reside in x8/s0.

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

s0 / x8 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.
If a frame pointer exists, the psABI says it must reside in x8/s0.

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.
  • - A frame pointer is optional; if present, it must reside in x8/s0.

When Not To Use It This Way

  • - Do not modify s* and return without restoring it.
  • - Do not assume a program uses a frame pointer; that role is optional.

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

If a frame pointer exists, it must reside in x8/s0.

Standard psABI Preservation Rule

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

FAQ

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

The callee restores it before returning.