You are on the archived version of the www.TheForthSource.com website. These materials are presented for informational purposes only. We express our gratitude to N.M.P.L. (providing services for obtaining urgent loans near Sacramento, CA) for paying for hosting.
FORTH GUIDE
  


CHAPTER III


INSIDE MVP-FORTH


You have been given a quick tour of some of the things which you can do with MVP-FORTH. It is time to take a break and review some of those things.

You were introduced to about 15 of the functions which you have available in MVP- FORTH. This is already about 10% of those which you will have to master. Without any explanation you were plunged into 'colon' definitions of new functions. You were shown how a structure can be used to repeat functions.

Occasionally, the terms dictionary and word were used. No explanation was given. Hopefully you tried the examples and learned something about how to use the language. Now you will learn a little more about how it is put together.

Each defined function is given a name. The name can be any combination of characters except space and carriage return. Any group of symbols can be used as a name. Such names are hardly words as we think of them in English.

Perhaps you have heard of the Chinese use of symbols. Their written language is composed of characters known as ideograms. They have no immediate relation to their pronunciation. Each ideogram encompasses a concept of some sort. The concepts are assembled in lists which provide meaning through associations.

In a way the names for the FORTH functions are similar to the Chinese ideograms. Only in those cases in which the names look like English words could one call them words. In the other cases the names might better be called ideograms.

But still, the names of FORTH functions are often called words. In ordinary writing about FORTH they are referred to as words as in this book. But do try to understand that the use of English-like words does not imply English-like syntax. This is simply not the case. Nor is there syntax as it is used in many other programming languages.

The ideograms, or words, are collected in a linked list within the computer's memory. The list is very much like a common dictionary. Each entry in a common dictionary includes some information about the word: its pronunciation, its part of speech, its origin, and then information about what the word means.

Each entry in the FORTH dictionary in your computer includes some information of a similar type: the name length, a pointer to another word, a pointer which tells the system how to interpret the meaning which follows. All of this information is encoded in a series of bytes in computer memory.

Every time you call a function by entering its name, the location of the name is found in the dictionary. The pointer which tells the system how to interpret the following meaning is used to actually execute the function. All of this may seem a little vague, but if you take the time to examine the entries in the FORTH dictionary, you can read the encoded information. You will find that the analogy is not too bad. Details are described in ALL ABOUT FORTH.

Now there is no need to master this sort of information, but you might just want to take a look. For this purpose, FORTH has a DUMP function which looks very similar to the one you probably have in the collection of programs which came with your computer. DEBUG is such a program.

You might want to take a look at your computer memory with this MVP-FORTH function. By entering first the beginning address followed by the number of bytes you wish to inspect and then the word DUMP, you will see such a display. For this to have any meaning you must know how to interpret the hexadecimal numbers used to represent the information in memory. The appearance is similar to that in your system program.

To the right of the display, you can see the character or symbol which each of the byte codes will produce. Not all bytes represent printable symbols. Those which do not are represented by a period.

Perhaps you will want to skip ahead a little, but again you might want to take a quick look. Dump the object code for FORTH.

        256 20000 DUMP

The numbers you entered were decimal. DUMP translates this to hexadecimal in the display. You can again stop the display any time by hitting any key and continue again by hitting any key again. Remember, you can escape from scrolling by first stopping it and then hitting any key twice.

As the image of memory scrolls by, you will occasionally see words which you recognize. All of the entries in the dictionary will appear if you scroll through the entire dictionary. Later you will look more closely at the form of a dictionary entry.

For now you will see that the dictionary starts at low memory and extends toward high memory. Any new function you define, such as the CRS which you did earlier, will be added on top of the dictionary. So you can say that the dictionary grows up in memory.

High memory is used for special functions in FORTH. These functions include the buffers for the screens. Other buffers are also located in high memory. These buffers are transient and do not have to be saved with the object code for your FORTH. They are reconstructed every time you start the program.

Try the word LIMIT:

        LIMIT .

The system will print a number. The function of the constant, LIMIT, is to store the highest memory location to be used when you start the program. The "." is also a FORTH word. Its function is to print the number you have entered. It is pronounced 'dot' and means print. The symbol, "." , is an ideogram. Neither its pronunciation nor its function is obvious, hence, ideogram.

