Because it looks like you are trying to port some code from another Forth to FIG, I'll also give you my version of
.S (print stack) for FIG to print the number of items currently on the stack and their values without changing anything on the stack. This is my most-used word as I am developing Forth code or playing with someone else's code. It's included in many of the Forth standards, but doesn't come with FIG.
.S will print both the number of items on the stack and the values using the current BASE, but do be aware it is using
. to print the values so they will be negative if their most significant bit is set. You can make it print them as unsigned by changing the
. inside the
DO loop to
U. instead. Also, it doesn't know which items on the stack are doubles, so it will count and print each half separately.
Code:
HEX
( .S for FIG Forth )
( Adjust this constant to where the bottom of the stack is )
( on your system. If you do not know, you can use: )
( HEX SP@ . with an empty stack to find out. )
9E CONSTANT STACKBOTTOM
: .S ( -- ) ( Print stack debugging info )
( Print number and items on stack with TOS at right )
SP@ DUP STACKBOTTOM SWAP - 2 / ( determine # of items )
DUP ." <" 1 .R ." > " ( print # of items )
( Only print the list if there is a non-zero number of items )
IF 2 - STACKBOTTOM 2 - DO
I @ . -2 +LOOP
ELSE DROP THEN ;
DECIMAL
Here's an example run:
Code:
.s <0> OK
1 2 3 OK
.s <3> 1 2 3 OK
5. OK
.s <5> 1 2 3 5 0 OK
65535 OK
.s <6> 1 2 3 5 0 -1 OK
The number in angle brackets is how many numbers are on the stack and then the stack values are printed with the top of stack on the right. Note the double 5 is printed as 5 and 0 (most significant word ends up on top of stack for a double) and then 65535 (decimal) is the same bit pattern as -1 and this version always prints the signed value.