Machine Code and M-Log

See all articles from QZX v3 n12
Author(s): Alex Burr (K5XY)
Publication: QZX
Pub Details: QZX v3 n12 (Volume 3, Issue 12)
Date: November 1985
Pages: 10-11

Some suggestions and comments from OH4NC, Holger, got me started thinking about elementary machine code problems (the only kind I know anything about). Here I will refer to the nice logging program from N9BBN which appeared in the August 1985 issue of QZX and to the article on the USR command which appeared in the November 1984 issue of QZX. (Back issues $1.00.)

ON0NC first made some comments about the basic M-Log program. He said, “I am glad that there are some MC wizards among us to make the ZX 81 work faster; I have yet to learn to master that aspect of computing.” Then he added, “Looking through the Basic M-Log program, I noticed that part would not work in Fast mode because the computer would continuously look for a processed key without displaying a picture. The solution is simple; just add three lines at 65, 188 and 315, all identical — PAUSE 4E4. Now even Fast mode works. Also note that in line 135 the second 59 should be followed by a space before the last “. The same goes for the second CW in line 470. The last number in the second row of the decimal listing (i.e. 19?) should not be there.”

These last comments do not refer to any error in the listing printed in the August issue. If you look very closely, you will find that the spaces referred to above do appear in the listing. It is just because they appear at the end of a line that they are very hard to spot. The questionable digit in the decimal listing is just an extra blotch which appeared at the edge of the printing block and is not a number. But again it takes a sharp eye to notice this.

Bo and I are aware that it is very difficult to correctly enter some of the listings which appear in QZX, particularly if the logic of the program is hard to follow. We do not know of an easy solution to this problem; so we print the best copy that we can produce in the time available. We just cannot afford the time necessary to retype all the programs we receive. At the very least, the reader can follow the ideas of the programmer through the BASIC listing.

We know it is impossible for a beginner to follow a machine language segment of a program such as the 1 REM statement in the M-Log program. Here I will explain for a beginner what is going on.

Of course, everybody knows that the computer does not directly respond to a BASIC statement like GOTO but is directed by 0’s and 1’s in its memory location. The BASIC statements just put the appropriate numbers in these locations. The programmer can speed the program up by putting those 0’s and 1’s in directly without going through the interpreter. This process is called machine language programming.

As detailed in the November 1984 QZX, the USR command lets BASIC refer to the directly entered machine code. All the odd looking REM statement in M-Log does is put the correct 0’s and 1’s in known locations for the USR function.

It would be possible to put these 0’s and 1’s in the right places by keying in the exact information shown in the REM statement. But it would be difficult to do so because it is hard to distinguish, for example, between the token (or single command key) PRINT and the four keystrokes P R I N T. This difficulty is why N9BBN provided a machine code loader in lines 1000 to 1050 at the end of his program. Each time the loader pauses, the reader is to input the next decimal number from the poke listing given at the end of the article. The computer then automatically translates the decimal numbers into the appropriate 0’s and 1’s and places them in the correct memory location. This loader program will automatically overwrite anything in the 1 REM statement and all will be well as long as you have made the REM statement long enough (at least 269 characters in this example). The 1 REM statement (rather than some other REM statement is used because one always knows just where in memory the 1 REM statement is going to begin; hence the correct USR call can be made (lines 50 and 300 in M-Log).

Every machine language programmer has his own favorite machine code loader program. Once the machine code is loaded, the loader program (in this case lines 1000 to 1050) can be erased.

The loader given with M-Log is about as simple and straight forward as they come. OH0NC sent along a more complex and flexible one which is printed after this article. His program, with line numbers 9700 to 9790 follows two paragraphs which show what was put into the loader and what it prints out. The printouts are arranged with the first column giving the initial memory location for that line and followed by the decimal contents of that location and the four following locations. The last column gives a check sum of these five locations. This check sum is just the arithmetic sum of the decimal contents of the five locations. If the machine code listing includes these check sums, the entry process can be checked for errors.

I hope this brief description of some machine code ideas will help other beginners understand strange 1 REM statements and help readers recognize machine code loaders when they see them.