beautypg.com

Calling c functions from assembly – Zilog Z8F0130 User Manual

Page 247

background image

UM013037-1212

Calling C Functions from Assembly

Zilog Developer Studio II – Z8 Encore!

User Manual

223

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.

In the C functions, all registers, other than return registers, are considered as caller save.
Therefore, the caller assembly function must make sure that it saves on the stack any reg-
isters that are in use before calling the C function and which also must be available after
the call. The caller assembly procedure then restores those registers after the return from
the C function. The flag register need not be saved and restored by the caller assembly
function.

The following example (the

Assembly File

section on page 224 and the

Referenced C

Function Prototype

section on page 224) shows an assembly source file referencing the

sin

function written in the large, dynamic model. The

sin

function is defined in the C

run-time library (

crtldd.lib

).

The C-Compiler precedes the function names with an underscore in the generated assem-
bly. See the

Function Naming Convention

section on page 221.

Note: