How to Write Computer Programs Using Forth

Learn about the FORTH kernel: The FORTH kernel is the entire FORTH development environment., Learn about the command line interpreter: The command line interpreter receives input from the user., Learn about the STACKS., Learn the difference between...

9 Steps 2 min read Medium

Step-by-Step Guide

  1. Step 1: Learn about the FORTH kernel: The FORTH kernel is the entire FORTH development environment.

    It is interactive and extensible, and consists of the parts described as follows:
  2. Step 2: Learn about the command line interpreter: The command line interpreter receives input from the user.

    If the input is a FORTH word, the interpreter tries to execute it.

    It the input can be interpreted as a number, the interpreter put the value on the stack.

    It is is neither of these, the interpreter gives a message like "UNDEFINED WORD" or "Huh?" depending on the sense of humor of the person that implemented the version of FORTH. , Access to a CPU stack is very fast.

    Access to external memory is much slower.

    Avoid external memory when things need to be fast, and use external memory when things need to be saved. , The data stack is usual referred to as 'the stack' and the return stack is specifically referenced as the 'return stack'.

    In most cases, the user manipulated values on the data stack (the stack), while the return stack hold the value of the routine that called the one currently executing.

    The return stack is somethings used to temporarily store values within a single function, but care must be taken not to interfere with the return value that must be present at the end of the function. ,, The user adds definitions to the dictionary using previously define FORTH words in the dictionary , The FORTH words (routines) that access memory are usually some form of @ "fetch from memory" and ! "store to memory". @ and ! usually fetch and store values of the default cell size defined for the system.

    Other size values are C@ and C! for character (8 bit byte), W@ and W! for word (16 bit 2 byte) L@ and L! for LONG (32 bit 4 byte).

    Other memory access can be defined as EC@ and EC! for EEPROM character fetch and store, and so on depending on the system implementation. , This is usually the starting point as a reference for a FORTH system.

    Any variations from the standard are usually stated for the convenience of the intended users. ,
  3. Step 3: Learn about the STACKS.

  4. Step 4: Learn the difference between the Data Stack and the Return Stack.

  5. Step 5: Learn about the 'extra stack': many implementation have a third stack used for advanced math functions.

  6. Step 6: Learn about the dictionary structure: The FORTH dictionary is list of FORTH words that are the routines used in FORTH.

  7. Step 7: Learn about memory access: External memory access refers to RAM or any memory external to the CPU.

  8. Step 8: Learn about the DPANS94 standard: DPANS94 is the formal ANSI-FORTH standard.

  9. Step 9: Find the references: STARTING FORTH and THINKING FORTH are two of the common references used to learn about FORTH

Detailed Guide

It is interactive and extensible, and consists of the parts described as follows:

If the input is a FORTH word, the interpreter tries to execute it.

It the input can be interpreted as a number, the interpreter put the value on the stack.

It is is neither of these, the interpreter gives a message like "UNDEFINED WORD" or "Huh?" depending on the sense of humor of the person that implemented the version of FORTH. , Access to a CPU stack is very fast.

Access to external memory is much slower.

Avoid external memory when things need to be fast, and use external memory when things need to be saved. , The data stack is usual referred to as 'the stack' and the return stack is specifically referenced as the 'return stack'.

In most cases, the user manipulated values on the data stack (the stack), while the return stack hold the value of the routine that called the one currently executing.

The return stack is somethings used to temporarily store values within a single function, but care must be taken not to interfere with the return value that must be present at the end of the function. ,, The user adds definitions to the dictionary using previously define FORTH words in the dictionary , The FORTH words (routines) that access memory are usually some form of @ "fetch from memory" and ! "store to memory". @ and ! usually fetch and store values of the default cell size defined for the system.

Other size values are C@ and C! for character (8 bit byte), W@ and W! for word (16 bit 2 byte) L@ and L! for LONG (32 bit 4 byte).

Other memory access can be defined as EC@ and EC! for EEPROM character fetch and store, and so on depending on the system implementation. , This is usually the starting point as a reference for a FORTH system.

Any variations from the standard are usually stated for the convenience of the intended users. ,

About the Author

G

Gary Reyes

Dedicated to helping readers learn new skills in DIY projects and beyond.

49 articles
View all articles

Rate This Guide

--
Loading...
5
0
4
0
3
0
2
0
1
0

How helpful was this guide? Click to rate: