beautypg.com

Echelon Neuron User Manual

Page 116

background image

Examples:
The following example assumes that the stack contains two 16-bit elements, A

and B, with A nearest to the top of the stack. The example places a copy of B in

TOS and NEXT.

Example APEXP ; ( a(2), b(2) -– b(2), a(2), b(2) )

push [dsp][-2] ; ( msb(b), a(2), b(2) )

push [dsp][-2] ; ( lsb(b), a(2), b(2) )

ret ; ( b(2), a(2), b(2) )


The following example loads TOS with the contents of the general-purpose

register R0.

R0 EQU 8

Example APEXP ; ( -- r0)

push !R0 ; ( r0 )

ret ; return to caller


The following example calls the do_it_n function N times, with N >= 0 in TOS.

The number of remaining invocations is passed to the do_it_n function with each

call, which consumes its argument.

Example APEXP ; ( n -- )

poppush ; ( ) R(n)

loop_body ; ( ) R(n)

push [rsp] ; ( n ) R(n)

dec ; ( n-- ) R(n)

callf do_it_n ; ( ) R(n)

dbrnz loop_body ; ( ) R({n})

ret ; ( ) R( )


The following example loads TOS with the content of N-th byte in the base page.

N is passed into this example function in TOS.

Example APEXP ; ( n -– v )

push !tos ; ( n, v -- )

drop_r tos ; ( v )

106

Neuron Assembly Language Instruction Statements