The Forth Corner

THE 4TH CORNER heading logo with a cartoon of a reader holding a FORTH book
THE 4TH CORNER heading logo with a cartoon of a reader holding a FORTH book

For many of us, the BASIC language is an excellent high level language that allows the user to be introduced to the world of computers. We all now have some ability in at least elementary program creation.

If not, we can become quite comfortable in just using programs that have been written by someone else. We find we can balance our checkbooks, plan our diets, educate ourselves and our children in school and non-school subjects, analyze our reflex limitations, question our knowledge in various areas and, of course, play those ever available games, all with the aid of a computer.

Up to now, for most of us, the BASIC language is the only one we could identify with, mainly because of the owner’s manual and because most programs are available in BASIC.

We have seen machine language programs and routines and have been impressed with the speed and capabilities of machine code. We may have noticed that some effects occur that we cannot duplicate with the BASIC language, even at its slower speed. We have looked at the so-called “machine language made easy tutorials and many of us have walked away shaking our heads.

Enter “FORTH”!

WHAT IS FORTH?

FORTH is a high level language that allows us to write programs with an entry format that has similarities to BASIC but gives us much stronger computing capabilities and with a speed comparable to machine language.

As a matter of fact, FORTH allows the user to create command words and statements that link together existing FORTH commands. The user can then compile these commands into routines that operate much faster than BASIC.

I was intrigued with the idea of doing a review of PLURI-FORTH from TREE SYSTEMS. This is an interpreter program, resident in a ROM chip of a circuit board. The old BASIC ROM is removed from the ZX/TS machine and the PLURI-FORTH board is plugged in its place. The BASIC chip can then be soldered into the PLURI-FORTH board and a toggle switch added – but more on this later.

The reason I preferred the chip/board over a software program on cassette is twofold:

1. The FORTH language is resident in ROM and comes up running immediately and,

2. Since it replaces the BASIC ROM it is more memory-efficient, and with a 16K RAMpack the user has over 15K to work with.

The minimum configuration needed is 2K RAM. It won’t work on a 1K ZX-81 but it will work on a 2K TS-1000. It will work on either machine with a 16K RAMpack. It uses about 1/2 K of the 2K or16K RAM along with the 8K ROM.

On the ZX/TS computers, we have the FAST and SLOW modes. These also exist with PLURI-FORTH. But FORTH also has another mode called AUTO. This mode will make a program operate in the SLOW mode automatically until it reaches a situation where it is going to do some calculating that requires more than 1/4 of a second. It will then send the program automatically into the FAST mode until the calculating is done and then return to the SLOW mode.

I did some benchmark timing tests on the ZX/TS machines in the SLOW mode with the following program:

10 FOR N = 1 TO 10000
20 NEXT N

It took 43 seconds for this program to RUN. PLURI-FORTH has a similar routine called a DO-LOOP. A DO-LOOP can count from 1 to 20,000 in one second.

Sounds impressive, doesn’t it!

FORTH is not as easy to learn as BASIC (what’s that you say – BASIC isn’t that easy to learn either?). FORTH programs do not enter like BASIC.

PLURI-FORTH uses ASCII characters rather than the SINCLAIR code. ASCII (American Standard Code for Information Interchange) is an industry standard and is compatible with almost every other computer and interface device.

There are two screens with PLURI-FORTH. The first appears when the computer is first fired up. If the user presses the SHIFT/EDIT keys, the second screen appears which is made up of two sections separated by a bar, which is called a PAD. The portion above the PAD contains 16 potential lines and is called:

THE SCREEN EDITOR

This part of the screen is used for entering programs

THE EXECUTION SCREEN

This part of the screen is used to compile the program into machine language and to execute it. There is a EOFF command that allows the upper portion to be scrolled away so that the entire screen can be used to observe the program when it is running.

The program can be compiled line by line or in its entirety.

FORTH is, however, much easier to learn than machine language. To give you an idea on what kind of people can learn FORTH, there is a group of people who are trying to introduce FORTH into elementary school level teaching situations as the best language to be taught in schools. Why?

Forth combines the power of many other languages that are much harder to learn or more specialized.

