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.
  • DSRPAG/PSVPAG should be preserved if the -mconst-in-code (auto_psv) memory model is being used.
Table 14-1. Registers Required
Data Type Number of Working Registers Required
char 1
int 1
short 1
pointer 1 (eds pointer requires 2)
long 2 (contiguous – aligned to even numbered register)
float 2 (contiguous – aligned to even numbered register)
double* 2 (contiguous – aligned to even numbered register)
long double 4 (contiguous – aligned to quad numbered register)
structure 1 register per 2 bytes in structure
_Fract 1
long _Fract 2 (contiguous – aligned to even numbered register)
_Accum 3 (contiguous – aligned to quad numbered register)
* double is equivalent to long double if -fno-short-double is used.

Parameters are placed in the first aligned contiguous register(s) that are available. The calling function must preserve the parameters, if required. Structures do not have any alignment restrictions; a structure parameter will occupy registers if there are enough registers to hold the entire structure. Function results are stored in consecutive registers, beginning with W0.