Question

When writing an assembly code, After making a call to a function that takes several parameters, are all the %o registers (except for %o0 since it contains the return value) set to 0?

For example:

mov    %i0, %o0
mov    %i1, %o1
mov    %i2, %o2
call   somefunction
nop

From the code above, ! are o1 and o2 automatically set to zero now?

Was it helpful?

Solution

In short, values of registers are not changed or set to 0 automatically.

Assuming a new stack frame is created via the save instruction (or some other means), the arguments passed to the %o0 to %o5 registers become %i0 to %i5 to the callee and that routine can change those register values.

So, when the register window is restored, you are not even guaranteed the values you put in the %ox registers are preserved as the callee may have changed them.

Remember that the out registers become the in registers to the callee. That's why the callee puts the return value in %i0 and restores the register window. Then back at the caller, the return value is in %o0.

The same holds true for leaf routines. In this case however, the routine only has access to the %o0 to %o5 registers to perform its work.

When returning from either routine, the contents of the %ox registers will be whatever was left.

In addition, %o6 and %o7 hold the addresses of the stack pointer and program counter, respectively.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top