MPLAB C Compiler for PIC24 MCUs and dsPIC DSCs ... - Microchip
MPLAB C Compiler for PIC24 MCUs and dsPIC DSCs ... - Microchip
MPLAB C Compiler for PIC24 MCUs and dsPIC DSCs ... - Microchip
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
4.11 FUNCTION CALL CONVENTIONS<br />
Run Time Environment<br />
When calling a function:<br />
• Registers W0-W7 are caller saved. The calling function must push these values<br />
onto the stack <strong>for</strong> the register values to be preserved.<br />
• Registers W8-W14 are callee saved. The function being called must save any of<br />
these registers it will modify.<br />
• Registers W0-W4 are used <strong>for</strong> function return values.<br />
TABLE 4-2: REGISTERS REQUIRED<br />
Data Type Number of Registers Required<br />
char 1<br />
int 1<br />
short 1<br />
pointer 1<br />
long 2 (contiguous – aligned to even numbered register)<br />
float 2 (contiguous – aligned to even numbered register)<br />
double* 2 (contiguous – aligned to even numbered register)<br />
long double 4 (contiguous – aligned to quad numbered register)<br />
structure 1 register per 2 bytes in structure<br />
* double is equivalent to long double if -fno-short-double is used.<br />
Parameters are placed in the first aligned contiguous register(s) that are available. The<br />
calling function must preserve the parameters, if required. Structures do not have any<br />
alignment restrictions; a structure parameter will occupy registers if there are enough<br />
registers to hold the entire structure. Function results are stored in consecutive<br />
registers, beginning with W0.<br />
4.11.1 Function Parameters<br />
The first eight working registers (W0-W7) are used <strong>for</strong> function parameters.Parameters<br />
are allocated to registers in left-to-right order, <strong>and</strong> a parameter is assigned to the first<br />
available register that is suitably aligned.<br />
In the following example, all parameters are passed in registers, although not in the<br />
order that they appear in the declaration. This <strong>for</strong>mat allows the compiler to make the<br />
most efficient use of the available parameter registers.<br />
EXAMPLE 4-1: FUNCTION CALL MODEL<br />
void<br />
params0(short p0, long p1, int p2, char p3, float p4, void *p5)<br />
{<br />
/*<br />
** W0 p0<br />
** W1 p2<br />
** W3:W2 p1<br />
** W4 p3<br />
** W5 p5<br />
** W7:W6 p4<br />
*/<br />
...<br />
}<br />
The next example demonstrates how structures are passed to functions. If the<br />
complete structure can fit in the available registers, then the structure is passed via<br />
registers; otherwise the structure argument will be placed onto the stack.<br />
© 2008 <strong>Microchip</strong> Technology Inc. DS51284H-page 73