The Two Forth Stacks
Some parts of this page/site are currently incomplete & will be updated asap
Other parts will change continually so use “Refresh” in your browser !!
There is extensive use of “Tooltips” text to support learning which do not seem to render on a Smartphone
What is a “Stack”?
A stack is an abstract data type that serves as a collection of elements, with two main principal operations:
- Push, which adds an element to the collection, and
- Pop, which removes the most recently added element that was not yet removed.
The order in which elements come off a stack gives rise to its alternative name, LIFO (last in, first out).
Image#1: The operation of a “LIFO stack” Source: Wikipedia
Using Two Stacks
Forth uses two stacks to hold its working data
The Parameter Stack (“The Stack”)
This is usually the microprocessor’s stack, via its Program Counter (“PC”), so the Parameter Stack gives direct access to the machine’s stack, a very powerful facility. As its name suggests it is used for passing parameter values to and from Forth words
The Return Stack
The Return Stack is the Forth Virtual Machine’s Program Counter (“PC”) 1 and allows a Forth word to return to the Forth word that invoked it
So merely a high-level version of the microprocessor’s PC & Stack ↩