Radio Shack TRS-80 Model 100 Basic Manual page 193

Basic language lab
Hide thumbs Also See for TRS-80 Model 100:
Table of Contents

Advertisement

Explanation of the program:
Line
lee
The array R contains the result and the array S$ contains the most recent
operator at level L. The program begins at level 0. Levels are analogous to
expressions within parentheses. The level is increased by one as a left parenthesis is
encountered, and decreased by one as a right parenthesis is encountered.
Line 118 A subroutine is used to get a character from the keyboard. The character is
returned in the string variable C$.
Lines 128· 138 If the character returned is a decimal point (.) or a digit (0 - 9), then
a subroutine (GOSUB 600) is used to build the rest of the number. The value of the
number is returned in the numeric variable NU. Another subroutine (GOSUB 800) is
used to compute the result of applying the operator to the previous result (if any) and
the current value NU. The result is stored in the appropriate level of the array R.
Line 148 If a right parenthesis is typed, the value at the current level is combined
with the value at the previous level. This is why the operator at the previous level was
saved in the S$ array.
Lines 158 • 185 If an arithmetic operator is typed, it is saved in the S$ array.
Execution then returns to line 110 to get the next character.
Line 198 If a left parenthesis is typed, the level is increased by one, the result at the
new level is initialized to zero, and the operator is assumed to be addition. Execution
then returns to line
110
to get the next character.
Line
2ee
If
an equals sign
(=)
is typed, then the answer, which is the result at the
current level, is displayed. The level is initialized to zero and execution jumps to line
100 to begin a new problem.
Line 265 If (ENTER) is pressed, then the message CANCELED is displayed and a new
problem is begun.
Line 218 If any other key is inadvertently typed, it must be a mistake, and therefore
does nothing to the calculation. Execution jumps back to line
110
to get the next
character.
Lines 588 - 538 A
REMark statement is used for documentation in line 500. A REM
statement is ignored by the BASIC language interpreter and is used to insert
explanatory comments for the convenience of the programmer. This subroutine
continually scans the keyboard until a key is pressed. The character is stored in the
string variable C$ and displayed before returning. The INKEY$ function returns a null
string
( " " )
if no key is pressed.
Lines 688 • 728 This subroutine builds a number with or without a decimal point. If
the number has a decimal point, the subroutine first builds the part of the number to
the left of the decimal point, and then builds the part of the number to the right of the
decimal point. Since the characters are originally in string form (C$), the VAL
function is used to convert to numeric form. The number is assumed to be completed
when any character other than a digit or a decimal point is typed.
Lines 888 • 868 This subroutine computes the result at the current level. The
appropriate operator (
+, -, *,
or A) is applied and the result stored in the R array.
187

Advertisement

Table of Contents
loading

Table of Contents