Microchip Technology SW006023-1N Data Sheet

Page of 238
MPLAB
®
 XC32 C/C++ Compiler User’s Guide
DS51686E-page 128
 2012 Microchip Technology Inc.
10.5
FUNCTION SIZE LIMITS
 There are no theoretical limits as to how large functions can be made.
10.6
FUNCTION PARAMETERS
MPLAB XC uses a fixed convention to pass arguments to a function. The method used 
to pass the arguments depends on the size and number of arguments involved.
The Stack Pointer is always aligned on an 8-byte boundary.
• All integer types smaller than a 32-bit integer are first converted to a 32-bit value. 
The first four 32 bits of arguments are passed via registers a0-a3 (see Table 10-1 
for how many registers are required for each data type).
• Although some arguments may be passed in registers, space is still allocated on 
the stack for all arguments to be passed to a function (see Figure 10-1). Applica-
tion code should not assume that the current argument value is on the stack, even 
when space is allocated.
• When calling a function:
- Registers a0-a3 are used for passing arguments to functions. Values in these 
registers are not preserved across function calls.
- Registers t0-t7 and t8-t9 are caller saved registers. The calling function 
must push these values onto the stack for the registers’ values to be saved.
- Registers s0-s7 are called saved registers. The function being called must 
save any of these registers it modifies.
- Register s8 is a saved register if the optimizer eliminates its use as the Frame 
Pointer. s8 is a reserved register otherwise.
- Register ra contains the return address of a function call.
Note:
The names “argument” and “parameter” are often used interchangeably, 
but typically an argument is the actual value that is passed to the function 
and a parameter is the variable defined by the function to store the argu-
ment.
TABLE 10-1:
REGISTERS REQUIRED
Data Type
Number of Registers Required
char
1
short
1
int
1
long
1
long long
2
float
1
double
1
long double
2
structure
Up to 4, depending on the size of the struct.