beautypg.com

Calling assembly functions from c, Function naming convention, Variable naming convention – Zilog EZ80F916 User Manual

Page 172

background image

UM014423-0607

Using the ANSI C-Compiler

ZiLOG Developer Studio II

eZ80Acclaim!

®

User Manual

152

Returning structure

If the function returns a structure, the caller allocates the space for the structure and
then passes the address of the return space to the called function as an additional and
first argument. To return a structure, the called function then copies the structure to the
memory block pointed to by this argument.

Not allocating a local frame
The compiler does not allocate a local stack frame for a function in the following case:

The function does not have any local stack variables, stack arguments, or
compiler-generated temporaries on the stack.

and

The function does not return a structure.

and

The function is compiled without the debug option.

CALLING ASSEMBLY FUNCTIONS FROM C

The eZ80Acclaim! C-Compiler allows mixed C and assembly programming. A function
written in assembly can be called from C if the assembly function follows the C calling
conventions as described in “Calling Conventions” on page 149.

The following sections describe how to call assembly functions from C:

“Function Naming Convention” on page 152

“Variable Naming Convention” on page 152

“Argument Locations” on page 153

“Return Values” on page 153

“Preserving Registers” on page 153

Function Naming Convention

Assembly function names must be preceded with an _ (underscore) in order to be callable
from C. The compiler prefixes C function names with an underscore in the generated
assembly. For example, a call to

myfunc()

in C is translated to a call to

_myfunc

in gen-

erated assembly by the compiler.

Variable Naming Convention

When the compiler generates an assembly file from C code, all names of global variables
are prefixed with an underscore.

Names of local static variables are prefixed with an underscore followed by a function
number to avoid assembly errors when the same local static variable occurs more than
once in the same file.

This manual is related to the following products: