I have been programming with FORTH for a number of years now and have used it on the 1802, PDP-11, 6502, 8080, Z-80, 68000, 8086, V-20, 80286, and the 68HC11 CPU’s. The different CPUs have many different assembly languages and when writing programs that you want to run on all the machines you can have a nightmare of problems. BASIC and C are languages that have been used among many programmers, but they require large machines with conversion routines to make it work on each CPU. FORTH has been written for each CPU and can be run fully in 8 to 16K on any CPU. If you write a FORTH program on one CPU then it will run on any other CPU if it is the same version of FORTH.
Most programmers have difficulties with understanding FORTH. When Charles Moore first wrote FORTH it was in answer to his Professors at MIT who said you can’t do that. It is easier for a programmer who understands assembly code to use FORTH than any other language. FORTH is a threaded language, building new words on a basic set of primitive words written for each CPU. A baseline FORTH is set up to act like a CPU attached to a dumb terminal. As each machine has added color graphics and sound, different new words are added to take advantage of all the features. When writing programs for other CPUs, the additional features must not be used or the programs will not work. Each version of FORTH has an EDITOR and Assembler to allow faster programs to be written and stored for future use. Like BASIC a FORTH program can be run as it is written, to check operation. After a program is checked it is written to a screen and stored for future use. By loading the screens, new words are added to the dictionary when needed. As words are used, they can be removed and the space used for new words. After a complete routine has been developed, the meta-compiler can remove all unneeded words and a compact program can be put in ROM and added to a stand-alone CPU for a final product.
Some of those products are used in robotics, HOBART scales, badge readers, microwave controllers, ATARI games, micro-controllers, data base software, graphics software, and CPU internal code.
The FORTH teaching guide that is most used is the book by Leo Brodie, “STARTING FORTH”. This book explains the basic words that are common to all FORTH versions. It has cartoons that show the operation of each word in a way that even children can understand. It also makes it easier to remember how each word is used as you are programming. Leo also wrote a newer book “MASTERING FORTH” to give you examples of programs you can try.
This is a few of the reasons that FORTH is used. Many say either you hate it or you love it. I use it as part of my programming needs. I like many of the built-in features but sometimes it is harder to explain my programs to others that write in other languages. I have included some sample programs that I have found fun and useful. I hope you like them. The QL has several FORTH compilers available, some in the public domain.
I try to give FORTH demonstrations each year at COMPUTERFEST in Dayton each August. If you want to see them, see me at the COMPUTERFEST museum this year, 28 and 29 August at Hara Arena.
The following is an example of a FORTH program. It converts a DEC PDP-11 RAD50 word to ASCII characters. It is written in F83.
OCTAL VARIABLE RAD VARIABLE CH1 VARIABLE CH2 VARIABLE CH3
: CH1! 0 RAD @ 3100 MU/MOD CH1 ! 2DROP ;
: CH2! CH1 @ 3100 * RAD @ SWAP - DUP 50 / CH2 ! ;
: CH3! CH2 @ 50 * - CH3 ! ;
: ANSWER RAD ! RAD @ U. CH1! CH2! CH3! CH1 ? CH2 ? CH3 ? ;
: ANS DUP 0= IF SPACE DROP ELSE DUP 33 < IF 100 + EMIT
ELSE DUP 33 = IF 44 EMIT DROP ELSE DUP 34 = IF 56 EMIT
DROP ELSE DUP 35 = IF ." spec" DROP ELSE 22 + EMIT
THEN THEN THEN THEN THEN ;
: READ CR ANSWER CH1 @ ANS CH2 @ ANS CH3 @ ANS ;
To use enter RAD50 number READ to print conversion.
Such as: 174777 READ
Answer: 174777 47 47 47 999
/ Set octal variables for rad, ch1, ch2, and ch3.
/ ch1! stores octal value in ch1.
/ ch2! stores octal value in ch2.
/ ch3! stores octal value in ch3.
/ answer stores rad50 in rad and breaks out each octal value.
/ ans converts values to ascii characters.
/ read takes top of stack and prints rad50 values and characters.
Programs to convert Celsius to Fahrenheit to Kelvin to Rankine
: C>F 18 10 */ 32 + ;
: F>C 32 - 10 18 */ ;
: K>C 273 - ;
: C>K 273 + ;
: F>K F>C C>K ;
: K>F K>C C>F ;
: F>R 460 - ;
: R>F 460 + ;
: C>R C>F F>R ;
: R>C R>F F>C ;
Program to print a POEM on the screen
: POEM CR 11 1 DO I . ." little " I 3 MOD O= IF
." Indians" CR THEN LOOP ." Indian boys. " CR ;