| Home CBM ASCII-X BASIC Disk Commands Enter RUN mode Program Format Secret Variables Variable Format Expressions Keywords Syntax Tokens C128 D64plus Disk Escape Codes Hardware PCxface PETSCII Pet2asc Futurama IBM PC-AT Contact Games Glossary Hall of fame Hall of shame Miscellaneous Privacy policy Programming Twisty puzzles |
This page discusses the "object code" of CBM BASIC.
Whenever you enter a line that starts with an unsigned number (no leading + or -),
BASIC will store the line (assuming the number was between 0 and 63999) as part of a program
in a compressed format known as "object code".
Below are some hexadecimal memory dumps of "object code".
This is the exact same sequence of bytes stored in a program file (on cassette or disk, for example)
except that a program file also contains two leading bytes; those bytes identify the start address in RAM
from which the program was saved. The first two bytes in a program file are ignored
(when loading a BASIC program) in all versions of BASIC, except v1.0.
The program format ("object code") is quite simple. Each program line stored in RAM consists of 4 parts:
A strange thing about CBM BASIC is that the byte preceding the first line MUST be a zero byte...
otherwise errors will occur. The sample memory dumps show this zero byte.
Example Source Code:
Example Object Code (C128):
The null terminators (zero bytes) are shown with a red background
(this includes the strange leading null, which is NOT saved to a file).
The line-links are shown with a yellow background.
The 16-bit line numbers are shown with a green background.
Tokens are shown with a blue background.
Everything else is punctuation/parameters (in ASCII-X).
Also note that the end-of-program is identified by a double-zero (line-link).
Because this is normally proceeded by a previous null terminator, the end of a BASIC program (in object format)
may be identified by a "triple null" (three zero bytes in a row).
NOTE that some people (who are desperate to save every possible byte)
may fudge the standard, and set the next-to-last-line-link (last non-zero line link)
to point to the terminating zero of the final line... in these rare cases, the program ends with only two null bytes.
It's an ugly hack, so if you don't understand that sentence, below is the same program using that "save 1 byte hack":
Ugly Hack to Save 1 Byte (C128):
If you (like me), examine the 2 hex/byte dumps shown above, it may be VERY difficult
to see the difference!!
To be crystal clear, here is the difference:
The "hacked" link points into the "end of line" ($1c25) instead of the "standard" next-line ($1c26)
-- save 1 whole byte!
I am not recommending this hack; I just want to make you aware it exists
(rarely seen in my experience).
© H2Obsession, 2014, 2015, 2019 |