General rules concerning parameters and the method for allocating parameters are described.
Refer to section 8.2.5, Examples of Parameter Allocation, for details on how to actually allocate parameters.
A function is called after parameters have been copied to a parameter area in registers or on the stack. Since the caller does not reference the parameter area after control returns to it, the caller is not affected even if the callee modifies the parameters.
Parameters whose types are declared by a prototype declaration are converted to the declared types. |
Parameters whose types are not declared by a prototype declaration are converted according to the following rules. |
Parameters are allocated to registers or to a parameter area on the stack. Figure 3.3 shows the parameter-allocated areas.
Following the order of their declaration in the source program, parameters are normally allocated to the registers starting with the smallest numbered register. After parameters have been allocated to all registers, parameters are allocated to the stack. However, in some cases, such as a function with variable-number parameters, parameters are allocated to the stack even though there are empty registers left. The this pointer to a nonstatic function member in a C++ program is always assigned to R1.
Table 3.28 lists general rules on parameter area allocation.
If a function has been declared to have variable parameters by a prototype declaration, parameters which do not have a corresponding type in the declaration and the immediately preceding parameter are allocated to the stack. For parameters which do not have a corresponding type, an integer of 2 bytes or less is converted to long type and float type is converted to double type so that all parameters will be handled with a boundary alignment number of 4. |
The address and allocation method to the stack for the parameters that are shown in table 3.28 as parameters allocated to the stack are as follows:
Parameters are stored in the parameter area on the stack in a manner so that the leftmost parameter in the parameter sequence will be located at the deep end of the stack. To be more specific, when parameter A and its right-hand parameter B are both allocated to the stack, the address of parameter B is calculated by adding the occupation size of parameter A to the address of parameter A and then aligning the address to the boundary alignment number of parameter B. |