Calling conventions – Echelon Neuron User Manual
Page 59

In typical C-language implementations of such functions, the caller is responsible
for removing the arguments from the stack after the function completes. But for
Neuron assembly language functions, the called function must ensure that all
arguments are consumed (removed from the stack) before returning to the caller.
Only function results can remain on the data stack. This calling convention
typically allows for more compact code, given the Neuron Chip’s stack-oriented
architecture.
Calling Conventions
Depending on its use, an assembly language function can use different calling
conventions:
•
Assembly-coded functions that are used exclusively by other assembly-
coded functions can employ any appropriate calling conventions for
efficiency or ease of use. For example, a function could pass pointer
arguments through general-purpose pointer registers.
•
Any function that calls, or might be called from, code that is generated by
the Neuron C compiler must meet the guidelines described in this section.
To avoid naming collisions, the Neuron C compiler enforces the following naming
convention for global and static data:
•
Firmware labels begin with alphabetic characters.
•
Firmware labels that are used as interfaces for application code are
prefixed with the underscore (_) character.
•
Global labels are prefixed with the percent sign (%). For a Neuron C
variable or function name, the % character is added by the compiler, not
the programmer. For Neuron assembler functions or data that interface
with Neuron C, you must be sure to add the % character for all exported
labels. When importing symbols from a Neuron C application into your
assembly programming project, you must also add the % character for all
imported symbols.
•
Static labels are also prefixed with the percent sign (%). A Neuron C
static segment label is the % character plus name of the module (without
the file extension) plus another % character and a unique number
generated by the compiler. For example, an anonymous string “ABC”
argument for a function call within a file named MyDevice.nc might be
named %MYDEVICE%STR1 by the compiler.
Your Neuron assembly functions must follow the same naming convention so that
the functions can interface with Neuron C programs.
Functions exchange arguments and results on the data stack. When calling a
function, the caller pushes the function’s arguments onto the data stack, right to
left, in the order of the Neuron C function prototype.
However, unlike most implementations of the C language, in Neuron C, the
called function, not the caller, is responsible for clearing the arguments off the
data stack prior to returning to the caller. Thus, the called function must leave
only function results (if any) on the data stack.
Neuron Assembly Language Reference
49