intel MCS BASIC-52 — Intel MCS BASIC-52 Versions 1 & 1.1 Operating and Reference Manual PDF (EN)

int e l 1.8 FORMAT OF AN MCS BASIC-52 PROGRAM This section answers the question "How does MCS BASIC-52 store a program?" LINE FORMAT Each line of MCS BASIC-52 text consists of tokens and ASCII characters, plus 4 bytes of overhead. Three of these four bytes are stored at the beginning of every line. The first byte contains the length of a line in binary and the second two bytes are the line number in binary. The fourth byte is stored at the end of the line and this byte is always a 0DH or a carriage return in ASCII. An example of a typical line is shown below, assume that this is the first line of a program in RAM. 10 FOR I = I TO 10: PRINT 1:

NEXT I LOCATION BYTE DESCRIPTION 512 11 H THE LENGTH OF THE LINE IN BINARY ( 17D BYTES) 513 00 H HIGH BYTE OF THE LINE NUMBER 514 0A H LOW BYTE OF THE LINE NUMBER 515 0A0 H THE TOKEN FOR "FOR" 516 49 H THE ASCII CHARACTER "I" 517 0EA H THE TOKEN FOR "=" 518 31 H THE ASCII FOR "1" 519 0A6 H THE TOKEN FOR "TO" 520 31 H THE ASCII FOR "1" 521 30 H THE ASCII FOR "0" 522 3A H THE ASCII FOR ":" 523 89 H THE TOKEN FOR "PRINT" 524 49 H THE ASCII FOR "I" 525 3A H THE ASCII FOR ":" 526 97 H THE TOKEN FOR "NEXT" 527 49 H THE ASCII FOR "I" 528 0D H END OF LINE (CARRIAGE RETURN) TO FIND THE LOCATION OF THE NEXT LINE, THE LENGTH OF THE LINE IS ADDED TO THE LOCATION WHERE THE LENGTH OF THE LINE IS STORED.

IN THIS EXAMPLE, 512 + 17D = 529, WHICH IS WHERE THE NEXT LINE IS STORED. The END of a program is designated by the value 01H. So, in the previous example if line 10 was the only line in the program, location 529 would contain the value 01H. A program simply consists of a number of lines packed together in one continuous block with the last line ending in a 0DH, 01H sequence. - 188 -