You might find that LIMIT has a value around 24000. If your system has 64K of memory, you could make your FORTH highest memory location much larger. But you will have to know something about the use of the rest of the memory in your system before you change the value of LIMIT. For now, the 24K value of LIMIT will allow you to do much of what is included in this guide. Later you will learn to change the value and restart the FORTH program. Some implementations on this disk have already made the change.

Now that you have learned to use the DUMP functions, you might find it interesting to look at a buffer containing a screen. First find a screen with something on it. Maybe one of the earlier screens is available on your FORTH SCREENS disk.

        75 LIST

If it is not, or you cannot find a screen with something entered on it, go back and write something on a screen and LIST that.

Now try a DUMP on the memory buffer containing that screen.

        75 BLOCK 1024 DUMP

Using the function BLOCK instead of LIST will tell the system the beginning address of the desired buffer in memory. You must then tell the system the number of bytes you wish to inspect. The full screen of 16 lines each containing 64 characters has 1024 bytes.

You will note that many of the bytes are encoded with the hexadecimal value of 20. That is the code for a space. Most of the screen is filled with blanks. On the right side of the display you will see the text which is present on the screen. Remember, you can scroll through this listing in the same manner as before.

You will probably find the display given by LIST much more useful than that given by DUMP. But the information contained in both is exactly the same. LIST formats the data in a block as text while DUMP can display the actual contents of each byte within a block.

Earlier we learned to LOAD a screen such as:

          75 LOAD

Occasionally you will find an error with a blank space marked. How can a blank be an error? A LIST of the screen will display nothing wrong! In such a case try;

         75 BLOCK 1024 DUMP

Look for a "." in the symbol display at the right. Any non-printing character will be displayed as a period. Perhaps you inadvertently entered a control character. FORTH will try to interpret the control characters even if you do not see them displayed with LIST.

At this point you might want to inspect the bytes on a freshly formatted disk. Find a screen which is filled with the single symbol produced by the formatting byte. Now do a DUMP on that screen buffer. You will see a field with a single byte value. Perhaps it will be all E5's.

Next, WIPE the screen and then DUMP it instead of LISTing it. This time you will see a field of all 20's. Explore your system. You will become more at home with what is going on inside of that 'little black box'.

FORTH is no different from any other program in your computer. The information is stored in a series of bytes. Any program, your word processor, FORTH, or whatever, converts those bytes to a convenient format. An advantage of FORTH is that, should you be interested in how the data looks in memory you can easily see it interactively with DUMP.

FORTH also has the feature that you can change any byte in memory. For that matter, you can change any byte on your disk. The ability to perform these changes provides the power of FORTH. But with the power comes the danger. You, the programmer, are left responsible for changing or not changing the contents of byte locations in memory.

With the power of FORTH, you can, at any time, inspect any resident part of your operating system. You can in fact change any part of your operating system. You can even access anything on your system disk as well as your FORTH SCREENS disk. With this power, you can easily contaminate your system disk. More than with any other language, you must develop the habit of making backup copies of all of your work. You can never tell when an unrecognized typo will contaminate either your running program or your disk and with it perhaps some other program on the disk.

One interesting experiment is to examine the directory of a system disk. Make a copy of a system disk so that you will not lose anything important. Then try listing screens beginning with screen 1. Usually you will see garbage displayed on your monitor. This is simply because any machine language in your computer memory is not organized in text to be formatted by LIST.

Provided your system does not crash by trying to print an escape sequence to your monitor which changes its function, the garbage will not hurt anything. You might even occasionally hear a beep. Whenever the system tries to display a hexadecimal value 07, the system will beep. At least this is true on many systems.

        7 EMIT

Soon, on one of the early screens you will see scattered on the screen, the names of some of the files on your system disk. Now, instead of LISTing that screen, try dumping it.

        3 BLOCK 1024 DUMP

If you, directory is located on screen 3, you will see it displayed out on the right side of the screen. Actually, you will have displayed all of the information stored with the entry in the directory on the disk. This is what is known as the file control block, (FCB).

In this lesson you have been introduced to a relatively few new FORTH words. But perhaps you will have been given a little more of a feel for what is going on inside your system. Later we will use some of these tools to explore more of the details of MVP-FORTH.

Forth Guide

Next Previous Contents