beautypg.com

Echelon Neuron User Manual

Page 67

background image

value formerly held in NEXT. Using this instruction prepares for the

loop construct that follows.

The POPD instruction takes two bytes from the stack (the pData

variable) and loads them into the general purpose register (P0, which was

equated to the mnemonic name pData).

The PUSHS instruction pushes a short immediate constant (value range

0..7) onto the stack. In this case, it pushes the value zero. The single

PUSHS instruction allocates the local cs variable, and initializes it to the

value zero.

The PUSH [pData][0] instruction uses the indirect-indexed addressing

mode to push the first byte in the array (index 0) addressed through the

pData value (pointer register P0) onto the stack.

The INC [pData] instruction uses pointer-direct addressing to increment

the pData pointer (P0).

The XOR instruction combines TOS and NEXT with a logical exclusive-

OR, leaving the result in TOS. Prior to this operation, TOS contains the

current byte read from the pData array, and NEXT contains the running

local cs variable.

The DBRNZ instruction completes the loop. The instruction first

decrements the value on the top of the return stack, which holds the

remaining size of the array that is being processed. If the resulting value

is zero, the loop index is removed from the return stack and processing

continues with the next instruction. If the resulting value is not zero,

however, processing continues at the indicated label cs_loop.

The RET instruction returns to the caller function by loading the

instruction pointer (IP) with the return address from the return stack

(which was below the loop counter). This return address is automatically

loaded onto the return stack when the Neuron C program calls the

function with the CALL, CALLR, or CALLF instruction.

Both stacks must be balanced when the function terminates: the data stack must

hold the correct number of bytes to match the return type at every return point

from the function, and the return stack should have the same number of bytes as

when the function was called. That is, unlike in many common C language

implementations, Neuron C and Neuron Assembly require that the called

function itself remove the function arguments from the data stack.

Including the Assembly Function in a Neuron C

Application

To include the Checksum function in a Neuron C application program, use the

#pragma include_assembly_file compiler directive. This directive instructs

the compiler to copy the content of the specified file directly into the assembly

output for the Neuron C program. This directive is available to IzoT NodeBuilder

tool users, and is the preferred method for working with simple assembly

language functions.
The following Neuron C program includes a TestCall() function that calls the

assembly-coded Checksum function:

Neuron Assembly Language Reference

57