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.
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.
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.
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.
s* registers are callee-saved: if a function borrows them, it must restore them before return.
Callers may assume s* remain unchanged after the call returns.
Changing s* usually implies save-on-entry and restore-on-exit.
addi sp, sp, -16
sd s0, 0(sp)
addi s0, a0, 0
call foo
# s0 still keeps the value needed after the call
ld s0, 0(sp)
addi sp, sp, 16
rets0-s11 are preserved across calls; a callee that modifies them must restore them, so callers can rely on their values after return.
The callee restores it before returning.