beautypg.com

Echelon Neuron User Manual

Page 68

background image

#pragma num_alias_table_entries 0

#pragma include_assembly_file “checksum.ns”

extern unsigned Checksum(unsigned, const char*);

void TestCall(void) {

unsigned cs;

cs = Checksum(8, “ABCDEFGH”);

}

The Neuron C compiler reads the Checksum function arguments from right to

left, and pushes them onto the stack so that the first argument (unsigned) is in

TOS, the top of the stack. When the function completes, the compiler expects the

function result (cs) on the data stack. Thus, the function must digest all

arguments and local variables before returning to the caller.
The #pragma include_assembly_file compiler directive instructs the compiler

to include the assembly source file, but the compiler does not parse the included

assembly file. Likewise, the compiler does not analyze the included assembly

code to ensure that there is an appropriate Neuron C function prototype for the

assembly implementation. You must provide a proper function prototype,

typically in a header file. In addition, you muse ensure that the number, order,

and type of arguments, and any results, are correct, both in the Neuron C

function prototype and in the Neuron assembly implementation.
Note that certain Neuron C specifications have no direct correspondence in a

Neuron assembly function. For example, the declaration of the pData argument

as const (a variable pointer to constant data) is correct from a C language point

of view, but it is your responsibility in the assembly function to ensure that this

data is not modified.

58

Exploring an Example Function in Neuron Assembly