Previous: C Code restrictions, Up: Simple instructions [Contents][Index]
By default, the stacks grow towards lower addresses. You can change this
for a stack by setting the stack-access-transform
field of the stack
to an xt ( itemnum -- index )
that performs the appropriate index
transformation.
E.g., if you want to let data-stack
grow towards higher addresses,
with the stack pointer always pointing just beyond the top-of-stack, use
this right after defining data-stack
:
\E : sp-access-transform ( itemnum -- index ) negate 1- ; \E ' sp-access-transform ' data-stack >body stack-access-transform !
This means that sp-access-transform
will be used to generate indexes
for accessing data-stack
. The definition of
sp-access-transform
above transforms n into -n-1, e.g, 1 into -2.
This will access the 0th data-stack element (top-of-stack) at sp[-1], the
1st at sp[-2], etc., which is the typical way upward-growing stacks are
used. If you need a different transform and do not know enough Forth to
program it, let me know.