15.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 15-1. Registers Required
Data TypeNumber of Working Registers Required
char1
int1
short1
pointer1 (eds pointer requires 2)
long2 (contiguous – aligned to even numbered register)
float2 (contiguous – aligned to even numbered register)
double*2 (contiguous – aligned to even numbered register)
long double4 (contiguous – aligned to quad numbered register)
structure1 register per 2 bytes in structure
_Fract1
long _Fract2 (contiguous – aligned to even numbered register)
_Accum3 (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.