H4th - Stack

Programming in Forth
Post Reply
Admin
Site Admin
Posts: 15
Joined: Tue Apr 02, 2019 5:29 pm

H4th - Stack

Post by Admin » Fri Apr 26, 2019 5:47 pm

Here are some stack commands for H4th. They can be very useful as they give stack information without actually changing anything on the stack.

The first, DEPTH, just puts the count of items onto the stack.
The second, STACK, print out the stack items.
The third word, 0STACK, will clear all items on the stack.

HEX
: DEPTH FC90 @ SP@ - 2 / 1 -;
: STACK SP@ FC90 @ - IF
SP@ FC90 @
DO I 2 - @ U. -2 +LOOP THEN ;
: 0STACK FC90 @
CODE D7 E5 FD E1 ;C ;


examples:

1 2 3 DEPTH .
STACK
0STACK
DEPTH .
STACK


will return

3 OK
1 2 3 OK
OK
0 OK
OK

Post Reply