Search code examples
assemblymipscpu-registersmips32

Why the register $v0 is caller saved?


I am studying MIPS architecture and I can't figure why the register $v0 is caller saved.

This register is where the function stores the return value. When and why the caller must save it? May someone make a good example?


Solution

  • Since it is the register that will hold the return value, it cannot be callee-save. That would have created a situation where the callee both

    • must change the register, in order to return a value in it, and
    • is not allowed to change it (except temporarily), because it's callee-save.

    So it's caller-save. This does not mean that the caller must save it, it just means that if the caller needs the value to persist across a call, then it must save it somewhere else.