Argument locations, Return values, Preserving registers – Zilog EZ80F916 User Manual
Page 173: Calling c functions from assembly

UM014423-0607
Using the ANSI C-Compiler
ZiLOG Developer Studio II
eZ80Acclaim!
®
User Manual
153
Argument Locations
The assembly function assigns the location of the arguments following the C calling con-
ventions as described in “Calling Conventions” on page 149.
For example, if you are using the following C prototype:
void myfunc(short arga, long argb, short *argc, char argd, int arge)
The arguments are placed on the stack, and their offsets from Stack Pointer (SP) at the
entry point of an assembly function are as follows:
arga: –3(SP)
argb: –6(SP)
argc: –12(SP)
argd: –15(SP)
arge: –18(SP)
Return Values
The assembly function returns the value in the location as specified by the C calling con-
vention as described in “Calling Conventions” on page 149.
For example, if you are using the following C prototype:
long myfunc(short arga, long argb, short *argc)
The assembly function returns the long value in registers E:HL.
Preserving Registers
The eZ80Acclaim! C-Compiler implements a caller save scheme. The assembly function
is not expected to save and restore the registers it uses (unless it makes calls to C func-
tions; in that case, it must save the registers it is using by pushing them on the stack before
the call).
CALLING C FUNCTIONS FROM ASSEMBLY
The C functions that are provided with the compiler library can also be used to add func-
tionality to an assembly program. You can also create your own C function and call them
from an assembly program.
NOTE: The C-Compiler precedes the function names with an underscore in the generated
assembly. See “Function Naming Convention” on page 152.
The following example shows an assembly source file referencing the
sin
function:
•
•