User guide

2.4 Parameter passing
A routine with a variable number of arguments is variadic. A routine with a fixed number of arguments is nonvariadic.
There are different rules about passing parameters to variadic and to nonvariadic routines.
This section describes the base standard. For additional information relating to floating-point options, see
Floating-point options.
2.4.1 Nonvariadic routines
Parameter values are passed to a nonvariadic routine in the following way:
1. The first integer arguments are allocated to r0-r3 in order (but see Allocation of long integers).
2. Remaining parameters are allocated to the stack in order (but see Allocation of long integers).
Warning
Stack accesses are costly in code size and execution speed. Keep the number of parameters less than five if
possible.
Allocation of long integers
An integer parameter longer than 32 bits, for example a long long, might be allocated partly to a register, and
partly to the stack. In this case the part allocated to the stack is allocated before any FP values, even if this does not
correspond to the order in the parameter list.
Allocation of floating-point numbers
If your system has floating point hardware, FP parameters are allocated to FP registers as follows:
1. Each FP parameter is examined in turn.
2. For each parameter, the available set of FP registers is examined.
3. If one is available, the lowest-numbered, contiguous set of FP registers large enough for the parameter is
allocated to the parameter.
2.4.2 Variadic routines
Parameter values are passed to a variadic routine in integer registers a1-a4, and on the stack if necessary (a1-a4
are synonyms for r0-r3).
The order of the words used is as if the parameter values were stored in consecutive memory words and then
transferred to:
1. a1-a4, a1 first.
2. The stack, lowest address first. (This means that they are pushed onto the stack in reverse order.)
Note
As a consequence, a floating-point value might be passed in integer registers, on the stack, or split between integer
registers and the stack.
2.4.3 Result return
A function can return:
A one-word integer value in a1.
A two to four-word integer value in a1-a2, a1-a3 or a1-a4.
A floating-point value in f0, d0, or s0.
A compound floating-point value (such as complex) in f0-fN, or d0-dN. The maximum value of N depends on
the selected floating-point architecture (see Floating-point options).
A longer value must be returned indirectly, in memory.
Using the Procedure Call Standard
Copyright ?1999 2001 ARM Limited 2-6