beautypg.com

Arrays, Structures and unions, Bitfields – Echelon Neuron User Manual

Page 62: Calling a neuron c function from assembly code

background image

Arrays

The Neuron Chip and Smart Transceiver hardware has no data alignment

requirement, beyond the natural byte alignment. Thus, arrays are consecutive

elements without intervening padding. The first element (the element at index

0) is at the lowest address of the array. The remaining elements appear

consecutively at addresses that increase as multiples of the array-element size.
Arrays are therefore packed objects with no unused space between the elements.

Array sizes are always exactly the size of an individual element multiplied by the

number of elements in the array.

Structures and Unions

A structure is a group of fields packed into consecutive byte locations. The first

field is at the lowest address of the structure. The remaining fields appear

consecutively at addresses that increase by adding the size of the previous fields

to the beginning address of the structure. The size of a structure is always

exactly the sum of the sizes of each individual element in the structure.
A union is a group of overlaid fields. Each field starts at the beginning of the

union. The size of a union is always exactly the maximum of the sizes of each

individual field in the union.

Bitfields

Bitfields in a Neuron C structure or union are always packed within one or more

bytes. A single bitfield cannot cross a byte boundary; thus, the maximum bitfield

size is eight bits. The first bitfield in a byte uses the most significant bits, and

subsequent bitfields within the byte use the next most significant bits until all

bits are used.
Anonymous bitfields of non-zero size are supported as placeholders, allowing for

exact positioning of the named bitfields within their container byte. Anonymous

bitfields of size zero always complete the current container.
A new byte is begun when a bitfield is encountered that is too large for the

remaining bits, or when an anonymous bitfield is encountered with size 0, or

when a non-bitfield object is encountered.

Calling a Neuron C Function from Assembly Code

When a Neuron assembly function calls a Neuron C function, the main task of

the assembly function is to prepare the stack for the function by pushing the

function arguments in the correct order, and to call the function. Because the

called function clears the stack as part of its operation, the calling assembly

function need only retrieve the function’s result data (if any) from the stack.
The general approach to calling Neuron C functions from assembly code includes

performing the following steps:

1. Import the symbol for the function.
2. Preserve all general-purpose registers in use.
3. Push the function arguments onto the data stack, from right to left.

52

Interfacing with a Neuron C Application