Preserving registers, Calling c functions from assembly, Assembly file – Zilog ZUSBOPTS User Manual
Page 204

Calling C Functions from Assembly
UM017105-0511
176
Zilog Developer Studio II – ZNEO™
User Manual
Preserving Registers
The ZNEO C-Compiler implements a scheme in which the registers R8–R13 are treated as
callee save. The assembly function must preserve any of these registers that it uses. The
assembly function is not expected to save and restore the flag register.
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 functions and call them
from an assembly program.
Because the compiler makes the caller function responsible for saving registers R0–R7
(see the
section on page 172), if the assembly code is using any of
these functions and needs their contents to be preserved across the C function call, it must
save them before the call and restore them afterwards.
The C-Compiler precedes the function names with an underscore in the generated assem-
bly. See the
The following example shows an assembly source file referencing the function
sinf
. The
sinf
function is defined in the C library.
Assembly File
globals on
xref _sinf
segment near_data
val:dl %3F060A96; 0.523599
res:dl 0
segment code
_main:
pushm
; save the registers, other than return register, if any in
use
ld R1,val; load the argument
call _sinf; call the c functions
ld res,r0 ; the result is in r0
Note: