0 ratings0% found this document useful (0 votes) 97 views219 pagesZilog Basic Interpreter Users Manual
Scanned in high resolution from original document and cleaned up.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here.
Available Formats
Download as PDF or read online on Scribd
ZILOG
BASIC INTERPRETER
USER'S MANUAL
78116 REVISION ASECTION IT:
SECTION III:
TABLE OF CONTENTS
SECTION I: INTRODUCTION TO BASIC. . .
1.1 SPECIAL KEYS ...-..---
1.2 PROMPT CHARACTERS . .
13 STARTING AND STOPPING A BASTC SESSION
CORRECTING TYPOGRAPHICAL ERRORS .
4
BASIC COMMANDS AND STATEMENTS
LISTING A PROGRAM
1.6 ao
1.7 USER'S WORK AREA.
1.8 .
1.9 RUNNING A PROGRAM .
ried
aed
Q DELETING A PROGRAM
1 DOCUMENTING A PROGRAM
EXPRESSIONS .. 2... -
2.1 CONSTANTS. 2.2... ---
2.1.1
Pir}
NUMERIC CONSTANTS . . .
LITERAL STRINGS . . . .
2.2 VARIABLES... 2...
2.3 PUNCTIONS...-....
2.4 OPERATORS... 2...
2:5 EVALUATING EXPRESSIONS |
STATEMENTS .. 2...
ASSIGNMENT STATEMENT: LET . .
END/STOP STATEMENTS . . . .
LOOPING STATEMENTS: FOR.
GOTO/ON,
GOsUB.
CONDITIONAL STATEMENT:
INPUT STATEMENT . 2...
-RETURN STATEMENTS . .
NEXT
«GOTO STATEMENTS . .°.
IF... THEN
1.5.1 COMMANDS ... 1... eee
1.5.2 STATEMENTS . 2... eee eee
1.5.3 ERROR MESSAGES .. .
1.5.4 CHANGING OR DELETING A STATEMENT
BASIC PROGRAMS . a3.8 PRINT STATEMENT
3.8.1
wwe
bbe
RES
SYSTEM STATEMENT
SECTION IV: COMMANDS ~
TAB FUNCTION
READ/DATA/RESTORE STATEMENTS
COMMENTS: REM STATEMENT AND
RANDOMIZE STATEMENT . . .
4.1 PROGRAM EXECUTION COMMANDS
4.1.1 RIN...
4.1.2 xEQ.. -
4.1.3
4.1.4 QUIT ..
4.2. EDITING COMMANDS
LIST .
WEW. .
DELETE .
RENUMBER,
SIZE. .
CLEAR . .
NNNNNN
aie
4.3 DISK RELATED COMMANDS . -
SAVE
ASAVE
RSAVE
Ger.
XEQ
APPEND .
OBTAINING
CS
Duane wie
a be ba Uo ba ba ba
SECTION V:
A
LIST oF
DELETING FILES .
RUN
s
RESUMING PROGRAM EXECUTION:
CONTINUE, STEP,
KEYBOARD EXECUTABLE STATEMENTS
Gfioo0ddo
3-23
3-24
3-26
3-29
3-30
3-31SECTION
6.2
6.2
anaanana
DUO
SECTION
Tel
7.2
Tes)
SECTION.
8.1
8.2
8.3
8.4
VI: NUMERIC TYPES .....-.
TYPE SPECIFICATION ..--. -
NUMERIC CONSTANT FORMS . .. .
6.2.1 INTEGER FORM . .
6.2.2 ‘PLOATING POINT FORM | ¢
NUMERIC EXPRESSIONS .. . . .
CONDITIONAL NUMERIC EXPRESSIONS
NUMERIC ASSIGNMENT . 2...
INPUTTING NUMERIC DATA 5
OUTPUTTING NUMERIC DATA
NUMERIC FUNCTIONS . . .
ABS . .
AIN. .
cos...
EXP .
INT.
LOG .
RND
SGN
SIN
SOR
TAN
DAAAAAAAADD
Brom uaueune
BS
Vite ARRAYS) eee
DIM STATEMENTS .... 2. ee
STORING DATA IN ARRAYS .. ~~
PRINTING DATA FROM ARRAYS . .
VIII: STRINGS . 2... - ee
LITERAL STRINGS .....-
STRING VARIABLES . .
DIM STATEMENT WITH STRINGS
STRING EXPRESSIONS . ~~
t
&
on
ap aa m
Te oa
we td
FSeata ow
an8.5 STRING-RELATED FUNCTIONS .......+.+..+ 8-11
8.5.1 CHR$ FUNCTION... -.. +--+ e+e + 8-11
ie eee) Goo gon obooGod kl
pee eine) Goo g0cGG5 0000 tel
8.5.4 POS FUNCTION ... 2... +--+ eee + + 8-12
8.5.5 VAL FUNCTION ..----- +--+ + - 8-12
8.5.6 STR$ FUNCTION... .-- +--+ ++ + + 8-12
Geo sige CLEP TS PEUNCTIONS sce pe yee edo)
8.5.8 RIGHTS FUNCTION. -...... +--+. 8-13
8.5.9 SEGS FUNCTION... 2... +e eee 8-13
8.5.10 KEYS$ FUNCTION ...----.- ++. 8-14
8.6 COMPARING STRINGS -..-. +--+. --+-++-4 8-14
BS] STRINGEASSIGNMENT Cyt) fest oe tees 0-6)
8.8 STRING INPUT STATEMENT .-.-~.- +--+ +--+ 8-19
8.9 STRING LINPUT STATEMENT... .-.- +--+. 8-20
8.10 STRING PRINT STATEMENT ....... +--+ + 8-21
8.11 STRING READ/DATA/RESTORE STATEMENT . . . . . 8-22
SECTION IX: USER-DEFINED FUNCTIONS ..-----.- + 9-1
9.1 ONE-LINE FUNCTIONS ..-. eee ee ee ee 92
9.2 MULTI-LINE FUNCTIONS . . Sbogoga 9-4
9.3 - CALLING A USER-DEFINED FUNCTION | 122222 9-7
BECTION Sc) OCLESE ee 10-1
10.1 PILE TYPES AND ATTRIBUTES... ~~... +... 10-2
LO let ASCTI PTLES eee ere) eee 102)
10.1.2 BINARY FILES ...--- eee ee ee 10-2
10.1.3 FILE NAMES ..-.. eee ee eee 10-2
10.1.4 FILE ATTRIBUTES AND STRUCTURE... . . 10-2
10.2 OPENING PILES: FILE STATEMENT... ..... 10-4
10.3 CLOSING FILES: CLOSE STATEMENT ......-.- 10-8
10.4 DELETING FILES: ERASE STATEMENT... .... 10-9
L0e5| TRUNCATE, STATEMENTE CS) © oct cs); 2 es - 10-1)
10.6 SPACE STATEMENT... -.- +--+ + e+ ee + - 10-12
Me? petiecrnt oe 6 go mo 6 Coon doo Go ome
10.7.1 SEQUENTIAL FILE READ, INPUT
AND LINPUT .. . soe ee es 10-14
10.7.2 SEQUENTIAL PILE PRINT AND WRITE | |] ] 10-16
10.7.3 FILE RESTORE STATEMENT ... ~~... . 10-17
10.714 RANDOM PILE READ, INPUT, AND LINPUT | | 10-18
10.7.5 RANDOM PILE PRINT AND WRITE... . . . 10-1910.8 PILE RELATED FUNCTIONS .........- . 10-21
10.8.1 EOF FUNCTION .... 2.2.2... 10-21
SECTION XI: FORMATTED OUTPUT. -....-. +++. Ll-L
11.1 PRINT USING STATEMENT... . +. +--+ + 11-2
ted | PORMAT GTRIWGd | freee eee lee
SECTION XII: TRAPPING ee iad
12,1 TRAP STATEMENT 2 2. 1 eee ee ee ee ee 122
gebot REYSs ee ee eed
U2se2 ESTs 2 2 5 2 eS ee. - 12-4
22-3 BBC. se ee tt tt te ww wt ~ (LSM
ged CRB etree oe) te 12-5
T2215 SEOR 2) elete ce eis louse ec stems L2s5
12.1.6 ENVIRONMENTS AND TRAPS ... 2... + 12-5
12.2 TRAP RELATED FUNCTIONS .......+.-. 12-7
Dee ee leer
12.2.2 BSC... eee ee ee ee ee ee ee 127
12.2.3 KEYSS . . eee ee ee ee ee ee ee 1D
122204 ERR; - © 2 ee ee ee te ee - 6LORT
SECTION XIII: SEGMENTATION... 1... eee ee ee 132
dee (CHATN STATEMEN De eee 1 ee 132
13.2 COM STATEMENT . 2. 1. 1 ee ee ee ee ee 19
SECTION XIV: COMMUNICATION WITH NON-BASIC PROGRAMS . . 14-1
Vek OVA wii Geo ooooogaopooo eitAPPENDIX
APPENDIX
APPENDIX
APPENDIX
APPENDIX
APPENDIX
APPENDIX
APPENDIX
APPENDIX
APPENDIX
ASCII CHARACTER SET
SUMMARY OF ZILOG BASIC STATEMENTS
SUMMARY OF ZILOG BASIC COMMANDS
BUILT-IN FUNCTIONS
ERROR MESSAGES
BASIC, PLZ AND ASSEMBLY LANGUAGE LINKAGE
EXAMPLE: ASSEMBLY LANGUAGE CALL-SYSTEM STATEMENT
PROCESSORS
EXAMPLE: A USER PROCEDURE CALL
A PROCEDURE FOR PRINTING TO A PRINTER
EXTERNAL INTERRUPT LINKAGESECTION I
INTRODUCTION TO BASIC
Zilog BASIC is a programming language designed for use
at a keyboard terminal. It consists of statements for
writing programs and commands for controlling program
operation.
There are two versions of Zilog BASIC. The difference
between them is the math package. BINBASIC includes a
binary math package with seven significant bits of
precision. BASIC includes a BCD math package with 13
significant digits. Section 6.2.2 describes the two
floating point representations. The examples shown in
this user's manual will primarily reflect the BASIC BCD
math package. The use of the word BASIC in this manual
will refer to both BASIC and BINBASIC.
This section describes how to begin and end a BASIC
session, how to enter commands and statements and make
corrections. A few simple programs are used for
illustration. The actual programming language is
described in following sections.
This manual assumes that the user knows how to connect
his terminal, and is familiar with his terminal’ keyboard.
Special keys with particular functions in Zilog BASIC are
described in this section.1.1 SPECIAL KEYS
RETURN
LINEFEED
CTRL
CTRL-#
RUBOUT (DEL)
ESCAPE (ESC)
”
Must be pressed after every command and
statement. It terminates the line and
causes the cursor to return to the first
print position.
Causes insertion of a space in the text
and moves. the cursor to the beginning
of the next line.
When pressed simultaneously with another.
key, converts the key to a control
character that is usually non-printing.
Control-# is accomplished by pressing the
Control and # keys simultaneously.
Deletes the previous character in a line.
The cursor, is moved back one position for
each character deleted. (See RIO manual).
Cancels the line currently being typed.
Cancels the current line if typed during
command or statement input; stops the
currently executing program if typed
during run mode. (May not work on a ZDS
system-because there is no hardware __
Universal Asynchronous Receiver Transmitter
(UART)) .
Causes output to pause and continue if
typed while terminal is outputting
information. (May not work on a ZDS
system because there is no hardware UART).
1-21,2 PROMPT CHARACTERS
Zilog BASIC uses a set of prompting characters to
signal to the user that certain input is expected
or that certain actions are completed.
> The prompt character for the Zilog BASIC _
Interpreter; a BASIC command or statement is
expected.
& The prompt character for the RIO Operating
System; RIO commands such as CAT or BASIC are
expected.
0
User input is expected during execution of an
INPUT statement.
1-31.3 STARTING AND STOPPING A BASIC SESSION
STARTING A SESSION
Once the terminal is connected and ready, the user
presses the carriage return.
RIO responds with a
Percent sign (%) at the beginning of the line. The
user may now begin. (Note:
T£ you are using a printer,
it must be activated before entering BASIC. See
Appendix I.)
ENTERING BASIC
The RIO Operating
System signals it is
ready for the next
command by printing:
To enter BASIC, type:
BASIC signals that
it has control by
printing:
followed by the prompt
character:
To enter BINBASIC, type:
BINBASIC signals that it
has control by printing:
followed by the prompt
character:
SBASIC
ZILOG BASIC
version date
BCD ARITHMETIC
SBINBASIC
ZILOG BASIC
version date
BINARY ARITHMETIC
>
BASIC commands and statements can now be entered.
Each command or statement is prompted by the
greater-than sign at the start of a new line.
14ENDING A BASIC SESSION
When the user is through, he or she returns control
to RIO with the QUIT command.
To leave BASIC, type: >QuIT
RIO signals that it
has resumed control by
printing: Ag
1-51.4 CORRECTING TYPOGRAPEICAL ERRORS
Corrections can be made while the line is being
entered if the error is noticed before RETURN is
pressed. The control character CTRL-# can be
used to correct a few characters just typed, or
the character RUBOUT (DEL) can be used to cancel
the line and start fresh.
Suppose the user misspells
the command, RUN >ROM
CTRL-# will delete the last >RU (Note: CTRL-E was
character pressed once)
The user retypes the
character correctly and
finishes the line. when
RETURN is pressed, the
line is entered correctly. >RON
If several characters have been typed after the
error, CTRL-H must be typed for each character to
be deleted.
>10 PXINT
>10 B (Note: CTRL-H was pressed 4 times)
>10 PRINT
In this case four characters were deleted.
Another method is to use RUBOUT (DEL) to cancel
the line, RUBOUT (DEL) must be typed before
return is pressed.
To cancel the line, type >10 PXINT
RUBOUT (DEL). The user > (Note: RUBOUT (DEL)
retypes the line was pressed)
>10 PRINT1.5 BASIC COMMANDS AND STATEMENTS
1.5.1 Commands
Zilog BASIC commands instruct the Zilog BASIC
Interpreter to perform certain control functions.
Commands differ from the statements used to write
a program in the Zilog BASIC language. A command
instructs the interpreter to perform some action
immediately, while a statement is an instruction
that normally performs an action only when a program
is run. Similar to commands, some statements can be
executed immediately.
Any Zilog BASIC command can be entered following
the BASIC prompt character ">". Each command is a
single word. If misspelled, the computer will give
an error message. Some commands have parameters to
further define command operation.
For instance, QUIT is a command that signals
completion of a BASIC programming session and return
to the operating system. It has no parameters.
Another command, LIST, prints the program currently
being entered. It may have parameters to specify
that only part of the program is to be listed.
-5.2 Statements
Statements are used to write a Zilog BASIC program
that will subsequently be executed. Hach statement
performs a particular function. Every statement.
entered becomes part of the current program and is
kept until explicitly deleted or the user exits from
BASIC with QUIT.
A statement in a BASIC program is always preceded by
a statement number. This number is an integer between
1 and 9999. The statement number indicates the order
in which the statements will be executed. statements
are ordered by BASIC from the lowest to the highest
statement number, thus it is not necessary for the user
to enter statements in execution order.Following each statement, RETURN must be pressed to
inform the interpreter that the statement is complete.
The interpreter generates a LINEFEED and. prints the
prompt character ">" on the next line to signal that
the statement is accepted. If the entered statement
is in error, the computer prints an error message.
Zilog BASIC statements have a free format. This means
that blanks are ignored.
For instance, all these >20 LET 87=25
statements are equivalent. >20LETB7=25
>20LETB7=+25
>20 LET B7 = 25
1.5.3 Error Messages
If an error is made in a line and the line is entered
with RETURN, the interpreter types a message. The
message consists of the word ERR followed by a number
indicating the nature of the error. See Appendix E
for a list of the error and warning numbers and their
meaning.
1.5.4 Changing or Deleting 2 Statement
If an error is made before RETURN is pressed, the
error can be corrected. with CTRL-H or the line may
be cancelled with RUBOUT (DEL) (See section 1.4).
After RETURN is pressed, the error can be corrected
by deleting or changing the statement.
To change a statement, simply type the statement
number followed by the correct statement.
To change this statement: >20 LET B7=25
retype it as: >20 LET B7=37
A change such as this can be made any time before
the program is run.
To delete a statement, type the statement number
followed by return.
Statement 20 is deleted: >20
The DELETE command, described in section 4.2.3, is
useful to delete a group of statements.
1-81.6 BASIC PROGRAMS
Any statement or group of statements that solves a problem
constitutes a program. The process whereby the computer
uses the program to solve the problem is called executing
or running the program.
A program can consist of only one statement.
This is an example of
a program with only
one statement.
100 is the statement number.
>100 PRINT "5 * 10 = ";5*10
PRINT is the key word or
instruction that tells the interpreter the kind of
action to perform.
expression "5 + 10
that follows.
evaluated by the interpreter.
run, the result is printed.
In this case, it prints the string
*" and the result of the expression
5*10 is an arithmetic expression that is
When the program is
The statement 100 PRINT "S * 10 = ";5*10 is a complete
program since it can run with no other statements and
produce a result.
one statement.
These four statements >1o
are a program: >20
>30
>40
This program, which calculates
is shown in the order of its execution.
Usually a program contains more than
INPUT A,B
LET C=A+B
PRINT
PRINT A;" +";
the sum of two numbers,
It could be
entered in any order if the statement numbers assigned
to each statement were not changed.
This program runs >20
exactly like the >1o
program above. >30
>40
It is generally a good idea to
increments of 10. This allows
LET C=A+B
INPUT A,B
PRINT
PRINT A;" +";B7" ="7C
number statements in
room to intersperse
additional statements as needed.
1-91.7 USER'S WORK AREA
When statements are typed at the terminal, they
become part of the user's work area (the area in memory
in which the user writes and runs programs). All state-
ments in the user's work area constitute the current
program.
Any statement in the user's work area can be edited
or corrected; the resulting statement will then
replace the previous version in the user's work area.
When the user exits from BASIC with the QUIT command,
the work area is cleared.
The program in the work area can be saved on the user's
disk. See section 4.3 for complete details.
1-101.8 LISTING A PROGRAM
At any time while a program is being entered, the LIST
cémmand can be used to produce a listing of the
statements that have been accepted by the computer.
LIST causes the computer to print a listing of the
current program at the terminal.
After deleting or changing a line, LIST can be used
to check that the deletion or correction has been
made.
>10 INPUT A,B
>20 LET C=A+G
A correction is made >20 LET C=A+B
while entering a >30 PRINT
program: >40 PRINT A;" +"7B;"
>LIST
10 INPUT A,B
To check the 20 LET C=A+B
correction, list 30 PRINT
the program: 40 PRINT A;" +";B;"
>
Note that the greater-than sign prompt character is
not printed in the listing, but is printed when the
list is complete to signal that BASIC is ready for
the next command or statement.
Should the statements have been entered out of order,
the LIST command will cause them to be printed in
ascending order by statement number. ,
>40 PRINT Az" +";B;" =";7C
For instance, the >20 LET C=
program is entered >30 PRINT
in this order: >10 INPUT A,B
>LIST
The list is in correct 10 INPUT A,B
numeric statement order 20 LET C=A+B
for execution: 30 PRINT
40 PRINT A;" +!
>
1-111.9 RUNNING A PROGRAM
After the program is entered and, if desired, checked
with LIST, it can be executed with the RUN command.
RUN will be illustrated with two sample programs.
The first program has
one line >100 PRINT "5 * 10 =";5*10
When run, the result of = >RUN
the expression 5*10 is 5 * 10 50
printed:
READY
>
Because the program contains a PRINT statement, the
result is printed when the program is run.
The second sample
Program adds two >L0 INPUT A,B
numbers. The numbers 520 LET C=a+3
must be input by the >30 PRINT
use >40 PRINT a;* +"
The two letters following the word INPUT, and separated
by a comma,. name variables that will contain a value
input by the user from the terminal. When the program
is run, the interpreter signals that input is expected
by printing a question mark. The user enters the
values following the question mark. They are entered
with a comma between each successive value.
The statement LET C=A+B assigns the value of the
expression to the right of the equal sign to the
variable C on the left of the equal sign. The
expression adds the values of variables A and B
together. The result is the value of C.
When the program is run,
the user enters input >RUN
values and the computer ?1078,5.3
prints the result 1078 + 5.3 = 1083.3
>
1-121.10 DELETING A PROGRAM
If a program that has been entered and run is no
longer needed, it can be deleted with the NEW command.
Typing NEW deletes whatever program has been entered
by the user during the current session.
The first program éntered was 100 PRINT "5 * 10 ="75410.
After it has been run, it should be deleted before
entering the next program. Otherwise both programs
will run when RUN is typed. They will run in the
order of their statement numbers. For instance, if
both programs are currently in the user's work area,
the program with numbers 10 through 40 executes before
line 100.
>100 PRINT "5 * 10 =";5*10
>10 INPUT A,B
>20 LET C=A+B
>30 PRINT
Both programs will run >40 PRINT A;" +"
when RUN is typed >RUN
71078,5.3
1078 + 5.3 = 1083.3
5 * 10 = 50
Bet anyC
To avoid confusing results, a program that has been
entered and run can be deleted with NEW:
>100 PRINT "5 * 10 =";5*10
After entering >RUN
and running: >5_* 10 = 50
the program is deleted: >NEW
The user's work area is now cleared and another
program can be entered.
>10 INPUT A,B
>20 LET C=A+B
The second program >30 PRINT A;"
is entered: >RUN
2343 ,275
343 + 275 = 618
Unless this program is to be run again, it can now be
deleted and a third program entered.
1-131.11 DOCUMENTING A PROGRAM
Remarks that explain or comment can be inserted in a
program with the REM statement. Any remarks typed
after REM will be printed in the program listing
but will not affect program execution. As many REM
statements can be entered as are needed.
The sample program > 5 REM...THIS PROGRAM ADDS
to add 2 numbers can > 7 REM 2 NUMBERS
be documented with >15 REM...2 VALUES MUST BE INPUT
several remarks: >35 REM C CONTAINS THE SUM
The statement numbers determine the position of the
remarks within the existing program. A list will
show them in order:
>LIST
5 «THIS PROGRAM ADDS
7 «2 NUMBERS
10 INPUT A,B
List of sample 15 REM...2 VALUES MUST BE INPUT
program including 20 LET C=A+B
remarks: 30 PRINT
35 REM...C CONTAINS THE SUM
40 PRINT A;" +"7B;" =";C
When run, the program will execute exactly as it did
before the remarks were entered.
Comments may also appear on the same line as a
statement. This is done by preceding the comment
with the character "\" (backslash). Characters after
the backslash are not processed as part of the
statement but are stored along with the program
statement.
Comments that follow a statement in this manner cannot
be used on the same line as a DATA statement (Section 3.9).
Sample program with >10 INPUT A,B \INPUT 2 NUMBERS
comments following >20 LET C=A+B \FIND SUM OF A AND B
statements: >30 PRINT \CARRIAGE RETURN AND LINE FEED
>40 PRINT A;" +";B;" =";C \PRINT SUM,
1-14SECTION IT
EXPRESSIONS:
An expression combines constants, variables, or functions
with operators in an ordered sequence. When evaluated, an
expression must result in a value. For example, an. expression
that, when evaluated, is converted to an integer, is called an-
integer expression. Constants, variables, and functions
represent values; operators tell the computer the type of
operation to perform on these values. Sections VI and VII
describe numeric and string types in detail.
Some examples of expressions are:
(A*3)-(B+10) A and B are variables that must have
been previously assigned a value.
3 and 10 are constants.
Parentheses group those portions
of the expression evaluated first.
If A=6 and B=4, it is an integer
expression with the value 4.
(X* (Y=2)) +2 .%, ¥, and Z must all have been
assigned values. *, + and - are
the multiply, add and subtract
operators. The innermost
parentheses enclose the part
evaluated first.
If X=7, Y=4, and %=3, the value
of the integer expression is 17.
2-12.1 CONSTANTS
A constant is either numeric or it is a literal string.
2.1.1 NUMERIC CONSTANTS
A numeric constant is a positive or negative decimal
number including zero. When using BINBASIC (binary math
package), a numeric constant consists of seven sign.
digits. When using BASIC (BCD math package), a nume:
constant consists of 13 significant digits. It may be
written as an integer, a fixed point number, or a floating
point number. See Section 6.2.2 for a description of floating
point representation for each BASIC.
Integers are a series of digits with no decimal point.
BINBASIC Integers BASIC (BCD) Integers
1234567 1234567890123
7321465 1234567890123
0 Q
60 56789
Ploating point numbers are a number followed by the
- letter E and an optionally signed integer. In the floating
point. notation, the number preceding 2 is a magnitude that
is multiplied by some power of 10. ‘The integer after E is
the exponent; that is, it is the power of 10 by which the
magnitude is multipled.
The exponent of a floating point number is used to position
the decimal point. Without-this notation, describing a
very large or very small number would be cumbersome:
18435
4
100000000000000000000000000000000000
1B-35
+ 00000000000000000000000000000000001Examples of Floating Point Numbers:
12+23 =lx ae = 100000000000000000000000
1,023 (same as above)
-O001E26 (same as above)
T
1.02E+7 = 1,02 x 10 =10200000
1.02E-7 = ,000000102
Within the computer, all these constants are represented as
floating point real numbers whose size is between 12-128
and 1E+127, The precision is determined by the type of
BASIC math package.
BINBASIC BASIC (BCD)
floating point numbers floating point numbers
123. 4567E+35 123456 .7890128+20
1234567E-36 -1234567890123E+5
-.0128+20 123456.0789E-5
2.1.2 LITERAL STRINGS
A literal string consists of a sequence of characters
in the ASCII character set enclosed within quotes. The
quote itself and the character “<" are the only characters
excluded from the character string. Blank spaces are
significant within a string.
"ABC"
"LIWHAT A DAYII"™
"XY 2"
we (a null, empty, or zero length string)
(a string with two blanks)
2-32.2 VARIABLES
A variable is a name to which a value is assigned. This
value may be changed during program execution. A
reference to the variable acts as a reference to its
current value. Variables have either numeric or string
values.
Real variables are a single letter (from A to Z) or a
letter immediately followed by a digit (from 0 to 9).
aA AQ
PB BS
x x9
A variable of this type always contains a numeric, value
that is represented in the computer by a real floating
point number.
Variables can also hold values internally represented
as 16-bit integers. Names -of such variables are similar
to those above except that their names have a suffix of
7:
AS BSS
xB x38
Variables may also contain a string of characters. This
type of variable is identified by a variable name
similar to those above except that their names have a
suffix of "$":
AS AOS
PS PS$
The value of a string variable is always’a string of
characters, possibly null or zero length. String
variables cannot be used without being declared with a
BIM statement (see Section 8-3).
24I£ a variable names an array (see Arrays, Section VII),
it may be subscripted. When a variable is subscripted,
the variable name is followed by one or two subscript
values enclosed in parentheses. If there are two
subscripts, they are separated by a comma. A subscript
may be an integer constant, a variable, or any expression
which is rounded to an integer value:
A(1) AQ (NS,/MS)
P(1,1) P5%(Q5,N/2)
X(N+1) x9 (10,10)
A simple numeric variable and a subscripted numeric
variable may have the same name with no implied relation
between the two. The variable A is totally distinct
from variable A(1,1).
Simple numeric variables cam be used without being
declared. Subscripted numeric variables must be
declared with a DIM statement (see Section 7.1) if the
array dimensions are greater than 10 rows, or 10 rows
and 10 columns. The first subscript is always the row
number, the second the column number. The rounded
subscript expressions must result in a value between
1 and the maximum number of rows and columns.
String arrays differ from numeric arrays in that they
have only one dimension, and hence only one subscript.
Also, the name of a string array and a simple string
variable may not be the same (see String Arrays in
Section VIII). Examples of subscripted string array
names are:
AS (1) AOS(N) BS$(Z%)
2-52.3 FUNCTIONS
A function names an operation that is performed using
one or more parameter values to produce a single value
result. A numeric function is identified by a multi-
letter name (or a multi-letter name followed by a 3)
followed by one or more formal parameters enclosed in
Parentheses. If there is more than one parameter, they
are separated by commas. The number and type of the
parameters depend on the particular function. The
formal parameters in the function definition are
replaced by actual parameters when the function is used.
Since a function results in a single value, it can be
used anywhere in an expression where a constant or
variable can be used. To use a function, the function
name followed by actual parameters in parentheses
(known as a function cali) is placed in an expression.
The resulting value is used in the evaluation of the
expression.
Examples of common functions:
INT(X) where X is a numeric expression.
When called, it. returns the largest
integer less than or equal to x.
For instance, INT(8.35)
SGN(X) where X is a numeric expression.
When called, it returns 1 for X>0,
0 for X=0 and-1 for xX<0. For instance,
SGN (4*~3) =-1.
og BASIC provides many built-in functions that perform
common operations such as finding the sine, taking the
Square root, or finding the absolute value of a number.
The available numeric functions are listed in Appendix D
and described in Section 6.8. In addition, the user may
define and name functions if there is a need to repeat a
particular operation. How to write functions is described
in Section IX, User-Defined Functions.
The functions described so far are numeric functions that
result in a numeric value. Functions resulting in string
values are also available. These are identified by a
multi-letter name followed by a "§". String functions are
described with user-defined functions in Section ix.
Available built-in string functions are listed in Appendix D
and described in Section 8.6.2.4 OPERATORS
An operator performs a mathematical or logical operation
on one or two values resulting in a single value.
Generally, an operator is placed between two values, but
there are unary operators that precede a single value.
For instance, the minus sign in A - 8 is a binary
operator that results in subtraction of the values; the
minus sign in -A is a unary operator indicating that A
is to be negated.
The combination of one or two operands with an operator
forms an expression. The operands that appear in an
expression can be constants, variables, functions, or
other expressions.
Operators may be divided into two types depending on
the kind of operation performed. The main types are
arithmetic, relational, and logical (or Boolean)
operators.
The arithmetic operators are:
+ Add (or if unary, positive) A+B oor +A
- Subtract (or if unary, negative) A - B or -A
* Multiply AxB
Y Divide A/B
7 Exponentiate ae
In an expression, the arithmetic operators cause an
arithmetic operation resulting in a single numeric value.
The relational operators are:
= Equal =B
< Less than ACB
> Greater than ADB
<= Less than or equal to
>= Greater than or equal to AD=B
° Not equal AOB
2-7When relational operators are evaluated in an expression
they return the value 1 if the relation is found to be
true, or the value 0 if the relation is false. For
instance, A=B is evaluated as 1 if A and B are equal in
value; aS 0 if they are unequal.
Logical or Boolean operators are:
& Logical "and" ASB
1 Logical "or" ALB
- Logical complement mA
Like the relational operators, the evaluation of an
expression using logical operators results in the
value of 1 if the expression is true, or the value of
0 if the expression is false.
Logical operators are evaluated as follows:
AgsB = 1 (true) if A<>0 and B<>0
Q (false) if A=0 or B=0
AIB = 1 (true) if A<>0 or B<>0
0 (false) if A=0 and B=0
“A = 1 (true) if a=0
0 (false) if ac>0
A string operator is available for combining two string
expressions into one:
na Concatenation AS+BS
The values of A$ and BS are joined to form a single
string; the characters in B$ immediately follow the
last character in AS. If A$ contains "ABC" and BS
contains "DEF", then A$+B$="ABCDEF" (see Strings,
Section VIII) .
2-82.5 EVALUATING EXPRESSIONS
An expression is evaluated by replacing each variable with
its value, evaluating any function calls, and performing the
operations indicated by the operators, The order in which
operations are performed is determined by the hierarchy of
operators:
Highest
unary +, unary -,
af
binary +, binary —
Relational (=, <, >, <=, >=, <>)
at
Lowest
The operator at.the highest level is performed first,
followed by any other operators in the hierarchy shown
above. If operators are at the same level, the order
is from left to right. Parentheses can be used to
override this order. Operations enclosed in parentheses
are performed before any operations outside the
Parentheses. When parentheses are nested, operations
within the innermost pair are performed first.
For instanc
z 5+6*7 is evaluated as 5+(6*7)=47
7/14*2/5 is evaluated as ((7/14)*2)/3=.2
If A=l, B=
, C=3, D=3.14, E=0
then: A+B*C is evaluated as
'B*C) =7
A*B+C is evaluated as (A*B)+C=5
A+B-C is evaluated as (A+B)-C=0
(A+B) *C is evaluated as (A+B) *C=9In a relation, the relationai operator determines whether
the relation is equal to 1 (true) or 0 (false). If A, B
and C have the values given above:
(A*B) <(A-C/3) is evaluated as 0 (false) since
A*B=2 is not less than A-C/3=0.
In a logical expression, other operators are evaluated
first for values of zero (false) or non-zero (true).
The logical operators determine whether the entire
expression is equal to 0 (false) or 1 (true). If A,
B, C, D and B have the values given above:
E&A-C/3 is evaluated as 0 (false) since both terms
in the expression are equal to zero (false).
ASBEAtB is evaluated as 1 (true) since both terms
in the expression are non-zero (true).
A=BIC=SIN(D) is evaluated as 0 (false) since both
expressions are false (0).
ALE is evaluated as 1 (true) since one term of
the expression (A) is not equal to zero.
is evaluated as 1 (true) since E=0.
For rules governing the evaluation of expressions using
strings, see. Comparing Strings in Section 8.7.
2-10SECTION III
STATEMENTS
Statements essential to writing a program in BASIC are
described here. A general description of statements is
given in Section 1.5.2. Tt should be recalled that all
statements in a program must be preceded by a statement
number and are terminated by pressing the RETURN key,
These statements are not executed until the program is
executed with a RUN command. Some statements may also be
executed immediately and are useful for debugging (see
Section V)..
3-13.1 ASSIGNMENT STATEMENT
This statement assigns a value to one or more variables.
The value may be in the form of an expression, a constant,
a string, or another variable of the same type.
Format
When the value of the expression is assigned to a single
variable, the forms are:
variable=expresson
LET variable-expression
Several assignments can be made in one statement if they
are separated by commas:
variable-expression,...,variable=expression
LET variabie-expression,...,variable=expression
Note that the word LET is an optional part of the
assignment statement.
Description
In this statement, the equal sign is an assignment
operator. It does not indicate equality, but is a
signal that the value on the right of the assignment
operator be assigned to the variable on the leit.
When a variable to be assigned a value contains
subscripts, these are evaluated first from left to
right, then the expression is evaluated and the
resulting value moved to the variable.
Examples:
10 LET 21=34.567
20 21=34.567
The variable Z1 is assigned the value 34.567. Statements
10 and 20 have the same result.
3-250 N=0
60 LET N=N+1
70 LET A(N)=N
Statements 50 through 70 set the array element A(1) to 1.
By repeating statements 60 and 70, each array element can
be set to the value of its subscript.
80 A=10.5,8=7.5
90 BS="ABC",CS$=BS
100 D$=5,B18=10
The real variable A is set to 10.5, then B is set to 7.5.
The string variable B$ is assigned the' value ABC, then C$ is
assigned the value of BS (or ABC). The integer variable Ds
is assigned the value 5, then E1$ is assigned the value 10.
Strings and string assignments are described in Section VIII.
3-33.2 END/STOP STATEMENTS
The END and STOP statements are used to terminate execution
of a program. Either may be used, neither is required.
An END is assumed following the last line entered in the
current program.
Format
=ND
STOP
The END statement consists of the word END; the STOP statement
consists of the word STOP.
Description
Both END and STOP terminate program execution. END has a
different function from STOP in that END causes all files
to be closed and the message "READY" to be printed. STOP
causes the message "STOP AT nnnn™ to be printed where
nnnn is the statement label of the STOP statement. After
a STOP, program execution can be resumed (see Section 4.1.3).
Examples
These three programs are effectively the same:
10 DIM AS[5], BS[15], C$[15]
20 LET AS="HELLO", B$="THERE"
30 CS=AS+" "+BS
40 PRINT C$
>RUN
HELLO THERE
READY
>
10 DIM AS(5], BS[15], CS[15]
20 LET AS="HELLO", BS="THERE"
30 CS=AS+" "+BS
40 PRINT CS
50 END
>RUN
HELLO THERE
READY
>
3410 DIM AS{15], BS[15], CS[15]
"HELLO", B$="THERE"
Se" "aRS
40 PRINT C$
50 STOP
>RUN
HELLO THERE
STOP AT 50
>
When sequence is direct and the last statement in the
current program is the last statement to be executed,
END or STOP are optional. The message "READY" prints
as with END, but open files will remain open. END and
STOP have a use, however, when sequence is not direct
and the last statement in the program is not the last
statement to be executed:
100 INPUT x
110 PRINT
120 GOSUB 140
130 END
140 IF X>0 THEN PRINT "xX > 0"
150 ELSE PRINT "X <60>= 0"
160 RETURN
>RUN
The subroutine at line 140 follows the END statement.
3-53.3 LOOPING STATEMENTS: FOR...NEXT
The looping statements FOR and NEXT allow repetition
of a group of statements. The FOR statement precedes
the statements to be repeated, and the NEXT statement
directly follows them. The number of times the
statements are repeated is determined by the value of a
simple numeric variable specified in the FOR statement.
Format
FOR variable=expression TO expression
FOR variable=expression TO expression STEP expression
The variable may be either a real or integer variable.
It is initially set to the value resulting from the
expression after the equal sign. When the value of the
variable passes the value of the expression following 70,
the looping stops. If STEP is specified, the variable is
incremented by the value resulting from the STEP expression
each time the group of statements is repeated. This value
can be positive or negative, but should not be zero. If
a STEP expression is not specified, the variable is
incremented by 1.
The NEXT statement terminates the loop:
NEXT variable
The variable following NEXT must be the same as the variable
following the corresponding FOR.
Description
When FOR is executed, the variable is assigned an initial
value resulting from the expression after the equal sign,
and the final value and any step value are evaluated.
Then the following steps will occur:
1. The value of the FOR variable is compared. to the final
value; if it is greater than the final value (or is
less than the final value when the STEP value is
negative), control skips to the statement following
NEXT. Otherwise, processing continues with the
statement immediately following the FOR statement.
3-62. All statements between the FOR statement and the NEXT
statement are executed.
The FOR variable is then incremented by 1, or, if
specified, by the STEP value.
4. Return to step 1.
Each time a FOR loop is begun, BASIC checks to see if
there are already any active FOR loops with the same
FOR variable. If so, all active loops within and
including the duplicated entry are deactivated and
processing proceeds as described above.
The user should not execute statements in a FOR loop
except through a FOR statement. Transferring control
into the middle of a loop can produce unpredictable
results.
FOR loops can be nested if one FOR loop is completely
contained within another. They must not overlap.
Examples
Each time the FOR statement executes, a smaller fraction
is printed.
>10 FOR A=1 TO 16
>20 PRINT 1/(107A)
>30 NEXT A
>RUN
et
+01
-001
+0001
-00001
+000002
-0000001
, «00000001
-000000001
+0000000001
- 00000000001
+000000000001
= 0000000000001
1,000000000000E-014
1.000000000000E-015
1.000000000000E-016
Note: In BINBASIC, the number would begin printing in
E-form after the line containing .000001
3-7The following FOR loop executes six times, decreasing the
value of X by 1 each time:
10 FOR X=0 TO -5 STEP -1
20 PRINT X
30 NEXT X
>RUN
The first X elements of the array P(N) are assigned
values. When N=X, the loop terminates. In this case,
the value of X is input as:
>10 INPUT X
>20 PRINT
>30 FOR N=1 TO x
>40 9 LET P(N)=N*1O
>50 PRINT P(N)
>60 NEXT N
>RUN
26
10
20
30
40
50
60
The examples below show legal. and illegal nesting.
A diagnostic is printed when an attempt is made to
run the second example:
10 REM..THIS EXAMPLE IS LEGAL
20 DIM ¥[7,16]
30 FOR A=1 TO 7 STEP 2
40 FOR B=1 T0 16 STEP 2
50 LET ¥(A,B)=-1
60 NEXT B
70 NEXT A
3-810 REM..THIS EXAMPLE IS ILLEGAL
20 DIM ¥[{7,16]
30 FOR A=1 TO 7 STEP 2
40 FOR B=1 TO 16 STEP 2
50 LET ¥(A,B)
60 NEXT A
70 NEXT B
>RUN
ERR:60 AT. 70
This example illustrates a complexity that can arise
when loops are exited via GOTO statements rather than
by normal completion.
10 FOR I=1 To 20
20 FOR J=1 T0 5
30 PRINT I,
40 IF J>2 THEN 70
50 NEXT J
60 NEXT I
70 REM THE LOOPS ABOVE ARE EXITED
80 FOR K=1 TO 10
90 FOR I=1 T0 3
100 PRINT K,I, "LATER"
110 NEXT I
120 NEXT K
>RUN
1 ~
& 2
1 L LATER
1 2 LATER
L 3 LATER
ERR 60 AT 120
Because the upper loop was exited prematurely, the first
two loops (FOR I, FOR J) were left active and the second
FOR I in line 90 caused all active loops (at this point,
FOR I, FOR J, and FOR K) to be deactivated (see discussion
above). An error was then generated in line 120 because
there was no active loop for K. The implication here is
that care should be exercised as to what loop variables
are chosen and in what order they are used.
3-93.4 GOTO/ON...GOTO STATEMENTS
GOTO and ON...GOTO override the normal sequential order of
statement execution by transferring control to a specified
statement. The statement to which control transfers must
be an existing statement.in the current program.
Format
GOTO statement label
ON integer expression GOTO statement label, statement label...
GOTO may have a single statement label, while ON...GOTO may
be multi-branched with more than one statement label.
Ig the multi-branch ON...GOTO is used, the value of the
integer expression determines the label in the list to
which control transfers.
Description
If the GOTO transfers to a statement that cannot be
executed (such as REM), control passes to the next
Sequential statement after that statement. GOTO
cannot transfer into or out of a function definition
(see Section 1X). If it should transfer to the DEF
statement, control passes to the line following the
function definition. (The function would be redefined
in this case -- see DEF statement, Section IX).
The labels in a multi-branch ON...GOTO are selected
by numbering them sequentially starting with 1, such
that the first label is selected if the value of the
expression is 1, the second label if the expression
equals 2, and so forth. If the value of the expression
is less than 1 or greater than the number of labels in
the list, then the GOTO is ignored and control transfers
to the statement immediately following ON.
If the expression is not an integer, it is rounded
to the nearest integer and that value is used to
select a label.
3-10