Echelon Neuron User Manual
Page 60

This optimization is leads to more efficient code (as the called function might
consume its arguments rather than working on copies), and leads to more stack-
efficient programs.
Example:
This example assumes a utility written in Neuron assembly that has the
following function prototype in Neuron C:
extern unsigned Checksum(unsigned size, const char* pData);
When calling this function, the pointer argument pData is pushed onto the stack
first (right to left), followed by the size argument. When the function call returns,
the unsigned result of the Checksum function is found on top of the data stack.
The pData and size arguments are no longer available on the data stack.
Consider the following Neuron C code, which calls the assembly-language code
function %Checksum in the Testcall function:
#pragma include_assembly_file “checksum.ns”
extern unsigned Checksum(unsigned, const char*);
void Testcall(void) {
unsigned cs;
cs = Checksum(8, “ABCDEFGH”);
}
For this Neuron C code, the Neuron C compiler translates the Testcall function
into the following assembly code (taken from the assembly listing of the compiler-
generated code):
IMPORT
%Checksum
SEG CODE
ORG
0000 _%MYDEVICE%STR1
EXPORT
0000 41 42 DATA.B
41,42,43,44,45,46,47,48
0002 43 44 45 46
0006 47 48
0008 00 DATA.B
0
SEG CODE
ORG
0000 %Testcall
APEXP ; Function body
0000 C0 ALLOC #1
0001 B5 0000* PUSHD #_%MYDEVICE%STR1
0004 B4 08 PUSH #8
0006 77 0000* CALLF %Checksum
0009 E5 DROP NEXT
000A 7F DEALLOC
#1
The listed code performs the following tasks:
1. First, the compiler generates an IMPORT %Checksum statement as
result of the Neuron C function prototype specification.
2. In the first code segment (SEG CODE), the compiler allocates initialized
data for the anonymous constant string variable using the compiler-
generated name _%MYDEVICE%STR1 (the “MYDEVICE” part of the name
is derived from the name of the Neuron C file). The DATA.B directive
50
Interfacing with a Neuron C Application