Here is the set of Auxiliary stack words I've settled on:
Code:
SCR# 2A
// >A
HEX
CODE >A ( S: N -- ) ( A: -- N )
HERE 6 + JSR, POP JMP,
AP0 @ LDY, DEY, DEY,
0< IF,
>FORTH
TRUE ABORT" AUX STACK FULL!"
>ASSEM -2 ALLOT
THEN,
0 ,X LDA, APLIM @ ,Y STA,
1 ,X LDA, APLIM @ 1+ ,Y STA,
AP0 @ STY,
RTS,
END-CODE
SCR# 2B
// DUP>A 2>A CS>A
HEX
CODE DUP>A ( S: N -- N ) ( A: -- N )
' >A @ 6 + JSR,
NEXT JMP, END-CODE
CODE 2>A ( S: D -- ) ( A: -- D )
INX, INX, ' >A @ 6 + JSR,
DEX, DEX, ' >A @ 6 + JSR,
POPTWO JMP, END-CODE
CODE CS>A ( S: CS -- ) ( A: -- CS )
-2 ALLOT
' 2>A @ , END-CODE
SCR# 2C
// A>
HEX
CODE A> ( S: -- N ) ( A: N -- )
HERE 6 + JSR, NEXT JMP,
AP0 @ LDY,
AP0 @ 1- 0FF AND # CPY,
0< NOT IF,
>FORTH
TRUE ABORT" AUX STACK EMPTY!"
>ASSEM -2 ALLOT
THEN,
DEX, DEX,
APLIM @ ,Y LDA, 0 ,X STA,
APLIM @ 1+ ,Y LDA, 1 ,X STA,
INY, INY, AP0 @ STY,
RTS, END-CODE
SCR# 2D
// A@ 2A> A>CS
HEX
CODE A@ ( S: -- N ) ( A: N -- N )
' A> @ 6 + JSR,
DEY, DEY, AP0 @ STY,
NEXT JMP, END-CODE
CODE 2A> ( S: -- D ) ( A: D -- )
' A> @ 6 + JSR,
' A> @ 6 + JSR,
' SWAP @ JMP, END-CODE
CODE A>CS ( S: -- CS ) ( A: CS -- )
-2 ALLOT
' 2A> @ , END-CODE
AP0 and
APLIM are Fleet Forth user variables.
AP0 is $256 and
APLIM is $200. Location $256 also serves as storage for the Aux stack pointer. This address range is part of the BASIC input buffer on the Commodore 64. Fleet Forth uses the address range $2A7 - $2FF , an otherwise unused section, for its text input buffer.
In Fleet Forth, the control flow stack is the data stack and each control flow stack item ( CS ) is two cells, an address and a security number, so
CS>A is an alias for
2>A and
A>CS is an alias for
2A>.
The Aux stack words
>A ,
DUP>A ,
2>A ,
A> ,
A@ and
2A> are slower than their return stack counterparts, even though they are defined in code, but could be useful when testing a new word that needs to place temporary data to the return stack. Use these words to use the Aux stack instead of the return stack to test the new word or words since an Aux stack overflow or underflow will not, of itself, cause a system crash ( unlike the return stack). It is also easier to see what is happening if the only data on the extra stack is only what the word under test placed there ( or was placed there for it ). When the new word works successfully, the Aux stack words can be replaced with their return stack counterparts.
To see what is on the Aux stack, here is
.ASCode:
SCR# 35
// ADEPTH .AS
HEX
: ADEPTH ( -- N )
AP0 @ [ AP0 @ ] LITERAL @ - 2/ ;
: .AS ( -- )
SETWIDTH ADEPTH DUP 0
?DO
AP0 @ I 2* - 2- @
16BITS DUP 2+ ?CR U.R SPACE
LOOP
?EXIT
." EMPTY " ;
.S was rewritten so it never aborts:
Code:
HEX
: .S ( -- )
SETWIDTH
DEPTH DUP 0 MAX 0
?DO
DEPTH I - 1- PICK
16BITS DUP 2+ ?CR U.R SPACE
LOOP
?EXIT
." EMPTY " ;
and
ABORT , which is called by the word compiled by
ABORT" , is defined as:
Code:
: ABORT ( -- )
ERR SP! AP! QUIT ; -2 ALLOT
ERR is a deferred word that is normally set to execute
NOOP , a no-op.