The compiler partitions the MAXQ30 general purpose registers into two sets.

The registers in the first set, A[4] through A[7], are used for parameter passing and returning function results and are not preserved across functions calls. In addition the registers DP[0], DP[1], LC[0], LC[1], BP, OFFS, and AP are not preserved across a function call.

The registers in the second set, A[0]A[3] and A[9]A[15], are used for register variables, working storage, and temporary results and must be preserved across function calls.

Fixed registers

For correct execution of C code, the compiler makes a number of assumptions about the state of the MAXQ30 processor during program execution. It does this both to reduce code size and increase execution speed, usually you won't need to be aware of what assumptions the C compiler makes. However, if you are interfacing C code to assembly language subroutines, or calling C code from your own assembly language subroutines, you must be aware of the following points.

For correct execution of C programs the control register APC must be set such that APC.0 and APC.1 are both zero indicating default mode, no incrementing of AP.

In particular, note that if you call a C subroutine from assembly code, you must ensure that APC is set as above before making the call to the function.

Parameter Passing

The compiler uses the scratch registers to pass values to the called routine for all parameters of simple data type. If there are not enough scratch registers to hold all parameter data to be passed to the called routine, the excess data are passed on the stack.

Simple data types which require more than a single word of storage are passed in register pairs or register quads. The register requirement for the basic data types are:

Allocation of the scratch registers for function calls proceeds in a left-to-right fashion, starting with register A[7] and progressing in reverse order to A[4]. The compiler tries to fit each parameter into the scratch registers and, if it can, allocates those registers to the incoming parameter. If the parameter requires more scratch registers than are free, it is noted and is passed on the stack. All parameters which are passed on the stack are pushed in reverse order.

Function return values

The compiler uses the scratch registers to return values to the caller.

Note that structure return types are not currently supported by the compiler and consequently the C library functions div, ldiv and lldiv are not supported.