Go to main content

SPARC Assembly Language Reference Manual

Exit Print View

Updated: October 2017

6.4 Functions Returning Values

Functions that return an integer value return it in %o0 or %o0 and %o1. For 32-bit code, long long data are returned with the upper 32-bits in %o0 and the lower 32-bits in %o1, treating %o0 and %o1 as if they were 32-bit registers.

If the function returning a value has executed a save instruction, then the return value would normally be put into %i0 or %i1 just before executing a restore or return instruction, which changes register windows and puts the values into %o0 and %o1.

Functions that return a floating-point or complex value return it in some subset of %f0, %f1, %d0, %d2, %d4, and %d6. So a float value is returned in %f0, and a double value is returned in %d0 (or equivalently in %f0 and %f1).

Structure and array values returned by value are more complicated and beyond the scope of this manual. Registers %o0-%o5 and %f0-%f31 may be used as temporaries.

6.4.1 Limitations for 32-Bit Code

The global registers and the output registers can be used to hold 64-bit integer values, but the input registers and the local registers can only be used to hold 32-bit values in the lower half of the register. This is because the register save area for the input and local registers does not have enough room to store the full 64-bits and only the lower 32-bits are saved. The input and local registers may be saved and later reloaded at any point in time by a trap to handle an interrupt.

6.4.2 Limitations for Both 32-Bit and 64-Bit Code

There is a minimum stack size for any routine, and certain areas of the stack that cannot be used.

The minimum stack frame size is just large enough to hold the register save area plus the required 6 slots for parameter passing. For 32-bit code, the minimum stack frame size is 92 bytes. This is normally allocated with a "save %sp, 92, %sp" instruction. For 64-bit code, the minimum stack frame size is 176 bytes. This is normally allocated with a "save %sp, 176, %sp" instruction.

The stack area below where %sp points is volatile and might be overwritten at any point in time (for example. by an interrupt). Do not store any useful data there, instead, change the %sp downward first and store above the %sp.

6.4.3 Additional Information About SPARC ABI

    For more information about the SPARC application binary interface (ABI), see the following documents available at sparc.org:

  • SPARC Compliance Definition 2.3 (32-bit specification)

  • SPARC Compliance Definition 2.4 (64-bit specification)

Refer also to the SPARC V9 Architecture Manual (PDF) descriptions of the instruction set, registers, and other details.