16.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 4-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
R0-R3
(see the table below for how many registers are required for each data type). - When calling a function:
Registers
R0-R3
are used for passing arguments to functions. Values in these registers are not preserved across function calls.Registers
R0-R3
,R12
,R14
, andR15
are caller-saved registers. The calling function must push these values onto the stack for the registers’ values to be saved.Registers
R4-R7
are callee-saved registers. The function being called must save any of these registers it modifies.Register
R11
is a saved register if the optimizer eliminates its use as the Frame Pointer. This is a reserved register otherwise.Register
R14
contains the return address of a function call.
Data Type | Number of Registers Required |
---|---|
char | 1 |
short | 1 |
int | 1 |
long | 1 |
long long | 2 |
float | 1 |
double | 2 |
long double | 2 |
structure | Up to 4, depending on the size of the struct. |