Maybe you have been thinking of selling or shelving your TS/ZX computer and purchasing a more sophisticated machine. Here’s a suggestion. The PLURI-FORTH language comes on a chip/circuit board. I had a computer with a keyboard enclosure that I opened up and removed the existing BASIC ROM chip from. The directions state that the resistors next to the ROM socket had to be bent down in order to plug in the circuit board. This is true if you use the board in the ZX-81 or TS-1000 factory case. If you have a larger keyboard enclosure that houses your circuit board, you can purchase from Radio Shack a socket extender (bring the old BASIC ROM chip to R.S. to get the right one). Plug the extender into the CPU board, solder it, and plug the PLURI-FORTH board into the extender socket.

If you want, you can purchase another extender and solder it into the PLURI-FORTH board and plug the BASIC chip into that. A single wire on the PLURI-FORTH board can now be cut and a 2-wire toggle switch attached. This enables the user to switch between the BASIC and PLURI-FORTH languages. Of course, any data in memory will be lost if this is done. However, the user, in effect has the capability of two computers.

I doubt if anyone can purchase a computer with FORTH resident in ROM for the price of this conversion.

Now, let us take a simple program in BASIC and see how it would be entered in FORTH.

BASIC PROGRAM – NUMBER DOUBLER

10 CLS
20 LET I = 1
30 IF I>32767 THEN STOP
40 PRINT I;" ";
50 LET I = 2*I
60 GOTO 30

If this program was RUN on the TS/ZX computer, the screen would display the following:

1 2 4 8 16 32  64  128  256  512
1024 2048 4096 8192 16384

To write the same program in FORTH, the user would enter the following into the editor (upper) portion of the screen:

:  DOUBLER  CLS 32767 1 DO I . I
+LOOP ;

The user would then press the SHIFT/EDIT key to enter into the execute (lower) portion of the screen and enter “CPL”. FORTH would now “compile” the program into machine language.

The user would now enter “DOUBLER” and the program would RUN with the same display as the BASIC version but much faster. Let us examine how the FORTH version of the program works.

You will notice that there is only one line and no line numbers. The “:” at the beginning and the “;” at the end of the line designate the contents and the program name. The name “DOUBLER” appears righ after the colon and is recognized as the program’s name. The “CLS” operates just like BASIC and clears the screen. The “32767” functions as the same limit-operator as in the BASIC version. The “1” is the value of the numeric variable “I” and the “.”, the “DO” and the “+LOOP” act as either a FOR/NEXT loop or the cycling loop as found in lines 30 and 60.

But here is something you can’t do in BASIC. If the user was to enter the line in the editor mode:

: DUBL2 DOUBLER ." ALL DONE " ;

The following would be displayed on the screen:

1 2 4 8 16 32  64  128  256  512
1024  2048  4096  8192 16384 ALL
DONE

“DUBL2” contains the “DOUBLER” program and the message “ALL DONE”.

Now, while in the execution mode, we find we can execute two different programs, “DOUBLER” and “DUBL2”.

Herein lies the power of FORTH. From this simple example, we can observe a number of things:

…. more than one program or routine can be in the computer at the same time.

…. programs, routines or commands can be merged together.

…. a small amount of keystrokes can accomplish in FORTH a desired effect as compared to BASIC.

…. the memory used by the program in FORTH is much smaller than that used by a similar program in BASIC.

…. the speed of execution in FORTH is much faster than BASIC because it is in machine language when executed.

…. FORTH gives the advantages of machine code regarding speed and extra command capabilities while giving the advantages of a structured language (such as BASIC) regarding keyboard program entry.

The PLURI-FORTH chip/circuit board is manufactured by TREE SYSTEMS and marketed by:

SOFT MAGIC CORPORATION | 1210 W. HIGH ST. | BRYAN, OH, 43506 | (419) 636-4531

FORTH SYSTEM – $49.95 | (including documentation) | (introductory price)

Documentation – $12.95 | (creditable to system order)

STARTING FORTH by Leo Brodie | $14.95 (special price)

All mail orders, add $2.00 p & h

If we wrote our cassette programs in FORTH, all of the programs could be put in the same program if memory would allow it. The user need only load the one program and could go back and forth between them. How’s that for power?

Next month, we will examine more of the FORTH commands and show some more programs and compare them with their BASIC counterparts.