14.7 Function Call Conventions
When calling a function:
- Registers W0-W7 are caller saved. The calling function must preserve these values before the function call, if their value is required subsequently from the function call. The stack is a good place to preserve these values.
- Registers W8-W14 are callee saved. The function being called must save any of these registers it will modify.
- Registers W0-W4 are used for function return values.
- Registers W0-W7 are used for argument transmission.
- For dsPIC33C/E/F and dsPIC30F devices, DSRPAG/PSVPAG should be
preserved if the
-mconst-in-code
(auto_psv
) memory model is being used. - For dsPIC33A devices, the following
conventions hold:
- Registers F0 - F7 are caller saved. The calling function must preserve these values before the function call if their value is required upon returning from the function. The stack is a good place to preserve these values.
- Registers F8 - F31 are callee saved. The function being called must save any of these registers it will modify.
- Registers F0 - F1 will be used to
return
float
,double
orlong double
values. - Registers F0 - F7 will be used to
transmit
float
,double
orlong double
values.
Data Type | Architecture | Number and Type of Registers Required |
---|---|---|
char | All | 1 W register |
short | All | 1 W register |
int | All | 1 W register |
any C qualified pointer | All | 1 W register |
any extended qualified pointer | dsPIC33C/E/F and dsPIC30F | 2 W registers |
long | dsPIC33C/E/F and dsPIC30F | 2 W registers, aligned to even numbered register |
dsPIC33A | 1 W register | |
float | dsPIC33C/E/F and dsPIC30F | 2 W registers, aligned to an even numbered register |
dsPIC33A | 1 F register | |
double (Note 1) | dsPIC33C/E/F and dsPIC30F | 2 W registers, aligned to an even numbered register |
dsPIC33A | 1 F register | |
long long int | dsPIC33C/E/F and dsPIC30F | 4 W registers, aligned to a quad numbered register |
dsPIC33A | 2 W register, aligned to an even numbered register | |
long double | dsPIC33C/E/F and dsPIC30F | 4 W registers, aligned to a quad numbered register |
dsPIC33A | 2 F registers, aligned to an even numbered register | |
_Fract | dsPIC33C/E/F and dsPIC30F | 1 W register |
_long _Fract | dsPIC33C/E/F and dsPIC30F | 2 W registers, aligned to even numbered register |
_Accum | dsPIC33C/E/F and dsPIC30F | 3 W registers, aligned to a quad numbered register |
struct | dsPIC33C/E/F and dsPIC30F | 1 register per 2 bytes in structure |
dsPIC33A | 1 register per 4 bytes in structure | |
Note 1: double
is equivalent to long double if
-fno-short-double is used. |