
6-18
SC100 C Compiler
Runtime Environment
6.4 Calling Conventions
The compiler supports a stack-based calling convention. Additional calling conventions are also supported.
Calling conventions can be mixed within the same application.
Specific calling conventions can be enforced using pragmas. For further information about the use of
pragmas for this purpose, refer to
Section 3.4.5,
“
Pragmas,
”
on page 3-54.
When compiling in separate compilation mode, non-static functions use the stack-based calling
convention.
6.4.1 Stack Pointer
The SP register serves as the stack pointer, which points to the first available location. The stack direction
is toward higher addresses, meaning that a push is implemented as
(sp)+
. The stack pointer must always
be 8-byte aligned.
6.4.2 Stack-Based Calling Convention
The following calling conventions are supported:
The first (left-most) function parameter is passed in
d0
if it is a numeric scalar or in
r0
if it is an
address parameter, regardless of its size. The second function parameter is passed in
d1
if it is a
numeric scalar, or in
r1
if it is an address parameter, regardless of its size. The remaining parameters
are pushed on the stack. Long parameters are pushed on the stack using little endian mode, with the
least significant bits in the lower addresses.
Structures and union objects that can fit in a register are treated as numeric parameters, and are
therefore candidates to be passed in a register.
Numeric return values are returned in
d0
. Numeric address return values are returned in
r0
.
Functions returning large structures, meaning structures that do not fit in a single register, receive
and return the returned structure address in
r2
. The space for the returned object is allocated by the
caller.
Functions with a variable number of parameters allocate all parameters on the stack.
Parameters are aligned in memory according to the base parameter type, with the exception of
characters and unsigned characters that have a 32-bit alignment.
The following registers are saved by the caller:
d0-d5
,
r0-r5
,
n0-n3
.
The following registers are saved by the callee, if actually used:
d6-d7
,
r6-r7
.
The compiler assumes that the current settings of the following operating control bits are correct:
Saturation mode
Round mode
Scale bits
The application is responsible for setting these mode bits correctly.