beautypg.com

Overview, Naming conventions, Function parameters – Echelon Neuron User Manual

Page 58

background image

Overview

Typically, you use Neuron assembly language to create utilities that can be used

with an application that is written in Neuron C. The Neuron C program code

might call functions defined in Neuron assembly, or a Neuron assembly function

might call a Neuron C function or program.
This chapter describes the conventions that a Neuron assembly language

function must follow when interfacing with Neuron C functions, including data,

calling and naming conventions.
See the following sections for information about integrating, assembling, and

linking your assembly program with the Neuron C application: Integrating the

Program, Assembling the Program, and Linking the Program.

Naming Conventions

Within a Neuron assembly file, declare functions, variables, or any other linkable

item that interfaces with the Neuron C application, with a percent-sign prefix.

This declaration allows the symbol to become part of the Neuron C name space.
To make the symbol and its meaning available to the Neuron C application, you

must provide its C language ‘extern’ specification (for variables and constants) or

its prototype (for functions).
Within a Neuron C file, when you specify an external symbol, the Neuron C

compiler automatically assumes a percent-sign prefix.
Example
:
The following example includes an assembly-coded function in a Neuron C

program:

#pragma include_assembly_file “checksum.ns”

extern unsigned Checksum(unsigned, const char*);

The compiler-generated calls to this function from the Neuron C application use

the name %Checksum. Thus, the assembly function must use the %Checksum

label with the APEXP directive:

%Checksum APEXP

... ; function body

ret ; return to caller

The Neuron C Compiler (and its companion tools, such as the Neuron Assembler

or Linker) cannot verify that the prototype (or extern specification that you

provide) actually matches the implementation in the assembly source file. It is

the programmer’s responsibility to ensure that the specification in Neuron C

matches the implementation in Neuron Assembly.

Function Parameters

Typically, an assembly language function is called with parameters. The

compiler pushes function arguments on the stack from right-to-left, so that the

last argument is in the TOS element of the stack. For example, for a function

with two arguments, such as Checksum(unsigned, const char*), the const char*

pointer is pushed first, and the unsigned argument is pushed into TOS.

48

Interfacing with a Neuron C Application