Micro­power

  

Volume 1 · Number 4 · December 1981

Page 21 of 33

10 COSSINTANATNPEEKDEEK

As a final point on this topic, I thought it would be interesting to take a look at the way the BASIC stores reserved words. First enter the command NEW, and then type in the following line:

10 PRINT"MIKE":END:SCREEN 15,12

Now reset and tabulate from 10FA hex. You will find the following code:

10FA    10 11 0A 00 9E 22 4D 49
1102    4B 45 3A 80 3A 97 20 31
110A    31 35 2C 31 32 00 00 00

The first two bytes, 10 11, store the address of the start of the next line, the next two bytes, 0A 00, hold the line number, and then come the bytes which represent the data stored in the line. The first data byte, 9EH, represents the reserved word PRINT; as a line is entered the text is scanned, and if the Basic recognises a reserved word it is replaced by a hexadecimal number in which bit 7 is set. This speeds up programs, because the interpreter can more quickly recognise a reserved word and access the necessary machine code routines.

PRINT is followed by the ASCII codes for “MIKE” (22 4D 49 4B 22) and the separating colon (3A). Two more reserved words then appear, END (represented by 80H) and SCREEN (97H).

The end of the line is marked in the store by a zero, which is followed by a pointer to the start of the next line, a line number, more data, and so on. At the end of the program the zero marking the end of the line is followed by two further zeros in place of the line pointer.

You will notice that although there is no ‘space’ character (20H) after the line number bytes, the LIST command always inserts a single space to improve legibility. No matter how many spaces you put between the line number and the start of the text when you enter the program, the interpreter always removes them – and then puts one back when listing. This makes it difficult to use ‘pretty printing’ – that is, formatting of the text by use of different indentations to make the underlying structure of the program obvious at a glance. You can always indent a line by inserting a colon before the required spaces. For example:–

10 :     PRINT "This Is An Indented Line"

*     –     *     –     *     –     *     –     *     –     *     –     *

Page 21 of 33