beautypg.com

Data representation, Integers, characters, and strings, Multi-byte values – Echelon Neuron User Manual

Page 61

background image

also supports a string format, but does not automatically include the

terminating zero-byte. An alternative declaration would have been

_%MYDEVICE%STR1 DATA.B “ABCDEFGH”, 0.

3. In the second code segment (SEG CODE), the Testcall() function

(%Testcall APEXP), uses the ALLOC #1 instruction to allocate one

local variable on the data stack (for the unsigned cs local variable). It

then pushes the address of the string onto the stack using the immediate

push-double instruction PUSHD #_%MYDEVICE%STR1, followed by a

PUSH #8 instruction for the size parameter. Note that the value 8 is out

of range for the shorter PUSHS instruction (which has a 1-byte opcode),

so the PUSH instruction must be used instead (which has a 2-byte

opcode).

4. Then, the Checksum function is called with the CALLF instruction, a far

call that can target any location in the 64 KB address space.

5. Finally, the compiler assigns the function result (in TOS) to the local

variable (in NEXT) with a simple DROP NEXT instruction. The cs local

variable is now in TOS. With the end of the block (indicated by the

closing curly brace), the compiler-generated code frees the allocated stack

space with the DEALLOC #1 instruction. The DEALLOC instruction

also performs a return-from-call operation (equivalent to RET).

Data Representation

The following sections describe how various types of data are represented in the

Neuron assembly language. The data types described include integers,

characters, strings, multi-byte objects, arrays, structures, unions, and bitfields.

Integers, Characters, and Strings

Short integers and characters are stored as a single byte. The Neuron assembly

representation of a signed integer is in two's-complement form; thus, the same

instructions can be used for both signed and unsigned arithmetic. A variety of

firmware functions are used for other arithmetic operations, as described in

Chapter 8, System-Provided Functions.
A character string is an array of characters (thus, an array of bytes). Strings

that interface with Neuron C are expected to include a terminator byte of zero.
Each Neuron C global or static variable is defined as its own relocatable segment

within the appropriate segment type.

Multi-Byte Values

Multi-byte scalar objects (such as signed and unsigned long integers) are stored

as two consecutive bytes in big endian orientation: the most significant byte is

stored at the lower address. Whenever a long integer is pushed onto the data

stack, the most significant byte is pushed first (or popped last).

Neuron Assembly Language Reference

51