What is Callee-saved register?
A register guaranteed to keep its value across a call; if the called function uses it, the function saves and restores it. In RISC-V these are s0-s11.
Japanese name: 呼び出し先保存レジスタ
A register guaranteed to keep its value across a call; if the called function uses it, the function saves and restores it. In RISC-V these are s0-s11.
Japanese name: 呼び出し先保存レジスタ
From the caller’s point of view, the value of such a register does not change across a function call. If the called function wants to use the register, it saves the original value on the stack at entry and restores it before returning. If it does not use the register, it need do nothing. In RISC-V these are s0 through s11 and the stack pointer; on x86-64 Linux and similar systems they are rbx, rbp and r12 through r15.
At function entry, the stack pointer is moved to make room and the values of the registers about to be used are written there. At function exit, the values are read back into the registers and the stack pointer is returned to its original position. The cost of saving is paid only by functions that actually use the register.
A value that stays in use across function calls is best placed in such a register, for example the iteration count of a loop that calls a function inside. It need not be saved around every call; one save and one restore at function entry and exit suffice. Conversely, a value that is finished with quickly is placed in a caller-saved register, which needs no saving. When exception handling leaves a function partway through, information about where the registers were saved is used to restore them.
Values the caller was using are corrupted without warning. It is a common mistake when writing functions in assembly language, and because the symptom appears somewhere far away, the cause is hard to find.
Yes. That name is also used, in the sense that the value does not disappear across a function call.
Callee-saved register appears in 1 practice question across 1 topic, including ISA & Assembly.
As an Amazon Associate I earn from qualifying purchases.
This page was drafted with AI and fact-checked by a separate AI review before publication. Our Editorial policy explains how we write and check content. If you spot an error, please tell us on our Contact page.