
Compiler Conventions
3-9
3.2.3 Conventions Used for Passing Parameters
SDCC/ZDXCC’s conventions for passing parameters are described
below.
The first three (16-bit) word parameters (scalar type) are passed in
registers r4–r6.
All other parameters are passed on the stack.
A 16-bit value is returned in r4; a 32-bit value is returned in r5r4.
A structure is returned using a hidden pointer, which is passed by
the caller in r4.
A structure is passed using two arguments. The first argument is a
pointer to the structure, and the second argument is the structure to
be passed. The pointer to the structure is a 16-bit value and can be
passed in a register if it is one of the first three word-sized
arguments. The second argument, the structure, is passed on the
stack. For structures with a size of one or two words, the pointer
argument is eliminated.
ZDCC’s conventions for passing parameters are described below.
Parameters are examined from first to last
A pointer value will be passed in the first unused register in the
following list: a0, a1, a6, r5r4, r7r6, r3r2.
A 32-bit non-pointer value will be passed in the first unused register
in the following list: r5r4, r7r6, r3r2, a0, a1, a6.
4. With SDCC/ZDXCC, the mre mode bit affects nonintrinsic code if the -minfer_mac
option is used.
5. This bit is ZSP400 specific and selects/unselects the use of shadow registers. Com-
piled code operates correctly with either shadow registers or nonshadow registers.
6. For ZSPG2, these bits affect the behavior of r14 and r15. They exist for compatibility
with ZSP400. They should never be set in code compiled with the ZDCC. When using
SDCC/ZDXCC, to prevent these bits from affecting nonintrinsic code, clear these bits
when the portion of code requiring circular buffers is exited.
7. This bit controls whether instructions are fetched from internal or external memory.
Compiled code operates correctly when it resides in internal or external memory,
though normally it resides in internal memory.
8. This bit controls whether data is fetched from internal or external memory. Compiled
code operates correctly when data resides in internal or external memory, though nor-
mally data resides in internal memory. Note that data includes the stack, and that
compiled code does not operate correctly if global data resides in one memory and
the stack resides in another memory.