Commodore 2001-8 User Manual page 28

Table of Contents

Advertisement

e,nd. The longer-programsteatures of list which allow you to list only
a
single line-nurtlber
lIST
2fJwiifcft'
lists just line 20, LIST 10-50 which lists lines 10 through 50 included, LIST-50 which means' list 61Pt#e
numbers fromth~·fJeginning of the program through line 50 included, and LIST 50- which Iists-aH'oUhe"
lines from line 50 to the end of the program. Some combination of the above can be use(nO find"and'
correct any piece of program which is currently stored in memory. Try each of the above commands,on,
your PET just to see what they do with our little program.
BASIC is an interpretive language related to the direct commands we are executing. BASIC executes a
command by taking the last line typed to It and analyzing the line working from left to right looking fOr' key
words and expressions which it recognizes. Every time it encounters a key word such as PRINT (or?
which Is the token for PRINT), It interprets this word into a command which means something to BASIC.
Command words are stored In memory with bit 8 on to tell BASIC that it Is a command word, or key word.
As
a program line is entered into RAM memory through the use of the carriage return, BASiC takes the
line number and searches through memory, until it finds the same number, or the number Just greater. If
it is the same line number, then the entire line in memory is deleted and a new line is inserted In memory.
In the pre·interpreted state all the key words are replaced with the single character token for the key word.
This allows the interpreter to store commands in the most memory·efflcient form. The only data stored
is the data typed in by the programmer such as literals, pointers to the variables, and the keywords.
PRINT, even though it takes five characters to type, only takes one character in memory.
BASIC is called an interpreter because the actual execution of the instructions is done by analyzing the
keyword that needs to be executed in the program line, then executing that keyword under the control of
a series of subroutines. This is a trade-off which results in very memory-efficient storage programs but
longer execution times than would be true of a machine language program. Because PET BASIC uses
tokens in memory and stores them on I/O devices whenever a program is loaded and saved, the actual
coding of data on tape or in memory is not transferable to other machines. It is generally not possible to
use BASIC instructions typed in from other machines.
When you create
a
BASIC program you are operating under two levels of editor: the screen character
editor and the BASIC line editor. The screen editor allows you to change characters within
a
line until the
carriage retumtransfers it to main memory. The BASIC line editor allows you to add new lines and modify
and delete old lines.
To delete
a
line, you type the line number immediately followed by
a
carriage return. To modify
a
line,
list it first on the screen and aiter it then type
a
carriage return to re-enter it. To replace a line, enter the
same line number with new text and type carriage return.
There are two ways to execute a BASIC program. The first of these is to type RUN. The command RUN
first clears all the program variables and initializes the program pointers. Then it executes each
instruction of the program in order, starting at the lowest number. Execution continues until there are no
more instructions, and END
is
encountered, or the stoP key
is
pressed. RUN may have as an argument the
number of the first instruction to be executed. For example, if you type RUN30, our sample program will
print THERE instead of HI THERE. RUN is executed in direct mode. A GOTO statement, also executed in
direct mode, operates the same as RUN except that none of the variables are re·initialized. The GOTO, of
course, must specify the line number of the first statement to be executed, e.g. GOTO 30.
LITERALS
In our HI THERE examples we have used PRINT commands with characters to be printed enclosed in
quotes. In the PET these are called literal strings. Data is also kept in the PET in binary floating·point
24
,

Advertisement

Table of Contents
loading

This manual is also suitable for:

Pet 2001-8

Table of Contents