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.

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 argument.

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, and R15 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.

Table 16-1. Registers Required
Data TypeNumber of Registers Required
char1
short1
int1
long1
long long2
float1
double2
long double2
structureUp to 4, depending on the size of the struct.