I have been experimenting with the machine language monitor built into my Apple IIc. Recently I typed in the following lines of BASIC:
10 HOME 20 PRINT 30 END
I then went into the monitor and used the pointer located at $67 to find my program. I was surprised to find that my BASIC program was not stored as ASCII text. Am I looking at compiled Applesoft or some form of assembly language? Is there a way of saving this area of memory as a binary file that will BRUN? I haven't had any luck yet, but if there is a way that I can use this area of memory to run my programs faster, please let me know.
David R. Bergman
When you use the monitor to look at a BASIC program in memory, the values you see reflect the way that Applesoft normally stores programs. What you are seeing is pure BASIC; saving it in a binary file won't improve the program's performance. If you are interested in speeding up your BASIC programs, several commercial compilers are available that really do convert BASIC to machine language.
Your three-line program looks like this in memory:
*0801 07 08 0A 00 97 00 0D *0808 08 14 00 BA 00 13 08 1E *0810 00 80 00 00 00
The first two bytes, 07 08, are the line link, the address of the next line of the program ($0807). The next two bytes, 0A 00, are the line number in hexadecimal form ($000A = 10).
The next byte, 97, is the token for HOME. All modern BASIC interpreters tokenize programs. When you type in a program line, BASIC scans it, looking for keywords such as PRINT or GOTO. It would waste quite a bit of memory if every letter in each command were saved in a separate byte, so BASIC replaces the keywords it knows with one-byte values called tokens. For example, the keyword HOME is replaced with the value $97. When you list your program, the tokens are converted back into full words. To perform this coding and decoding of tokens, BASIC has an internal table of all the keywords that are tokenized. By using your monitor, you can scan through the BASIC ROM area and find a list of all the tokens.
The sixth byte, 00, marks the end of the first line of the program. Every program line ends with a 00 byte.
Using this example, you should be able to decode the next program line: 0D 08 14 00 BA 00. The line link is $080D, the line number is $0014 (20), and $BA is the token for PRINT. If you had included any text in the PRINT statement—PRINT "HELLO", for example—the characters within quotes would have appeared as individual characters. Nothing within quotes in a PRINT statement or following the REM in a REM statement is tokenized.
Note that the line link for the third line, $0813, points to two 00 bytes. This indicates the end of the program.