Be aware of library usage, Use more efficient data types – Echelon Neuron C User Manual
Page 215

Neuron C Programmer’s Guide
203
The Neuron C utility functions include byte-manipulation functions, such as
high_byte( ), low_byte( ), make_long( ), and swap_bytes( ). There are bit-
manipulation functions such as clr_bit( ), reverse( ), rotate_long_left( ),
rotate_long_right( ), rotate_short_left( ), rotate_short_right( ), set_bit( ), and
tst_bit( ).
For extended precision arithmetic, Neuron C provides the muldiv( ), muldivs( ),
muldiv24( ), and muldiv24s( ) functions. These functions permit a multiply
operation, followed by a divide operation, with the intermediate result and the
operations using either 32-bit or 24-bit precision.
The Neuron C functions also include such utilities as the timers_off( ) function.
This function turns off all application timers with a single function call. This
function call takes less space than the corresponding assignment of zero to a
single timer, although it takes longer to execute. Thus, if your program contains
a single application timer, and you turn it off by assigning zero to it, consider
using this function instead in order to save code space.
Other miscellaneous functions include bcd2bin( ) and bin2bcd( ), delay( ) and
scaled_delay( ), and random( ).
All of the Neuron C functions are described in detail, with examples, in the
Neuron C Reference Guide
.
Be Aware of Library Usage
Be aware of the system functions that are placed in application memory (see the
table in the
Neuron C Reference Guide
for a complete list of the functions placed
in memory for each chip and each version of firmware). If possible, avoid use of
such things as signed bitfields in structures that cause use of library functions.
Use More Efficient Data Types
The Neuron C compiler generates more compact code when the data items and
operations on them more closely match the underlying machine architecture and
instruction set. If possible, change variables to be local rather than global, to be
short rather than long, and to be unsigned rather than signed.
For example, consider the following function which finds an occurrence of value
in the array a and returns the index where value was located:
for (i=0; i if (a[i] == value) break; } i; } When this function is compiled, the following code sizes are obtained corresponding to the data types shown: 25 bytes 24 bytes 34 bytes 34 bytes
return