Interrupt tasks with assembly code – Echelon Neuron User Manual
Page 49

pushd [SCRATCH16] ; (r(2), piDiv(2))
pushd [SCRATCH16] ; (r(2), r(2), piDiv(2))
; push the “second half” of pi:
pushd #PIFACTOR ; (PiFac(2), r(2), r(2), PiDiv(2))
; do the math:
call _mul16 ; ((piFac*r)(2), r(2), piDiv(2))
brf muldiv ; ( -- carea)
For this implementation, the Neuron assembly file imports the two external
functions: _mul16 and muldiv. The _mul16 function has a preceding
underscore because it is intended for use only with assembly functions. Note that
neither the _mul16 nor the muldiv function names has a percent sign (%) prefix.
The _mul16 system function is not defined in, or designed for, the Neuron C
application name space. The muldiv function is designed for the Neuron C
application name space, but is imported using the system keyword in Neuron C,
which makes the symbol available without the percent sign (%) prefix.
The assembly file then defines two mnemonics for the pi value approximation,
and defines a mnemonic for one of the general-purpose 16-bit registers. This
register temporarily holds a 16-bit value; as long as we do not interpret such a
value as a pointer, these registers can hold any 16-bit value, even though they
are typically used for pointer values.
The %carea function is then declared, using the percent sign (%) prefix, with the
APEXP directive to make this symbol available to the Neuron C application
name space.
The %carea function then sets up the stack for calling the _mul16 and muldiv
functions. Note that because the _mul16 function is located in the near code
area, it can be called with the two-byte CALL instruction, rather than the
slightly less efficient three-byte CALLF instruction.
By setting the stack up correctly, the carea function can branch into the muldiv
function (using the BRF instruction), rather than having to call the muldiv
function (using the CALLF and RET instructions). The carea function can use
the branch instruction because the stack layout for executing the muldiv
function is correct, and contains only the arguments for the muldiv function.
Also, the result type of the carea function is the same as that of the muldiv
function.
For more information about the _mul16 function, see _mul16 (Multiply, 16 Bit).
For more information about the muldiv() function, see the Neuron C Reference
Guide.
Interrupt Tasks with Assembly Code
For Series 5000 and 6000 devices, you can write an interrupt task to handle
hardware interrupts. Although you write the interrupt task in Neuron C, you
can include a Neuron assembly function in the Neuron C task using the
#pragma include_assembly_file compiler directive, or call a function written
in assembly from your interrupt task.
In general, interrupts run in a separate processor context on the Series 5000 and
6000 Chips, but for the lowest two clock rates (clock multiplier values ½ and 1 in
Neuron Assembly Language Reference
39