Examples of parameter allocation are shown in the following. Note that addresses increase from the right side to the left side in all figures (upper address is on the left side).
Parameters matching the type to be passed to registers are allocated, in the order in which they are declared, to registers R1 to R4. |
Parameters of a structure or union whose size is 16 bytes or less and is also a multiple of 4 are allocated to registers. Parameters of all other structures and unions are allocated to the stack. |
When declared in a prototype declaration as a function with a variable-number of parameters, the parameters without corresponding types and the immediately preceding parameter are allocated to the stack in the order in which they are declared. |
When the type returned by a function is more than 16 bytes, or for a structure or union that is not the size of a multiple of 4, the return value address is set to R15. |
When setting the return value to memory, normally a stack is allocated, as shown in example 4. In the case of setting the return value to a variable, however, no stack is allocated and it is directly set to the memory area for that variable. In this case, the address for the variable is set to R15. |