Digital PDFs
Documents
Guest
Register
Log In
DEC-08-LBSMA-A-D
July 1973
88 pages
Original
2.8MB
view
download
Document:
8K BASIC
Order Number:
DEC-08-LBSMA-A-D
Revision:
Pages:
88
Original Filename:
http://bitsavers.org/pdf/dec/pdp8/basic/DEC-08-LBSMA-A-D_8K_BASIC_Jul73.pdf
OCR Text
DEC-08-LBSMA-A-D 8K BASIC For additional copies, order No. DEC-08-LBSMA-A-D from Software Distribution Center, Digital Equipment Corporation, Maynard, Mass. digital equipment corporation · maynard. massachusetts First Printing, July 1973 Copyright ~ 1973 by Digital Equipment Corporation The following are trademarks of Digital Equipment Corporation, Maynard, Massachusetts: COP COMPUTER LAB COMTEX COMSYST DOT DEC DECCOMM DECTAPE DIBOL DIGITAL DNC EDGRIN EDUSYSTEM FLIP CHIP FOCAL GLC-8 IDAC IDACS INOAC KAIO PS/8 LAB-8 QUICKPOINT RAD-8 RSTS RSX RTM SABR TYPESET 8 UNIBUS LAB-8/e LAB-K OMNIBUS OS/8 PDP PHA contents Introduction ...... ............................... .... ............................. 1 Numbers 2 Variables ............................................................................ 3 Arithmetic Operations ........................................................ Priority of Arithmetic Operations .................................. Parentheses ................................................................ 3 4 Relational Operators .......................................................... 5 Immediate Mode .........................................'....................... PRINT Command .... .... .. ..... ... .. . .. . ... ........... ... ... ....... ..... LET Command.............................................................. 6 6 BASIC Statements ............................................................ Example Program .......................................................... Statement Numbers ........................................................ Commenting the Program ............................................ REM .......................................................................... Terminating the Program .............................................. END .......................................................................... STOP ........................................................................ The Arithmetic Statement .............................................. LET .......................................................................... Input/Output Statements .............................................. READ and DATA .................................................... RESTORE ................................................................ INPUT ...................................................................... PTR .......................................................................... PRINT ...................................................................... LPT ............................................................................ PTP ............................................................................ TTY IN and TTY OUT ............................................ 7 7 8 IV 4 6 9 ·9 9 9 10 10 10 11 11 12 14 14 15 19 20 20 Loops ........................................................................... . FOR, NEXT, and STEP ........................................... . Subscripted Variables ................................................... . DIM ......................................................................... . 22 22 25 27 Transfer of Control Statements ................................... . Unconditional Transfer-oGOTO ............................ ,. Conditional Transfer-IF-THEN and IF-GOTO ..... . Subroutines ................................................................... . GOSUB and RETURN ........................................... . Functions ..................................................................... . Sign Function-SGN(x) ........................................... . Integer Function-INT(x) ....................................... . Random Number Function-RND(x) ................... . TAB Function ........................................................... . PUT and GET Functions ....................................... . FNA Function ................................................ '" ., ... ,.. . 29 29 User-Defined Function-UUF ......................................... . Coding Formats ........................................................... . Floating-Point Format ................................................. . Addressing ................................................................... . Floating-Point Instruction Set ..................................... . Writing the Program ................................................... . Examples ..................................................................... . 43 43 44 Editing and Control Commands ..................................... . Erasing Characters and Lines ....................................... . SHIFT /0, RUBOUTS, and NO RUBOUTS ........ .. Listing and Punching a Program ................................. . LIST ........................................................................ .. PTP and LPT .......................................................... Reading a Program ..................................................... . PTR ......................................................................... . Running a Program ................................................... . RUN ......................................................................... . PTP and LPT .......................................................... Stopping a Run ............ , .. " . . . " .. ... " . ." " " " " " " " ~ """ v " " "" " "" "" "" """" """"" " 30 30 30 34 35 35 36 37 39 42 45 45 47 48 53 53 53 55 55 55 56 56 56 56 57 57 CTRL/C .................................................................... CTRL/O .................................................................. Erasing a Program in Core .......................................... SCR .......................................................................... Loading and Operating Procedures .................................. BASIC Comp~ler ................ ............ ...................... ........ User-Defined Function .................................................. 57 57 58 58 58 58 59 8K BASIC Error Messages .............................................. 59 8K BASIC Symbol Table .................................................. 61 Statement and Command Summaries ................................ Edit and Control Commands ........................................ BASIC Statements ........................................................ 67 67 67 Appendix A Appendix B ...................................................................... A-l B-1 VI 8K basic INTRODUCTION 8K BASIC is an interactive programming language with a variety of applications. It is used in scientific and business environments to solve both simple and complex mathematical problems with a minimum of programming effort. It is used by educators and students as a problem-solving tool and as an aid to learning through programmed instruction and simulation. In many. respects the BASIC language is similar to other programming languages (such as FOCAL and FORTRAN), but BASIC is aimed at facilitating communication between the user and the computer. The BASIC user types in the computational procedure as a series of numbered statements, making use of common English words and familiar mathematical notations. Because of the small number of commands necessary and its easy applica. tion in solving problems, BASIC is one of the simplest computer languages to learn. With experience, the user can add the advanced techniques available in the language to perform more intricate manipulations or express a problem more efficiently and concisely. 8K BASIC is an extended version of DEC's 4K BASIC,l but has additional features and requires 8K of core. The user who has no familiarity with the BASIC language may wish to refer to the EduSystem Handbook for a background description of the language fundamentals, and for information pertaining to working with BASIC at the computer. The minimum system configuration for 8K BASIC is a PDP-8 1 4K BASIC, or EduSystem 10, is the most fundamental BASIC in DEC's series of EduSystems. This series is directed primarily for use in an educational environment. Information concerning the EduSystems may be obtained from DEC's PDP-8 Educational Marketing Department. 1 series computer with 8K of core memory. Supported options include a high-speed reader and punch, and an LP08 line printer. New features provided by 8K BASIC include one and twodimensional subscripting, faster execution time, user-coded functions, use of the LP08 line printer and high-speed reader/punch, and specification of input and output devices from any part of a program. Loading and operating instructions and a command summary are included at the end of the manual. NUMBERS BASIC treats all numbers (real and integer) as decimal numbers -that is, it accepts any number containing a decimal point, and assumes a decimal point after an integer. The advantage of treating all numbers as decimal numbers is that the programmer can use any number or symbol in any mathematical expression without regard to its type. In addition to integer and real formats, a third format is recognized and accepted by 8K BASIC and is used to express numbers outside the range .01 <=x<=1 ,000,000. This format is called exponential or E-type notation, and in this format, a number is expressed as a decimal number times some power of 10. The form is: xxEn where E represents "times IOta the power of"; thus the number is read: "xx times IOta the power of n." For example: 23.4E2 = 23.4*10~ = 2340 Data may be input in anyone or all three of these forms. Results of computations are output as decimals if they are within the range previously stated; otherwise, they are output in E format. BASIC handles seven significant digits in normal operation and input/ output, as illustrated below: Value Typed In Value Output By BASIC .01 .0099 999999 1000000 .01 9.900000E-3 999999 1.000000E+6 2 BASIC automatically suppresses the printing of leading and trailing zeros in integer and decimal numbers, and, as can be seen from the preceding examples, formats all exponential numbers in the form: (sign) x.xxxxxx E (+ or -) n where x represents the number carried to six decimal places, E stands for "times 10 to the power of," and n represents the exponential value. For example: -3.470218E+8 is equal to -347,021,800 7.260000E-4 is equal to .000726 VARIABLES A variable in BASIC is an algebraic symbol representing a number, and is formed by a single letter or a letter followed by a digit. For example: Acceptable Variables Unacceptable Variables I B3 2C - a digit cannot begin a variable AB - two or more letters cannot form a variable X The user may assign values to variables either by indicating the values in a LET statement, or by inputting the values as data; these operations are discussed further on in the manual. ARITHMETIC OPERATIONS BASIC performs addition, subtraction, multiplication, division and exponentiation, as well as more complicated operations explained in detail later in the manual. The five operators used in writing most formulas are: Symbol Meaning Example Operator + * I t Addition Subtraction Multiplication Division Exponentiation (Raise A to the Bth power) 3 A+B A-B A*B AlB AtB Priority of Arithmetic Operations In any given mathematical formula, BASIC performs the arithmetic operations in the following order of evaluation: 1. Parentheses receive top priority. Any expression within parentheses is evaluated before an unparenthesized expression. 2. In absence of parentheses, the order of priority is: a. Exponentiation b. Multiplication and Division (of equal priority) c. Addition and Subtraction (of equal priority) 3. If either 1 or 2 above does not clearly designate the order of priority, then the evaluation of expressions proceeds from left to right. The expression A tBtC is evaluated from left to right as follows: 1. AtB 2. (result of step 1) tC == step 1 == answer The expression A/B*C is also evaluated from left to right since multiplication and division are of equal priority: 1. AlB 2. (result of step 1) *C step 1 == answer PARENTHESES Parentheses may be used by the programmer to change the order of priority (as listed in rule 2 above), as expressions within parentheses are always evaluated first. Thus, by enclosing expressions appropriately, the programmer can control the order of evaluation. Parentheses may be nested, or enclosed by a second set (or more) of parentheses. In this case, the expression within the inner- . most parentheses is evaluated first, and then the next innermost, and so on, until all have been evaluated. Consider the following example: A=7*«Bt2+L!)/X) The order of priority is: 1. Bt2 2. (result of step 1) +4 3. (result of step 2) IX 4. (result of step 3) *7 4 step 1 step 2 step 3 A Parentheses also prevent any confusion or doubt as to how the expression is evaluated. For example: A*Bf2/7+B/C+Df2 Both of these formulas will be executed in the same way. However, the inexperienced programmer or student may find that the second is easier to understand. Spaces may be used in a similar manner. Since the BASIC compiler ignores spaces, the two statements: 10 LET B = Df2 + 1 10LETB=Df2+1 are identical, but spaces in the first statement provide ease in reading. RELATIONAL OPERATORS A program may require that two values be compared at some point to discover their relation to one another. To accomplish this, BASIC makes use of the following relational operators: > greater than > = greater than or equal to < less than <= less than or equal to equal to < > not equal to Depending upon the result of the comparison, control of program execution may be directed to another part of the program, or the validity of the relationship may cause a value of 0 to 1 to be associated with a variable (that is, if a condition is true, a value of 1 is assigned; if a condition is not true, then the value of 0 is returned). Relational operators are used in conjunction with IF and .LET statements, both of which are discussed in greater detail later in the manual. The meaning of the equal (=) sign should be clarified. In algebraic notation, the formula X==X + 1 is meaningless. However, in BASIC (and most computer languages), the equal sign desig: nates replacement rather than equality. Thus, this formula is actually translated: "add one to the current value of X and store 5 the new result back in the same variable X." Whatever value has previously been assigned to X will be combined with the value 1. An expression such as A=B+C instructs the computer to add the values of Band C and store the result in a third variable A. The variable A is not being evaluated in terms of any previously assigned value, but only in terms of Band C. Therefore, if A has been assigned 'any value prior to its use in this statement, the old value is lost; it is instead replaced by the value of B+C. IMMEDIATE MODE There are two commands available which allow BASIC to act as a calculator-PRINT and LET. The user types in the algebraic expression which is to be calculated, and BASIC types back the result. This is called immediate mode since the user is not required to write a detailed program to calculate expressions and equations, but can use BASIC to produce results immediately. PRINT Command The PRINT command is of the form: PRINT expression and instructs BASIC to compute the value of the expression and print it on the Teletype. The expression may be made up of any decimal number, the arithmetic operators mentioned previously, and the functions which are discussed further on in the manual. (These may be used in conjunction with a string of text, as explained in the section concerning the PRINT statement.) For example: PRINT 1/8t8 5.960L!6L!E-08 LET Command Values may be assigned to variables by use of the LET command as follows: LET variable = expression The computer does not type anything in response to this command, but merely stores the information. This information may then be used in conjunction with a PRINT command to calculate results. For example: 6 LET Pl=3.14159 PRINT Pl*4t2 50.26544 BASIC STATEMENTS Example Program The following example program is included at this point as an illustration of the format of a BASIC program, the ease in running it, and the type of output that may be produced. This program and its results are for the most part self-explanatory. Following sections cover the statements and commands used in BASIC programmIng. 10 REM - PROGRAM TO TAKE AVERAGE OF 15 REM - STUDENT GRADES AND CLASS GRADES 20 PRINT "HOW MANY STUDENTS, HOW MANY GRADES PER STUDENT"; 30 INPUT A,B 40 LET 1=0 50 FOR J= I TO A-I 55 LET V=0 60 PRINT "STUDENT NUMBER =";J 75 PRINT "ENTER GRADES" 76 LET D=J 80 FOR K=D TO D+(B-l) 81 INPUT G 82 LET V=V+G 85 NEXT K 90 LET V=V/B 95 PRINT "AVERAGE GRADE =";V 96 PRINT 99 LET Q=Q+V 100 NEXT J 101 PRINT 102 PRINT 103 PRINT "CLASS AVERAGE =";Q/A 104 STOP 140 END 7 RUN HOW MANY STUDENTS, HOW MANY GRADES PER STUDENT? 5,4 STUDENT NU~BER = 0 ENTER GRADES ?78 ?86 ?88 ?74 AVERAGE GRADE = 81.5 STUDENT NUMEER ENTER GRADES ?59 = 1 ?86 ?7V'J ?87 AVERAGE GRADE = 75.5 STUDENT NUMBER = 2 ENTER GRADES ?58 ?64 ?75 ?8V'J AVERAGE GRADE = 69.25 STUDENT NUMBER = 3 ENTER GRADES ?88 ? 92 ?85 ?79 AVERAGE GRADE = 86 STUDENT NUMBER ENTER GRADES = 4 ?60 ?78 ?85 ?8V'J AVERAGE GRADE 75.75 CLASS AVERAGE READY. Statement Numbers An integer number is placed at the beginning of each line in a BASIC program. BASIC executes the statements in a program in numerically consecutive order, regardless of the order in which they have been typed. A common practice is to number lines by 8 fives or tens, so that additional lines may be inserted in a program without the necessity of renumbering lines already present. Multiple statements may be placed on a single line by seperating each statement from the preceding statement with a backslash (SHIFT /L). For example: 10 A=S\B=.2\C=3\PRINT "ENTER DATA" All of the statements in line 10 will be executed before BASIC continues to the next line. Only one statement number at the beginning of the entire line is necessary. However, it should be remembered that program control cannot be transferred to a statement within a line, but only to the first statement of the line in which it is contained (see the section entitled Transfer of Control Statements). Commenting the Program REM The REM or REMARK statement allows the programmer to insert comments or remarks into a program without these comments affecting execution. The BASIC compiler ignores everything following REM. The form is: (line number) REM (message) In the Example Program, lines 10 and 15 are REMARK statements describing what the program does. It is often useful to put the name of the program and information relating to. its use at the beginning where it is available for future reference. Remarks throughout the body of a long program will help later debugging by explaining the purpose of each section of code within the program. Terminating the Program END The END statement (line 140 in the Example Program), if present, must be the last statement of the entire program. The form is: (line number) END This statement acts as a signal that the entire program has been executed. Use of the statement is optional. However, if the program contains an END statement, after execution, variables and 9 arrays are left in an undefined state, thereby losing any values they have been assigned during execution. STOP The STOP statement is used synonymously with the END statement to terminate execution, but while END occurs only once at the end of ~ program, STOP may occur any number of times. The format of the STOP statement is: (line number) STOP This statement signals that execution is to be terminated at that point in the program where it is encountered. The Arithmetic Statement LET The Arithmetic (LET) statement is probably the most commonly used BASIC statement and is used whenever a value is to be assigned to a variable. It is of the form: (line number) (LET) x = expression 'where x represents a variable, and the expression is either a number, another variable, or an arithmetic expression. The word 'LET' is optional; thus the following statements are treated the same: 100 LET A=AfR+10 110 LET C=F/G 100 A=AtF3+10 110 C=F/G As mentioned earlier, relational operators may be used in a LET statement to assign a value of 0 (if false) or I (if true) to a variable depending upon the validity of a relationship. For example: 100 110 120 1 30 140 150 A=1\B=2 C=A=B D=A>B E=A<>B PRINT C.,D.,E END Translated, this actually means "let C= 1 if A=B (0 otherwise); let D== 1 if A> B (0 otherwise)" and so on. Thus, the values of C, D, and E are printed as follows: 10 RUN o o READY. There is no limit to the number of relationships that may be tested in the statement. Input/ Output Statements Input/Output statements allow the user to bring data into a program and output results or data at any time during execution. The Teletype keyboard, low or high-speed reader/punch, and LP08 line printer are all available as I/O devices in 8K BASIC. Statements which control their use are described next. READ AND DATA READ and DATA statements are used to input data into a program. One statement is never used without the other. The form of the READ statement is: (line number) READ x I, x2, ... xn where xl through xn represent variable names. For example: 10 READ A"B"C A, B, and C are variables to which values will be assigned. Variables in a READ statement must be separated by commas. READ statements are generally placed at the beginning of a program, but must at least logically occur before that point in the program where the value is required for some computation. Values which will be assigned to the variables in a READ statement are supplied in a DATA statement of the form: (line number) DATA xl, x2, ... xn where x 1 through xn represent values. The values must be separated by commas and occur in the same order as the variables which are listed in the corresponding READ statement. A DATA statement appropriate for the preceding READ statement is: 70 DATA 1,2,3 11 Thus, at execution time A=I, B==2, and C=3. The DATA statement is usually placed at the end of a program (before the END statement) where it is easily accessible to the programmer should he wish to change the values. A READ statement may have more or fewer variables than there are values in any one DATA statement. The READ statement causes BASIC to search all available DATA statements in the order of their line numbers until values are found for each variable in the READ. A second READ statement will begin reading values where the first stopped. If at some point in the program an attempt is made to read data which is not present or if the data is not separated by commas, BASIC will stop and print the following message at the console: DATA ERROR AT LINE XXXX where XXXX indicates the line which caused the error. RESTORE If it should become necessary to use the same data more than once in a program, the RESTORE statement will make it possible to recycle through the DATA statements beginning with the lowest numbered DATA statement. The RESTORE statement is of the form: (line number) RESTORE An example of its use follows: 15 READ B."C."D 55 RESTORE 60 100 READ E."F."G END The READ statements in lines 15 and 60 will both read the first three data values provided in line 80. (If the RESTORE statement 12 had not been inserted before line 60, then the second READ would pick up data in line 80 starting with the fourth value.) The programmer may use the same variable names the second time through the data, or not, as he chooses, since the values are being read as though for the first time. In order to skip unwanted values, the programmer may insert replacement, or dummy, variables. Consider: 1 REM - PROGRAM TO ILLUSTRATE USE OF RESTORE 20 READ N 25 PRINT "VA.LUES OF X ARE:" 30 FOR 1=1 TO N 40 READ X 50 PRINT X, 60 NEXT I 70 RESTORE 185 PRINT 190 PRINT "SECOND LIST OF X VALUES" 200 PRINT "FOLLOWING RESTORE STATEMENT:" 210 FOR 1=1 TO N 220 READ X 230 PRINT X, 2LJ0 NEXT I 250 DATA Lj, 1,2 251 DATA 3,LJ 300 END RUN VALUES OF X ARE: 1 LJ 3 2 SECOND LIST OF X VALUES FOLLOWING RESTORE STATEMENT: 2 LJ 1 READY. 3 The second time the data values are read, the first X picks up the value originally assigned to N in line 20, and as a result, BASIC prints: 2 13 3 To circumvent this, the programmer could insert a dummy variable which would pick up and store the first value, but would not be represented in the PRINT statement, in which case the output would be the same each time through the list. INPUT The INPUT statement is used when data is to be supplied by the user from the Teletype keyboard while a program is executing, and is of the form: (line number) INPUT xl, x2, ... xn where xl through xn represent variable names. For example: 25 INPUT A,B,C This statement will cause the program to pause during execution, print a question mark on the Teletype console, and wait for the user to type in three numerical values. The user must separate the values by commas; they are entered into the computer by his pressing the RETURN key at the end of the list. If the user does not insert enough values to satisfy the INPUT statement, BASIC prints another question mark and waits for more values to be input. When the correct number has been entered, execution continues. If two many values are input, BASIC ignores those in excess of the required number. The values are entered when the user types the RETURN key. PTR A PTR statement is used when data is to be input from the highspeed paper tape reader. The format of the data on the paper tape must be the same as it would be if it were input from the Teletype keyboard. If more than one value is to be input at a time, the values must be separated by commas. The tape must be positioned in the reader before it is called by the program; while it is reading, there is no echo (type out) on the Teletype. The for~ is: (line number) PTR The PTR statement is most useful for inputting large amounts of data in conjunction with the INPUT command. The following program accepts 20 data values from the high-speed reader, prints a heading, the value input, and its sine on the Teletype: 14 50 PTR 60 PRINT "SINE TABLE" 100 FOR J=1 TO 20 110 INPUT A 120 LET B=SINCA) 130 PRINT A.1B 140 NEXT J 1 50 END RUN SINE TABLE -.97 -.911 -.872 -.723 -.719 -.61 -.502 -.346 -.33 -.283 -.175 -.155 - .02 .03 .093 .127 • 13 .42 .529 .632 -.8248857 -.79011 71 -.7656171 -.6616371 -.6586325 -.5728675 -.4811798 -.3391376 -.324043 -.2792376 -.1741081 -. 1543801 -.01999867 .0299955 .092866 .1266589 .1296341 .4077605 .5046703 .5907596 READY. PRINT The PRINT statement is used to output results of computations, comments, values of variables, or plot points of a graph on the Teletype. The format is: (line number) PRINT expression When used without an expression, a blank line will be output on the Teletype. For more complicated formats, the type of expression and the type of format control characters following the word PRINT determines which formats will be created. In order to have the computer print out the results of a computation, or the value of a variable at any point in the program, the 15 user types the line number, PRINT, and the variable name(s) separated by a format control character, in this case, commas: 5 A=1()\B=5\C=4 10 PRINT A~C+R~SQR(A) In BASIC, ·a Teletype line is formatted into five fixed columns (called print zones) of 14 spaces each. In the above example, the values of A, C+B, and the square root of A will be printed in the first three of these zones as follows: RUN 16 9 4 READY. A statement such as: 5 A=2.3\R=21\C=156.75\D=1.134\E=23.4 10 PRINT A~B,C,D,E will cause the values of the variables to be printed in the same format using all five columns: RUN 2.3 21 156.75 1.134 23.4 READY. When more than five variables are listed in the PRINT statement, the sixth value begins a new line of output. The PRINT statement may also be used to output a message or line of text. The desired message is simply placed in quotation marks in the PRINT statement as follows: 10 PRINT "THIS IS A TEST" When line lOis encountered during execution, the following will be printed: THIS IS A TEST A message may be combined with the result of a calculation or a variable as follows: 16 80 PRINT "AMOUNT PER PAYMENT ="R Assuming R=344.9617, when line 80 is encountered during execution, this will be output as: RUN AMOUNT PER PAYMENT = 344.9617 READY. It is not necessary to use the standard five zone format for output. The control character semicolon· ( ;) causes the text or data to be output immediately after the last character printed (separated by one space.) If neither a comma nor a semicolon is used, BASIC assumes a semicolon. Thus both of the following: 80 PRINT "AMOUNT PER PAYMENT ="R 80 PRINT "AMOUNT PER PAYMENT =";R will result in: AMOUNT PER PAYMENT = 344.9617 The PRINT statement can also cause a constant to be printed on the console. (This is similar to the PRINT command used in Immediate Mode.) For example: 10 PRINT 1.234,SQR(10014) will cause the following to be output at execution time: 1.234 100.07 Any algebraic expression in a PRINT statement will be evaluated using the current value of the variables. Numbers will be printed according to the format previously specified. The following example program illustrates the use of the control characters 2 in PRINT statements: 2 The user may wish to refer to the section entitled Functions for information pertaining to three functions available for additional character control-TAB, PUT, and GET. 17 1121 2121 3121 4121 5121 6121 READ A,B,C PRINT A,B,C,At2,Bt2,Ct2 PRINT PRINT A;B;C;AT2;Bt2;Ct2 DATA 4,5,6 END RUN 5 4 16 6 25 36 4 5 6 16 25 36 READY. As this example illustrates, if a number should be too long to be printed on the end of a single line, BASIC automatically moves the entire number to the beginning of the next line. Another use of the PRINT statement is to combine it with an INPUT statement so as to identify the data expected to be entered. As an example, consider the following program: 10 REM - PROGRAM TO COMPUTE INTEREST PAYMENTS 20 PRINT "INTEREST IN PERCENT"; 25 INPUT J 26 LET J=J/100 30 PRINT "AMOUNT OF LOAN" ; 35 INPUT A 40 PRINT "NUMBER OF YEARS"; 45 INPUT N 50 PRINT "NUMBER OF PAYMENTS PER YEAR"; 55 INPUT M 60 LET N=N*M 65 LET I=J/M 70 LET B=!+I 75 LET R=A*I/(1-1/BfN) 78 PRINT 80 PR INT "AMOUNT PER PAYMENT ="; R 85 PRINT "TOTAL INTEREST =";R*N-A 88 PRINT 90 LET B=A 95 PRINT " INTEREST APP TO PRIN BALANCE" 100 LET L=B* I 110 LET P=R-L 120 LET B=B-P 130 PRINT L.,P.,B 140 IF B>=RGC TO 100 150 PRINT B*I.,R-B*I 160 PRINT "LAST PAYMENT ="B*I+B 200 END 18 RUN INTEREST IN PERCENT?9 AMOUNT OF LOAN?2500 NUMEER OF YEARS?2 NUMBER OF PAYMENTS PER YEAR?4 AMOUNT PER PAYMENT = 344.9617 TOTAL INTEREST = 259.6932 INTEREST 56.25 49.75399 43.11182 36.32019 29.37576 22.27508 15.01463 7.590824 LAST PAYMENT APP TO PR IN 288.7117 295.2077 301.8498 308.6415 315.5859 322.6866 329.947 337.3708 = 344.9608 BALANCE 2211.288 1916.081 1614.231 1305.589 990.0035 667.317 337.3699 READY. As can be noticed in this example, the question mark is grammatically useful in a program in which several values are to be input by allowing the programmer to formulate a verbal question which the input value will answer. LPT The LPT statement is used to generate output on the LP08 line printer, and is of the form: (line number) LPT By inserting this statement anywhere in a program, all subsequent output, with the exception of error messages, will be printed on the line printer. The LPT statement is particularly advantageous for outputting large amounts of calculated data, as can be seen from this and following examples: 100 110 120 130 140 LPT FOR F=30 TO 60 STEP 3 PRINT FJlFf2 NEXT F END 19 q~~ 10bq 12q& 1521 17b4 21iJ25 2304 2b01 2qlb 32"Q 30~H" When the END statement is encountered in the program, the output device is reset to the Teletype. PTP The high-speed paper tape punch is also available as an output device in 8K BASIC, permitting users to save data or output files quickly on paper tape. When the statement is encountered, all output is diverted from the Teletype to the high-speed punch. Control automatically returns to the Teletype when the END statement is encountered. The form is: (line number) PTP By substituting this statement in line 100 of the previous program, all output, with the exception of error messages, will be sent to the high-speed paper tape punch instead of the line printer. TTY IN AND TTY OUT The Teletype may be placed under program control so that, during execution of a program, 110 may be obtained or sent alternately between any available device. By issuing the statement: (line number) TTY IN control of input is returned to the Teletype if it has been previously set to another device. Similarly, the statement: (line number) TTY OUT returns output control to the Teletype. 20 The following program makes use of most all the available I/O devices. The output, with the exception of paper tape, is also included. 100 LPT 110 PRINT "FIRST DEGREE EQUATION CALCULATION" 120 TTY IN 130 TTY OUT 135 PRINT "TYPE Xl Y1 THEN X2 Y2" 140 INPUT X1,Y1,X2,Y2 150 X=X2-X1 160 Y=Y2-Y1 170 M=Y/X 180 B=Y2-M*X2 190 IF B> =0 THEN 300 200 PRINT "Y="M"X"B 210 LPT 220 PRINT "Y="M"X"B 230 GO TO 400 300 PRINT "Y="M"X+"B 310 LPT 320 PRINT "Y="M"X+"B 400 FOR Y=0 TO 10 STEP 2 410 FOR X=0 TO 10 STEP .5 420 LET T=M*X+B-Y 430 IF T<>0 THEN 480 440 PRINT X,Y 450 PTP 460 PRINT X, Y 470 LPT 480 NEXT X 490 NEXT Y 500 END RUN TYPE Xl Y1 THEN X2 Y2 1-3,-4,-1,0 Y= 2 X+ 2 READY. The line printer output is the following: FIRST DEG~~E CALCULATIO~ va 2 x+ 2 " 1 2 3 4 21 NOTE The Teletype low-speed reader and punch may be used as I/O devices at any time. No special statement is required. To read in data from the low-speed reader, position the tape over the sprocket wheel and set the reader to START when input is required. The tape will begin reading in. To punch a tape, set the low-speed punch to ON and all ouput will be punched on the low-speed punch. Using the low-speed I/O devices is, in effect, the same as using the Teletype keyboard. Characters will be typed on the Teletype keyboard as tapes are being read in or punched. Loops FOR, NEXT, AND STEP FOR and NEXT statements define the beginning and end of a loop. A loop is a set of instructions which are repeated over and over again, each time being modified in some way until a terminal condition is reached. The FOR statement is of the form: (line number) FOR v=xl TO x2 STEP x3 where v represents a variable name, and xl, x2, and x3 all represent formulas (a formula in this case means a numerical value, variable name, or mathematical expression). v is termed the index, xl the initial value, x2 the terminal value, and x3 the incremental value. For example: 15 FOR K=2 TO 20 STEP 2 This means that the loop will be repeated as long as K is less than or equal to 20. Each time through the loop, K is incremented by 2, so the loop will be repeated a total of 10 times. A variable used as an index in a FOR statement must not be subscripted, although a common use of loops is to deal with subscripted variables, using the value of the index as the subscript of 22 a previously defined variable (this is illustrated in the section concerning Subscripted Variables). The NEXT statement is of the form: (line number) NEXT and signals the end of the loop. When execution of the loop reaches the NEXT statement, the computer adds the STEP value to the index and checks to see if the index is less than or equal to the terminal value. If so, the loop is executed again. If the value of the index exceeds the terminal value, control falls through the loop to the following statement, with the value of the index equaling the value it was assigned the final time through the 100p. 3 If the STEP value is omitted, a value of + 1 is assumed. Since + 1 is the usual STEP value, that portion of the statement is frequently omitted. The STEP value may also be a negative number. The following example illustrates the use of loops. This loop is executed 10 times: the value of I is 10 when control leaves the loop. + 1 is the assumed STEP value. 1 0 FOR I = 1 TO 10 20 NEXT I 30 PRINT I 40 END RUN 10 READY. If line 10 had been: 10 F OR I = 10 TO 1 STEP - 1 the value printed by the computer would be 1. As indicated earlier, the numbers used in the FOR statement 3 The user should note that this method of handling loops varies among different versions of BASIC. 23 are formulas; these formulas are evaluated upon first encountering the loop. While the index, initial, terminal and STEP values may be changed within the loop, the value assigned to the initial formula remains as originally defined until the terminal condition is reached. To illustrate this point, consider the last example program. The value of I (in line 10) can be successfully changed as follows: 10 FOR 1=1 TO 10 15 LET 1=10 20 NEXT 1 The loop will only be executed once since the value 10 has been reached by the variable I and the terminal condition is satisfied. If the value of the counter variable is originally set equal to the terminal value, the loop will execute once, regardless of the STEP value. If the starting value is beyond the terminal value, the loop will also execute only once. It is possible to exit from a FOR-NEXT loop without the index reaching the terminal value. (This is known as a conditional transfer and is explained in the section entitled Transfer of Control Statements.) Control may only transfer into a loop which has been left earlier without being completed, ensuring that the terminal and STEP values are assigned. Nesting Loops It is often useful to have one or more loops within a loop. This technique is called nesting, and is allowed as long as the field of one loop (the numbered lines from the FOR statement to the corresponding NEXT statement, inclusive) does not cross the field of another loop. A diagram is the best way to illustrate acceptable nesting procedures: 24 ACCEPTABLE NESTING TECHNIQUES UNACCEPTABLE NESTING TECHNIQUES Two Level Nesting FOR FOR [ NEXT FOR [ NEXT NEXT ~ FOR FOR NEXT NEXT Three Level Nesting FOR FOR FOR [ NEXT FOR [ NEXT NEXT NEXT FOR FOR FOR [ NEXT FOR NEXT NEXT NEXT A maximum of eight (8) levels of nesting is permitted. Exceeding that limit will result in the error message: FOR ERROR AT LINE XXX X where XXXX is the number of the line in which the error occurred. Subscripted Variables In addition to single variable names, BASIC accepts another class of variables called subscripted variables. Subscripted variables provide the programmer with additional computing capabilities for handling lists, tables, matrices, or any set of related variables. Variables are allowed one or two subscripts. A siI}gle letter forms the name of the variable; this is followed by one or two integers in parentheses and separated by commas, indicating the place of that variable in the list. Up to 26 arrays are possible in any program (corresponding to the letters of the alphabet), subject only to the amount of core space available for data storage. For example, a list might be described as A (I) where I goes from 1 to 5, as follows: 25 This allows the programmer to reference each of the five elements in the list A. A two dimensional matrix A(I, J) can be defined in a similar manner, but the subscripted variable A can only be used once (i.e., A(I) and A(I,J) cannot be used in the same program). It is possible however, to use the same variable name as both a subscripted and an unsubscripted variable. Both A and A(I) are valid variable names and can be used in the same program. Subscripted variables allow data to be input quickly and easily, as illustrated in the following program (the index of the FOR statement in line~ 20, 42, and 44 is used as the subscript) : 10 REM - PROGRAM DEMONSTRATING READING 11 REM - OF SUBSCRIPTED VARIABLES 15 DIM A(5),BC2,3) 18 PRINT "ACI) WHERE A=1 TO 5;" 20 FOR 1=1 TO 5 25 READ AC I) 30 PR INT A CI ) ; 35 NEXT I 38 PRINT 39 PRINT 40 PRINT "BCI,J) WHERE 1=1 TO 2:" 41 PRINT" AND J=1 TO 3:" 42 FOR 1=1 TO 2 43 PRINT 44 FOR J=1 TO 3 4 8 READ B CI , J) 50 PRINT BCI,J); 55 NEXT J 56 NEXT I 60 DATA 1,2,3,4,5,6,7,8 61 DATA 8,7,6,5,4,3,2,1 65 END RUN ACI) WHERE A=1 TO 5; 234 5 BCI,J) WHERE 1=1 TO 2: AND J=1 TO 3: 6 7 8 8 7 6 READY. 26 DIM From the preceding example, it can be seen that the use of subscripts requires a dimension (DIM) statement to define the maximum number of elements in the array. The DIM statement is of the form: (line number) DIM VI (nl), v~ (n:,!, m:.!) where v., indicates an array variable name and nand m are integer numbers indicating the largest subscript value required during the program. For example: 15 DIM A(6~10) The first element of every array is automatically assumed to have a subscript of zero. Dimensioning A (6, 10) sets up room for an array with 7 rows and 11 columns. This matrix can be thought of as existing in the following form: Ao,lo Al,ll) A 2 ,lo AG,o A G,1 and is illustrated in the following program: 27 10 15 20 22 25 28 30 35 40 45 50 REM - MATRIX CHECK PROGRAM DIM A(6.110 ) FOR 1=0 TO 6 LET A(I.10)=I FOR J=0 TO 10 LET A(0.1J)=J PR INT A ( 1.1 J) ; NEXT J PRINT NEXT I END RUN 1 0 1 0 2 0 3 0 4 0 5 0 6 0 2 0 0 0 0 0 0 3 0 0 0 0 0 0 4 0 0 0 0 0 0 5 0 0 0 0 0 0 6 0 0 0 0 0 0 7 0 0 0 0 0 0 8 9 0 0 0 0 0 0 0 0 0 0 0 0 10 0 0 0 0 0 0 READY. Notice that a variable assumes a value of zero until another value has been assigned. If the user wishes to conserve core space by not making use of the extra variables set up within the array, he should set his DIM statement to one less than necessary, DIM A(5,9). This results in a 6 by 10 array which may then be referenced beginning with the A (0, 0) element. More than one array can be defined in a single DIM statement: 10 DIM A(20).1 B(4.17) This dimensions both the list A and the matrix B. A number must be used to define the maximum size of the array. A variable inside the parentheses is not acceptable and will result in an error message by BASIC at run time. The amount of user core not filled by the program will determine the amount of data the computer can accept as input to the program at anyone time. In some programs a TOO-BIG ERROR may occur, indicating that core will not hold an array of the size requested. In that event, 28 the user should change his program to process part of the data in one run and the rest later. Transfer of Control Statements Certain control statements cause the execution of a program to jump to a different line either unconditionally or depending upon some condition within the program. Looping is one method of jumping to a designated point until a condition is met. The following statements give the programmer added capabilities in this area. UNCONDITIONAL TRANSFER-GOTO The GOTO (or GO TO) statement is an unconditional statement used to direct program control either forward or back in a program. The form of the GOTO statement is: (line number) GOTO n where n represents a statement number. When the logic of the program reaches the GOTO statement, the statement(s) immediately following will not be executed; instead execution is transferred to the statement beginning with the line number indicated. The following program never ends; it does a READ, prints something, and jumps back to the READ via a GOTO statement. It attempts to do this over and over until it runs out of data, which is sometimes an acceptable, though not advisable, way to end a program. 10 REM - PROGRAM ENDING WITH ERROR 11 REM - MESSAGE WHEN OUT OF DATA 20 READ X 25 PRINT "X="X,"Xt2="Xt2 30 GO TO 20 35 DATA 1,5,10,15,20,25 40 END RUN X= 1 X= 5 X= 10 X= 15 X= 20 X= 25 Xt2= Xt2= Xt2= Xf2= Xf2= Xt2= 1 25 100 225 400 625 DATA ERROR AT LINE 20 29 CONDITIONAL TRANSFER-IF-THEN AND IF-GOTO If a program requires that two values be compared at some point, control of program execution may be directed to different procedures depending upon the result of the comparison. In computing, values are logically tested to see whether they are equal, greater than, less than another value, or possibly a combination of the three. This is accomplished by use of the relational operators discussed earlier. IF-THEN and IF-GOTO statements allow the programmer to test the relationship between two formulas (variables, numbers, or expressions). Providing the relationship described in the IF statement is true at the point it is tested, control will transfer to the line number specified, or perform the indicated operation. The statements are of the form: (line number) IF vI <relation> v2 {~~~~}x or expression where v 1 and v2 represent variable names or expressions, x represents a line number, and expression represents an operation to be performed. The use of either THEN or GOTO is acceptable. The following two examples are equivalent (the value of the variable A is changed or remains the same depending upon A's relation to B) : 100 IF A>B THEN 120 110 A=AfB-1 120 C=A/D 100 IF A<=B THEN A=AfB-1 110 C=A/D Subroutines GOSUB AND RETURN A subroutine is a section of code performing some operation that is required at more than one point in the program. Often a 30 complicated I/O operation for a volume of data, a mathematical evaluation which is too complex for a user-defined function, or any number of other processes may best be performed in a subroutine. Subroutines are generally placed physically at the end of a program, usually before DATA statements, if any, and always before the END statement. Two statements are used exclusively in BASIC to handle subroutines; these are the GOSUB and RETURN statements. A program begins execution and continues until it encounters a GOSUB statement of the form: (line number) GOSUB x where x represents the first line number of the subroutine. Control then transfers to that line. For example: 50 GOSUP 200 When program execution reaches line 50, control transfers to line 200; the subroutine ~s processed until execution encounters a RETURN statement of the form: (line number) RETURN which causes control to return to the statement following the GOSUB statement. Before transferring to the subroutine, BASIC internally records the next statement to be processed after the GOSUB statement; thus the RETURN statement is a signal to transfer control to this statement. In this way, no matter how many different subroutines are called, or how many times they are used, BASIC always knows where to go next. The following program demonstrates a simple subroutine: 31 1 REM - THIS PROGRAM ILLUSTRATES GOSUB AND RETURN 10 DEF FNACX)=ABSCINTCX» 20 INPUT A."B."C 30 GOSUB 100 40 LET A=FNACA) 50 LET B=FNA CB) 60 LET C=FNA CC) 70 PRINT 80 GOSUB 100 90 STOP 100 REM - THIS SUBROUTINE PRINTS OUT THE SOLUTIONS 110 REM - OF THE EQUATION: ACXt2) + BCX) + C = 0 120 PRINT '!THE EQUATION IS "A"*Xt2 + "B"*X + tIC 130 LET D=B*B-4*A*C 140 IF D<>0 THEN 170 150 PRINT "ONLY. ONE SOLUTION ••• X ="-B/C2*A) 160 RETURN 170 IF D<0 THEN 20~ 180 PRINT "TWO SOLUTIONS ••• X ="; 185 PRINT C-B+SQRCD»/C2*A)"AND X ="C-B-SQRCD»/C2*A) 190 RETURN 200 PRINT "IMAGINARY SOLUTIONS ••• X =; C"; 2 0 5 P R IN T - B / C2 * A ) " ." " S QR ( - D ) / ( 2 * A ) " ) AN DC" ; 207 PRINT -B/C2*A)".,,"-SQR(-D)/C2*A)")" 210 RETURN 900 END RUN ?1,.5.,,-.5 THE EQUATION IS 1 *Xt2 + .5 *X TWO SOLUTIONS ••• X .5 A~D X =-1 .+ -.5 THE EQUATION IS 1 *Xt2 + 0 *x + IMAGINARY SOLUTIONS ••• X = ( 0 , 1 ) 1 AND~ C 0 .,,-1 ) READY. Line 100 begins the subroutine. There are several places in which control may return to the main program, depending upon a certain. condition being satisfied. The subroutine is executed from line 30 and again from line 80. When control returns to line 90, the program encounters the STOP statement and execution is terminated. It is important to remember that subroutines should generally be kept distinct from the main program. The last statement in the main program should be a STOP or GOTO statement, and subroutines are normally placed following this statement. 32 More than one subroutine may be used in a single program, in which case these can be placed one after another at the end of the program (in line number sequence). A useful practice is to assign distinctive line numbers to subroutines. For example, if the main program is numbered with line numbers up to 199, 200 and 300 could be used as the first numbers of two subroutines. Nesting Subroutines Nesting of subroutines occurs when OOe subroutine calls another subroutine. If a RETURN statement is encountered during execution of a subroutine, control returns to the statement following the GOSUB which called it. From this point, it is possible to transfer to the beginning or any part of a subroutine, even back to the calling subroutine. Multiple entry points and RETURN statements make subroutines more versatile. The maximum level of GOSUB nesting is about thirty-three (33) levels, which should prove more than adequate for all normal uses. Exceeding this limit will result in the message: GOSUB ERROR AT LINE XXXX where XXXX represents the line number where the error occurred. An example of GOSUB nesting follows (execution has been stopped by typing a CTRLjC, as the program would otherwise continue in an infinite loop; see Stopping a Run.) 33 10 ijEM FACTORIAL PROGRAM USING GOSUB TO 15 REM RECURSIVELY GOMPUTE THE FACTORS INPUT N 50 IF N> 20 THE~ 120 60 X= 1 40 70 K=l 80 GOSUB 200 90 PRINT "FACTORIAL"W" ="X 110 GO TO 40 120 PRINT "MUST BE 20 130 GO TO 40 OR LESS" 200 X='X*K 210 K=K+l 220 IF K<=N THEN GOSUB 2ae 230 RETURN 240 END RUN ?2 FACTORIAL 2 2 ?4 FACTORIAL 4 24 ?5 FACTORI-AL 5 120 ? STOP. READY. Functions BASIC performs several mathematical calculations for the programmer, eliminating the need for tables of trig functions, square roots, and logarithms. These functions have a three letter call name, followed by an argument, x, which can be a number, variable, expression, or another. function. Table 1 lists the functions available in 8K BASIC. Most are self-explanatory; those that are not and are provided in greater detail are marked with asterisks. Table 1 8K BASIC Functions Function Meaning SIN(x) Sine of x (x is expressed in radians) COS(x) Cosine of x (x is expressed in radians) 34 Table 1 8K BASIC Functions (Cont.) Function Meaning TAN(x) Tangent of x (x is expressed in radians) ATN(x) Arctangent of x (result is expressed in radians) EXP(x) eX (e=2.718282) LOG(x) N aturallog of x (logex) *SGN(x) Sign of x-assign a value of + 1 if x is positive, 0 if x is zero, or-l if x is negative *INT(x) Integer value of x ABS(x) Absolute value of x (Ixl) SQR(x) Square root of x (VX) *RND(x) Random number *TAB(x) Print next character at space x *GET(x) Get a character from input device *PUT(x) Put a character on output device *FNA(x) User-defined function *UUF(x) User-coded function (machine language code) SIGN FUNCTION-SGN (X) The sign function returns the value + 1 if x is a positive value, o if x is zero, and-l if x is negative. For example, SGN(3.42)=1, SGN( -42) =-1, and SGN(23-23) =0. The following example in which X is assigned the sign of y illustrates the use of this function: INTEGER FUNCTION-INT(X) The integer function returns the value of the nearest integer not greater than x. For example, INT (34.67) =34. By specifying 35 INT(x+.5) the INT function can be used to round numbers to the nearest integer; thus, INT(34.67+.5)==35. INT can also be used to round numbers to any given decimal place by specifying: INT (x* 1OtD+ .5)/1 OtD where D is the number of decimal places desired. The following program illustrates this function; execution has been stopped by typing a CTRL/C: 10 20 30 40 50 60 70 80 90 REM - INT FUNCTION EXAMPLE PRINT "NUMBER TO BE ROUNDED"; INPUT A PRINT "NO. OF DECIMAL PLACES','; INPUT D LET B=INTCA*10tD+.5)/10tD PRINT "A ROUNDED = "B GO TO 20 END RUN NUMBER TO BE ROUNDED?55.65342 NO. OF DECIMAL PLACES?2 A ROUNDED = 55.65 NUMBER TO BE ROUNDED?78.375 NO. OF DECIMAL PLACES?-2 A ROUNDED = 100 NUMBER TO BE ROUNDED?67.89 NO. OF DECIMAL PLACES?-1 A ROUNDED 70 NUMBER TO BE ROUNDED? STOP. READY. If the argument is a negative number, the value returned is the largest negative integer (rounded to the higher value) contained in the number. For example, INT(-23)==-23 but INT( -14.39)=-15. RANDOM NUMBER FUNCTION-RND(X) The random number function produces a random number between 0 and 1. The numbers are not reproducible, a fact the programmer should keep in mind when debugging or checking his 36 program. The argument x in the RND (x) function call can be any number, as that value is ignored. The following program illustrates the use of this function to generate a table of random numbers: 10 25 30 40 50 60 REM - RANDOM NUMBER EXAMPLE PRINT "RANDOM NUMBERS" FOR 1=1 TO 30 PRINT RND(0), NEXT I END RUN RANDOM NUMBERS .9547609 .05280478 .9848808 .5828625 .04672124 .2585353 READY. .2890875 .3859534 .2466345 .7026891 .9868434 .5187701 .1416765 .8404774 .61588 .9703719 .5005693 .7858024 .2482717 .5692836 .4755698 .4980298 .1218251 .04588368 .2145417 .8514056 .3104984 .2548316 .2258269 .2030807 It is possible to generate random numbers over any range by using the following formula: (B-A)*RND(O)+A This produces a random number (n) in the range A<n<B. In order to obtain random integer digits in the range 0< == n<9, line 40 in the previous example is changed to read: 40 PRINT INT(9*RND(0)), When the program is run again, the results will look as follows: RANDOM NUMBERS 8 8 0 3 3 8 2 2 6 7 0 2 READY. 3 (21 0 0 4 6 1 0 4 6 5 7 7 8 6 6 2 = Notice that the range has changed to 0< n<9. This is because the INTfunction returns the value of the nearest integer not greater than n. TAB FUNCTION The TAB function allows the user to posItIon the printing of characters anywhere on the Teletype (or line printer) line. Print 37 positions can be thought of as being numbered from 1 to 72 across the Teletype from left to right. (For printing devices with long lines, the number of positions may be as large as 255, but it is unlikely that more than 160 spaces will be required for most printers.) The form of this function is: TAB (n) where the argument n represents the position (from 1 to the total number of spaces available) in which the next character will be typed. Each time the TAB function is used, positions are counted from the beginning of the line, not from the current position of the printing head. For example, T AB(3) causes the character to be printed at position 3; the following statement: 10 PRINT "X =";TAB(3);"/";3.14159 will print the slash on top of the equal sign, as shown below: X ~ 3.14159 READY. The following is an example of the sort of graph that can be drawn with BASIC using the TAB function: 38 30 40 50 60 FOR X=0 TO 15 STEP .5 PRINT TABC30+15*SINCX)*EXPC-.l*X));"*" NEXT X END RUN * * * * *' * * * * * * * * * * * * * * * * * * * * * * * * * * READY. PUT AND GET FUNCTIONS 8K BASIC provides two additional functions, PUT and GET, to increase input/output flexibility. Using these statements, the programmer can "PUT" an ASCII character on the current output device, or "GET" a character from the current input device. GET is of the form: GET (x) 39 where the argument x is a dummy variable which may be any value. GET (x) will be assigned the decimal value of the ASCII code of the next character input on the current input device. For example, jf the following statement appears in a program: Ie;, LET L=GETCX) and the next character input is an M, the variable L will be assigned the value 77(10). PUT is of the form: PUT (x) where the argument x represents the decimal value of the ASCII code of the character to be output. For example, the statement: 15 L=PUTCGETCV)) will wait for a character to be read from the current input device and then print it on the current output device. A statement such as: 30 PRINT PUTCQ) will print the character typed as well as the decimal value of the ASCII code for that character. To get 10 characters from a paper tape and print them on the line printer, a suitable program is: 100 110 120 130 140 150 LPT PTR FOR A=l TO 10 LET B=PUTCGET(0)) NEXT A END The GET(O) will contain the most recently obtained character which is then "PUT" to the line printer. The user should be careful to position the tape on the first character to be input. Otherwise 40 blank tape may be entered, resulting in spaces being printed as output. The PUT statement can also be used to format output. For example, to print a trig table on the line printer with a heading and 50 data lines per page, the line feed character (12(10)) can be "PUT" to the printer as follows: 100 LPT 110 GOSUB 1000 120 GOSUB 500 125 REM - SET UP TRIG TABLE 130 FOR J=0 TO 360 STEP .5 140 LET L=L+l 150 LET B=J/180*3.1~ 160 PRINT J~SIN(B)~COS(B)~TAN(B)~ATN(B) 165 REM - PRINT 50 ENTRIES IN TABLE 170 IF L=50 THEN GOSUB 500 180 NEXT J 1 90 G0 SUB 1 000 200 GOSUB 1000 210 STOP 500 REM PRINT HEADER 50 5 G0 S UB 1000 510 PRINT 520 PRINT 530 PRINT "ANGLE"~"SINE"~"COSINE"~"TANGENT"~"ARCTANGENT" 540 PRINT 550 RETURN 1000 REM PRINT FORM FEEDS TO ADVANCE PAPER 1005 X=PUT(12) 1010 L=0 1020 RETURN 1030 END The beginning of the line printer output from this program follows. The first page of the table continues through an angle of 24.5 degrees: then the header and the next 50 entries are printed on the next page, and so on until the values have been output for all angles through 360 degrees (in steps of .5). 41 ANGLE SINE. TANGt::~T COSI""~ A~CTANGEIIJT ~ 0 1 0 fl] ,5 1 1.5 2 2.5 3 3.5 8.722112E-rn .0174435& .026163&1:1 ."'3488181 .134359729 ,9Q99bc? .9Q98479 .999&'571 .9993915 .9990492 .998&309 .99813&7 .99756&5 .996921l:5 .9961986 .995'1009 .9945274 .9935784 .9925537 .9914535 8.722444E-03 .01744&21 .02611264 .0349121305 .043&3878 .0523811& .[£16113154 .06989125 .1217866164 • ~8 744408 .09623993 .1050506 .1138174 .1221211 .131585 8.722C1101E-03 .01744268 .02&1607 .03481,,74 .0435835 .05228564 .061397986 .0&966486 .07833935 .0871£HIJ20" .095651&& .10428&9 .1129"'67 .121512195 .1300944 ,9136318 .9100512 .4449743 .4554645 "54.5 5.5 b b.S 7 7,5 24 24.5 .0523094~ .06101763 .0b912111 .0784194 .1381111"7 .09579731 .1044751 .11314&1 .1218079 .1304604 The GET statement cannot be used to get binary characters. FNA FUNCTION In some programs it may be necessary to execute the same mathematical formula in several different places. 8K BASIC allows the programmer to define his own function in the BASIC language and then call this function in the same manner as the square root or a trig function is called. Only one such userdefined function may be included per program. The function is defined once at the beginning of the program before its first use, and consists of a DEF statement in combination with a threeletter function name, the first two letters of which must be FN. The format of the defining statement is as follows: (line number) DEF FNA(x)=formula(x) A may be any letter. The argument (x) has no significance; it is strictly a dummy variable, but must be the same on each side of the equal sign. The function itse,lf can be defined in terms of numbers, several variables, other functions, or mathematical expressions. For example: 10 DEF FNA(X)=Xt2+3*X+4 or 20 DEF FNC(X)=SQR(X+4)+1 42 The function: 10 DEF FNACS)=Sf2 will cause the later statement: 20 LET R=FNA(4)+1 to be evaluated as R== 17. The user-defined function can be a function of only one variable. USER-DEFINED FUNCTION - UUF A special user-coded function is available for the programmer who wishes to define an additional 8K BASIC function permanently or one which cannot be defined with one BASIC expression, as an FI'~A function must be. The UUF function routine is coded in PDP-8 assembly language, assembled with one of the available assemblers, and loaded as an overlay to 8K BASIC. While 8K BASIC is running, the special function can be used in a fashion analogous to the regular 8K BASIC functions. The usercoded function. if present, is referenced in the BASTC program as: UUF(n) where n can be any BASIC expression. The programmer who defines the UUF function should be familiar with the information on assembly language programming which is in Introduction to Progranlnling 1972 chapters 1-5, and the material on the Floating Point Package, chapter 8. He should also be familiar with the information on the assembler he intends to use by reading the appropriate manual. Coding Formats 8K BASIC uses a floating point package which has been modified to allow 27-bit, sign-magnitude mantissa floating point. In sign-magnitude convention the sign bit, rather than the mantissa, expresses the sign of the entire number. This format is described more fully below. All coding must be compatible with this format. The floating point instructions are discussed later in this manual. 43 Upon entrance to the UUF subroutine the value of the argument is in the F AC (floating accumulator). The value which is calculated for the function nlust be in the F AC in normalized form on exit. When floating point statements are to be included in the program, the start of a series of floating point instructions must be indicated by the instruction: FENTER immediately before the first floating point instructions. Each series of floating point instructions is terminated by the instruction: FEXIT immediately after the last floating point statement. There can be as many sections of floating point code as necessary in the program, but each must be delimited in this manner. Floating-Point Format The floating-point format used by 8K BASIC allocates three storage words to each number as follows: WORD 1 WORD 2 WORD 3 IIII IIIIIIIII IIIIIIIIIIIIIIIIIIIIIIIIII t . . - - - - - - - . J ) ' ' - - - - -_ _ _ _---........".- _ _ _ _ _ _ _ _----J EXPONENT MANTISSA SIGN BIT The F AC occupies five locations on page 0: Location Name Location Number Contents ACS ACE AC1 AC2 AC3 0024 0025 0020 0017 0016 Sign Exponent (200 8 biased) High-order word Mid-order word Low-order word The constant 200 8 is added to the exponent to make its range o to 377. All of BASIC's mathematical operations are in floating point format. Therefore, if any temporary storage locations are to be used, they will require three words, for example: 44 Addressing The floating point package uses only relative addressing. Therefore all statements that require an address specification must include one of the operators FWD or BKWD plus a reference to the current location. Such ,et.~~r~AS~:)~~<t.&~nerally of the form: ~.- ... -,"--C-:":. or r.:- instruction+FWD+LtEMP~ .. · ~di'( 'tti',Jr. -A.t.; .,,'\~ ~~ ".;:t, ~-.-- instruction+BKWD+.-LTEMP' .where L TEMP is the first of the three locations containing the number to be used. The operator FWD is used when the address of the location to be referenced is numerically greater than the address of the instruction; BKWD is used when the address of the location to be referenced is numerically less than the address of the instruction. The floating point interpreter uses the number of locations between the instruction and the data to locate the data. The location referenced must be within 200 8 locations of the instruction. The following two examples cause the contents of L TEMP to be added to the contents of the F AC, and the result left in the FAC: 00200 4210 F'AO+ F'W O+L TEMP-. 00210 0000 LTEMP 00211 0000 00212 0000 o o eJ or 00200 0000 LTE;'<1P 00201 0000 00202 0000 o o o 00210 4610 FAO+ 8:·{'.oJ 0+ • -L TE~P Floating-Point Instruction Set The legal instructions in the modified Floating-Point Package used by 8K BASIC are explained in Table 2 : 45 Table 2 Floating-Point Instructions· Instruction Value Meaning FST 2000 Store the contents of the floating accumulator (FAC). The contents of the FAC are not changed. FLD 3000 Load FAC with contents of relative address. FAD 4000 Add contents of relative address to FAC. FSB 5000 Subtract contents of relative address from FAC. FMP 6000 Multiply the contents of the FAC by the contents of the relative address. FDV 7000 Divide F AC by contents of relative address. FJMP 1000 Floating-point jump to relati ve address. FENTER 4435 Start floating-point code. FEXIT 0000 Exit floating-point code. Return to PDP-8 code. FWD 0200 Access a relative location in the forward direction. BKWD 0600 Access a relative location in the backward direction. FSNE 0040 Skip if FAC FSEQ 0050 Skip if FAC = 0 FSGE 0100 Skip if FAC ~ 0 FSLT 0110 Skip if FAC < 0 FSGT 0140 Skip if FAC > 0 FSLE 0150 Skip if FAC ~ 0 46 10 The following list contains floating-point instructions for indirect relative addressing. The indirect addressing is similar to the I construction used in regular PDP-8 assembly language coding. Floating-Point Instructions (Indirect Relative Addressing) Instruction Value Operation FSTI FLDI FADI FSBI FMPI FDVI FJMPI 2400 3400 4400 5400 6400 7400 1400 Store Load Add Subtract Multiply Divide Jump Writing the Program UUF must be made a defined function for 8K BASIC. This is done by inserting the starting address of the UUF subroutine in BASIC's table of subroutine addresses. The subroutine address must be placed in location 1156 of field O. If UUF is the first location of the subroutine, the following code is sufficient: *1156 UUF The UUF subroutine may be placed in the area of core normally occupied by the RIM and BIN loaders, location 7600-7777 of field O. To do this, the loaders are placed in field 1. The loading instructions for UUF are contained in the section called Loading and Operating Procedures. If mass storage devices are in use, they may destroy the data break locations on the last page of field O. If TC08 DECtape is used, locations 7752 and 7753 must be reserved. If an RF08 or DF32 disk is used, locations 7750 and 7751 must be reserved. There are three subroutines in 8K BASIC which are available to maintain a floating-point format acceptable to the modified floating-point package in 8K BASIC. These subroutines are described below. The listing of 8K BASIC is available from the Software Distribution Center for the programmer who wishes to call other subroutines in the compiler. 47 BEGFIX If a value is to be returned to the F AC as a result of the UUF function, that value must be in normalized floating point format in the FAC on exit from the subroutine. If floating point arithmetic is used throughout the user function, then the value in the F AC is in normalized floating point format and need not be converted. If fixed point arithmetic (single word) is used anywhere in the function, then the subroutine BEGFIX must be called to initialize the F AC before the fixed point number is placed in the F AC and subsequently converted to floating point (see ANORM below). After BEGFIX is called, the 12-bit number is stored by a simple DCA AC3 instruction and then ANORM is called. BEGFIX is located at 3762 and is called with a JMS instruction; on return from BEGFIX the AC is clear. ANORM If a fixed point value is placed in the F AC, ANORM may be called to normalize the FAC. After the fixed point value has been placed in AC3, ANORM may be called to supply the acceptable values for ACE, ACS, ACl, and AC2. ANORM is located at 4600; on return, the AC is clear. FIX When the value in the F AC must be made into an integer, FIX may be called to perfom that job. The 12-bit value of the F AC is left in AC3 and that value plus 1 is left in the AC. FIX is located,}'t 4744. Examples The following examples illustrate the method of writing and calling a UUF routine. Example 1: This UUF routine is an example of a fixed point calculation. The value of UUF(X) is 3X+2. 48 'AGE t IUUF(x)a3X.2 tENTER WITH X IN FAC IEX!T WITH UUF(X) IN FAC IUSE FIXED POINT ARITHMETIC - ! 1211211& 4744 37&2 121115& tl60~ 000121 FIELD 0 115& *1156 1211210~ 4215 4215 0'(,121' ~&2a 1217&10 07611 1217&12 07613 1217&ia 7326 07&15 07&1& 1217&11 07&20 1217&21 1210121121 1222 121 JMS I IFIX CLA DCA ANSWER JMS LOOP JMS LOOP 7200 3222 4215 07&1216 07&2;! *760121 UUF, t1&23 (37612l5 1217&23 1217624 1217f125 UUF 7b0~ 1&1210 07&121121 017&0\ 1217&1212 07&03 07&0U AC3-1& FIX-4744 BEGFIX=37&2 ANORM a ab012l IMAKE 12-BIT INTEGER. /5.e-tAC~a 15:+ ANs:/i 'D I~ULTrpL.V )( BY 3 JMS ~OOP JMS I IBEG CLA r:Ll.. CML RTL ISET AC-2 I~ETCH 3)( TAO ANSWER IRETURN 3)(.2 TO FAC DCA AC3 INORMALIZE JMS I INORM I--RETURN·· JMP I UUF 1222 3016 4625 5&1210 LOOP, 121 TAD ANSrlER IAOO At] TO ACCUMUL.ATEO SUM TAO AC3 DCA ANSwER J~4P I L.OOP 112116 3222 5&15 12101210 4744 3762 ANSWER, 0 IFJX, FIX IBEG, BEr.FIX 4Et00 I NORM, ANORM s The following BASIC program calls UUF(X) to print X and 3X+2 for a number of values of X: READY. 100 FOR X=-3 TO 3 STEP .5 110 PRI~T ~~ 120 .'l EXT X 130 END UUF(~) 49 RU:\1 -3 -2. 5 -2 11 11 g - 1. 5 8 5 5 2 2 5 5 - 1 -.5 "0 .5 1 1. 5 2 2. 5 3 8 3 11 READY. Example 2: This UUF routine is an example of a floating point calculation. Like example 1, this routine returns a value of UUF(X)=3X+2. PAGE 1 IUUF 0' a3lt+2 IENTER WITH X IN FAC IEltIT WIT~ UUF(X) IN FAC IUSE ~~ING ~~"~NT ARITHMETIC 4435 FENTElh4l£35 2000 0200 0000 FST;:a2000 &000 l£000 001~ 31&2 1J&00 ANO~M"Q&00 0000 FIELD 0 1156 *1156 01156 1&00 07&00 7&00 0000 l£435 0"~l2Il 1211&0? 1217603 01&0a 1211605 07&0b FWO-200 FEXIT=0000 FMPn&000 FAOa4000 AC3 8 16 BEGFIX:;3762 221& 0000 132'S l£ii4 l£435 CH~07 6il1 07610 2210 07& 11 1217&12 0210121 73i& 1217&13 4224 UUF o FENTER FST+FWO+X-. ISTORE X FROM FAC INTO Loe, x FEXIT .~;: ClA Cll CMl lAC RAl ISET AC-3 J~S FLOAT IGET A FLOATING POINT 3 IN THE FAC FENTER FMP+FWO+X-. IMULTIPLY X BY J FST+FWO+X-. ISAVE IT FOR lATER FEXIT CLA CLL C~L RTl IGET A 2 IN THE FAC JMS FLOAT 50 01&14 01&15 07&1& 07fl17 4435 4203 0e'00 5f>00 t'l1b20 07&i?1 )( , 010'0 011,22 0000 0000 0000 07&23 121000 TEMP, o - 07&24 0et00 3223 4633 1223 301& 4&34 5&24 FLOAT, 37&2 4600 IBEG, INOIlM, 01~25 1211&2& 01&21 07&30 01&31 01632 07b33 211611.1 FENTEQ FAD.FWO.)(-, FE)(IT JMP I UUF IAOD 2 TO 3)( ILEAVE RESULT IN FAC I--RETURN-· o OCA TEMP JMS I IBEG TAD TEMP DCA ACl JMS I INORM JMP I FLOAT ISTORE CONSTANT TEMPORARILY IPREPARE FAC TO RECEIVE VALUE IPUT CONSTANT IN FAt INORMALIZE IT I·-RETURN .. • BEGFI)( ANORM IUUF on -])(.2 PALl-V? 5/25/72 PAGE t-l s The following BASIC program"calls UUF(X) to print X and 3X+2 for a number of values of X. The results differ from those in example 1 because of the capability of floating point arithmetic to handle fractions. READY. 100 FOR X=-3 TO 3 STEP • 5 110 PRINT UUFC X) 120 \JEXT X 130 END x, RU\I -3 -2.5 -2 - 1. 5 - 1 -.5 0 •5 1 -7 - 5. 5 -4 - 2.5 - 1 t. 5 •5 2 3.5 5 6.5 2 2.5 9.5 3 11 8 READY. 51 Example 3: This UUF routine computes the square of the argument in floating point format. IUUF(X)-X·2 IENTER wITH X IN 'AC IExIT WITH UUFeW) IN FAC IUSE FLOATING POINT ARITHMETIC 4435 20210 21200 FENTER-4435 FS1-2000 F"'0-200 602121 21000 FMP-&2100 FExIT-0000 21000 FIELD 0 115& *115& UUF 0115& 7700 01100 011211 011212 01103 21000 "''''35 "FENTER FST.F",O.X-, 6203 01104 01105 21000 5100 FMP.FWO.X., FEXIT ISTORE ARGUMENT IN X IMULTIPlV FAC 8V ~OC. IRESULT IS IN FAC JMP I UUF ltot-RETURN·· 01106 0000 0000 0000 7100 01701 011UI *1100 UlJF, 22214 x, x (X-X) 0'0,0 The following BASIC program uses the above UUF to produce a table of squares and square roots: READY. 100 FOR A=1 TO 10 STEP 1 110 PRI NT AI UUF( A) I SQR( A) 120\J EXT A 130 EN 0 RU:\J 1 2 3 4 5 6 1 8 9 10 4 9 16 25 36 49 64 81 100 1.414214 1.132051 2 2.236068 2.44949 2.645151 2.623427 3 3.162218 READY. 52 EDITING AND CONTROL COMMANDS Errors made while typing at the console keyboard are easily corrected. BASIC provides special commands to facilitate the editing procedure. Erasing Characters and Lines SHIFT /0, RUBOUTS, NO RUB OUTS There are two methods available for erasing a character or series of characters one at a time. Typing a SHIFT / O' causes the deletion of the last character typed, and echoes as a back arrow ( ~) on the Teletype. One character is deleted each time the key is typed. The RUB OUT key may also be used for deletion of characters one at a time providing the command: RUBOUTS has been typed on the keyboard before the editing is done. This command enables the RUBOUT key to be used. If the user has neglected to type this command, he may not use the RUBOUT key. A later command of: NO RUBOUTS disables the key for use. (This is desirable when programs created on other systems which use rubouts as null characters are to be read into core. See the section entitled PTP AND LPT under Listing and Punching a Program.) For example: The user types a B instead of T and immediately notices the mistake. He may type SHIFT /0 (or RUBOUT key, if enabled) once to delete the B, and as many times more as characters, including spaces, are to be deleted. After the correction is made, he may continue typing the line. The typed line enters the computer only when the RETURN key is pressed. Before that time any number of corrections can be made to the line. 53 When the RETURN key is typed, the line is input as: Notice that spaces, as well as printing characters, may be erased. The user may erase an entire line (provided the RETURN key has not been typed) by typing the ALTMODE key (ESCAPE key on some keyboards). BASIC echos back: DELETED at the end of the line to indicate that the line has been removed. The user continues as though it were a new line. If the RETURN key has already been typed, the user may still correct the line by simply typing the line number and retyping the line correctly. He may delete the line by typing the RETURN key immediately after the line number, thus removing both the line number and line from his program. If the line number of a line not needing correction is accidentally typed, the SHIFTjO or RUB OUT key may be used to delete the number(s); the user may then type in the correct numbers. Assume the line: 10 IF A>5 GO TO 230 is correct. The programmer intends to insert a line 15, but instead types: 10 LET He notices the mistake and makes the correction as follows: 10 LET~~~~~5 LET X=X-3 Line 10 remains unchanged, and line 15 is entered. Following an attempt to run a program, error messages may be 54 output on the Teletype indicating illegal characters or formats, or other user errors in the program. Most errors can be corrected by typing the line number (s ) and the correction (.S ) and then rerunning the program. As many changes or corrections as desired may be made before runs. Listing and Punching a Program LIST An indirect program or data can be listed on the active output device by typing the command: LIST followed by the RETURN key. The entire program (or data) will be listed. A part of a program may be listed by typing LIST followed by a line number. This causes that line and all following lines in the program to be listed. For example: LIST 100 will list line 100 and all remaining lines in the program. PTP AND LPT The LIST command may be issued in conjunction with the LPT or PTP commands as follows: PTP LIST LPT LIST This will list the current program on the high-speed paper tape punch or line printer respectively. Control is reset to the Teletype after the listing is completed. Occasionally, when 8K BASIC is reading in a program from the low-speed reader, it may drop a character since the Teletype buffer cannot accept input at a prolonged fast rate. To eliminate this possibility, use LIST as follows when punching out paper tapes: 55 PTP LIST* This inserts null characters after carriage returns and is recommended when punching any tapes that will later be read in from the low-speed paper tape reader. (8K BASIC does not use rubouts as null characters.) Reading a Program PTR The PTR command can be issued to read in a paper tape from the high-speed reader. This mode is particularly useful for reading in a user-coded "load and go" BASIC program. The tape should be positioned in the reader before the command is issued; if not, or if the reader runs out of tape, BASIC prints; TTY on the Teletype to indicate that there is no more input from the high-speed reader, and that it is waiting for input from the Teletype. The user may cause tapes to be read in from the low-speed reader by simply placing the tape over the sprocket wheel and setting the reader to START. Running a Program RUN After a BASIC program has been typed and is in core, it is ready to be run. This is accomplished by simply typing the command: RUN followed by the RETURN key. The program will begin execution. If errors are encountered, appropriate error messages will be typed on the keyboard; otherwise, the program will run to completion, printing whatever output was requested. When the END statement is reached, BASIC stops execution and prints: READY. 56 PTP AND LPT Either the high-speed paper tape punch or LP08 line printer, if available, can be used in conjunction with the RUN command. After the command is issued, all output during program execution is diverted from the Teletype to the specified. device. The command sequence is: PTP LPT RUN RUN This procedure eliminates the need to insert the PTP (or LPT) statement within the program. Output returns to the Teletype after execution. Stopping a Run CTRLjC To stop a program during execution or to return to BASIC at any time, type a CTRL/C (accomplished by typing the CTRL key and the C simultaneously). This causes the current operation to be aborted immediately, and the message: STOP. READY. to be printed indicating that an 8K BASIC command can now be issued. CTRL/O The command CTRLjO (caused by typing the CTRL and 0 keys down simultaneously) is used to stop output temporarily. The program will continue to execute but output will not be printed on any output device unless an error occurs or unless BASIC is waiting for a command or for data from an input statement. In the latter case, the Teletype is the expected input device. This feature is particularly useful for programs that print lengthy introductions and then request a user-specified parameter. Typing CTRL/O after the program is started will cause BASIC to bypass printing the introduction and wait until the parameter is specified, thereby saving the time required to print the message. A second CTRLj 0 will resume output. 57 NOTE For most programs that do not wait for input from the Teletype, processing of the program after an initial CTRLjO will be completed before a second CTRL/O can be typed. Thus, it is very possible for no output to be printed rather than the anticipated partial output. Erasing a Program in Core SCR The command: SCRATCH or SCR is provided to allow the programmer to clear his storage area, deleting any commands, or a program which may have been previously entered, and leaving a clean area in which to work. If the storage area is not cleared before entering a new program, lines from previous programs may be executed along with the new program, causing errors or misinformation. The SCRATCH command eliminates all old statements and numbers and should be used before any tapes are read into core, or new programs created. LOADING AND OPERATING PROCEDURES BASIC Compiler The following procedure may be used to load in the 8K BASIC binary tape. 1. Toggle the RIM Loader into field 0 and, using the appro- priate reader, read the Binary Loader into field O. (Refer to Appendix A for details.) 8K BASIC will not use locations 7600 to 7777, thereby preserving the Binary Loader if it is present. 2. Place the 8K BASIC binary tape in the appropriate reader; set switches 6-8 == 0, and 9-11 == 0; press EXTD ADDRess LOAD. 3. Set the Switch Register == 7777 and press ADDRess LOAD. 58 4. If using high-speed reader, set the Switch Register = 3777 and press CLEAR and CONTinue; otherwise, simply press CLEAR and CONTinue. S. After the tape has read in, set the S~tch Register = 1000. 6. Press ADDRess LOAD, and CLEAR and CONTinue. BASIC responds by typing READY. 7. BASIC programs on paper tapes may be read in using the PTR command explained earlier, or created on-line. User- Defined Function The following procedure may be used to load in a user-defined function. 1. Load the Binary Loader into field 1. 2. Load BASIC into field O. 3. Load the user-function (binary paper tape overlay) into field O~·~/i~.~, ~ r t'" .,{ ~ .,"/ .~. 4. Set Switch Register = 1000; press ADDRess LOAD and START. '~ "'.:"''" ,';. L \ l' Note that the Binary Loader is destroyed. To reload BASIC, steps 1 through 6 must be repeated. 8K BASIC ERROR MESSAGES The computer checks all commands before executing them. If for some reason it cannot execute the command, it indicates this by typing one of the error messages. The number of the line in which the error was found is also typed out. The form is: ERROR MESSAGE AT LINE XXXX Table 3 lists the errors 8K BASIC checks for and reports before execution: Table 3 8K BASIC Error Messages Message Meaning ARGUMENT ERROR A function has been given an illegal argument; for example: SQRC-l) DATA ERROR There are no more items in the data list. FOR ERROR FOR loops are nested too deeply. 59 FUNCTION ERROR The user has attempted to call a function which has not been defined. GOSUB ERROR Subroutines are nested too deeply. LINE NO ERROR A GOTO, GOSUB, or IF references a nonexistent line. NEXT ERROR FOR and NEXT statements are not properly paired. RETURN ERROR RETURN statement issued when not under control of a GOSUB. SUBSCRIPT ERROR A subscript has been used which is outside the bounds defined in the DIM statement. SYNTAX ERROR The command does not correspond to the language syntax. Common examples of syntax errors are misspelled commands, unmatched parentheses, and other typographical errors. Reference to an undefined UUF will also produce this diagnostic. TOO-BIG ERROR The combination of program size and number of variables exceeds the capacity of the computer. Reducing one or the other may help. If the program has undergone extensive revision, punching it out, typing SCRATCH and reloading should be tried. The following programming errors are not reported by 8K BASIC, but instead are used in the computation as specified. They are included here for the programmer's reference. 1. Attempting to use a number in a computation which is too large for BASIC to handle will produce a result which is meaningless. 2. Attempting to use a number in a computation which is too small for BASIC to handle will result in the value zero being used instead. 3. Attempting to divide by zero will produce a result which is meaningless. 60 BASIC SYMBOL TABLE Table 4 lists 8K BASIC's symbols and their values. This information IS useful when writing user-coded (machine language) functions. Table 4 A3CJEr A3DGET A30P ASS AC1 A:2 A:3 ACCEPT A:E ACN AC:OUNT ACS A::JA1 AJA2 AJA3 AJACPT AJ8 AJC AJGCOR AGCl AJCUNT AOCX AJLJRES AJLE AJL"1 AJRB Al)RS AJSE AJSK AJST AGET ALl ALG\JL.P ALL3 ALlOC AI.. Ti"IOD AMATCH A\jOR~ AP0T A?0 T1 APUT2 ARl 1750 BARROW e0~6 BCDE~G ~325 BCKWOS BEGFIX SIDLE BKWD BREAK BSKIP BUSY CARRET CCINTK CCXRA CDEVCO CDINP CHECKW CHKFIT CLAB CLBA CLC CLCA CLEAR CL.EARV CL.EN CLKSTS CL.OCKI CL.OE CLRCNT CL.S CL.SA CL.SK CL.T(MP CltE CNCLR CNTLCF' CNTLCR Ct'-lTL2 CODELO 6425 2020 0017 ~016 7473 0025 4417 e~22 0024 Ck'J25 e026 e'''27 e0f2l7 7477 7477 012164 6530 ~01" e012 e067 6536 6531 6533 6537 6535 6534 6532 0301 4654 4466 3146 1461 2663 6506 46021 2'263 0.023 0024 44~2 A~GERR 7363 ARRlOC ATE"1P ATEMP2 ArlINE ATN ATNSI::; AT~~ L0 i'J AT\I"JOT AUTEHP e!323 0324 6451 6200 6265 6220 6237 ~003 ~063 COLU~N COMMON COMPAR CONST COS COWT COWTFP COL-HLP COWTO COWTW CRINTX CRL.r CRLrPR CTl CT2 8K BASIC Symbol Table CT3 CVTLOO DATAER DBAD DBBAD DBGOT DBISRT 2666 1757 4502 3762 6713 f2l60~ 6522 2730 6737 DB~IT DBPUT DDLAST DECEXP DECFRA DEEPER DEF' DELAY DELETE 27"'~ 7465 7:542 ~00~ 7445 2346 640~ 6133 6136 7477 6137 7432 2462 6134 012103 0175 6132 DE~OUT DEVCOM DEVCON DICD DIGIN DIGIT DIGLUP DILC DILE OILX DILY DIM DIMF'LA OINP 036~ 7477 6135 6131 0~11 DIRE 613J 0143 67021 OISAUT DISB DIS0 DIVL.P DIVXTE OIXY DLAST DOAO DOADLP DOITNO DOTtER DPF"L.AG DCINTX DSCREW DVL,OOP EDIT END ENOLIN ENONUM ENDPDl EOF'AD 667~ 0133 0004 0126 340~ 2136 1367 5616 7326 7343 7331 734~ 7344 3076 6531 374;:' 0016 f2l2J15 61 ~IiH4 50~4 1667 1513 '5~2 1420 1547 7526 1556 7512 ~043 33~6 0526 1516 1463 6501 0142 7175 71'6 6051 3224 32~4 6557 6050 6056 621'33 6054 6472 0~:54 7511 62157 012115 0136 621'2 ~705 33&4 6055 1511 ~362 ~366 1247 13'1 33&5 31'0 03'5 5245 2405 2'~7 7643 3331 111.'J4 45~6 EPTR ERROR EVAL EVALGO EX£CUT ExIT EXP ExPGOO EXPLON EXPOK F'AD F'ADEXT tAD I F'ATNAX F'ATNC F'ATNC1 F'ATNC2 F"ATNC3 F"ATNC4 F'ATNC5 rATNC6 F'ATNC7 F'ATNCS rATNC9 F'ATNCH rATNCJ F'ATNSX F'ATNT F"ATNTT F'CNTLC F"CNTLO F'DIGIT F"DV rDVI F'ENTER F'EXIT F'EXPC1 F'EXPC2 F'EXPC3 F"E)(PC4 F'EXPC5 F'E)CPC6 F'E)(PF' F'EXPI F'E)CPU F'INDIT F'INDLU F'IX F'IXEXI F'IXITU rl)CLIN F'IXLUP ~056 4142 10214 10217 0213 24212 60211lJ 5242 5'64 5265 40210 1314 4400 6273 6337 63214 63217 6312 6315 63221 6323 6326 6331 6334 6342 6345 62'12 6276 6301 6665 6103 3360 700(21 7400 4435 21000 6012 62115 6Hl(21 61213 61216 611i 6067 6061 6064 rlJ5'7 1lJ5&5 4144 41'3 5200 2113 4"0 FIXU~ F"JMP FJMPI FJUMP FLO F"lO! FLOGel FLOGC2 F"LOGC3 FLOGC4 FMP F'~PI F'1T1 FMT2 n1T3 FMTENF FN F~E~R FNEXIT FOR FORCT F'ORDON FORERR F'~RLIM F"ORLIS F'ORSTE FORVAR F'OUND F'OURLF FPADo FPADoR F'POIV FPDOIT FPFlAG FPGOTO FPJMP FPJUMP FPLAC FPLOOP FPMUL FPNOAD FPOPER F'PPGZ! F"PSKIP F'PSTO FPSUB FPT FPTEMP F'PTR F'PlDIV F'RNDX FRSTNE 5146 10210 14eJ0 113" 3212121 34121" 6175 6156 6161 6164 6"0121 64021 5125 5"53 513" 5123 5453 0352 12fZ1" 0413 "12163 "663 fZl501 0721 7705 0724 0452 ~575 3557 4456 4304 4667 4231 0156 4273 4317 4274 4351 4202 453k'l 42721 4305 4227 4314 4322 4453 42021 4576 0057 4736 5404 2155 FSB FSBI FSEQ FSGE FSGT FSHIFT FSINll21 FSINC1 F'SINC3 F'SINC4 F'SINC5 FSINC6 FSINC7 FSINM4 FSINOK FSINr FSINt~ F'SlE F'SlT FSNE FSQRX FST FSTI FTANTl F'TANT2 FUNTAB FUPRC1 FWD FXXPFX GALT GDIM2 GET GETADD GETARY GET8LK GETCH GETJ GETLIN GETLRE GETOPR GETVAR ·GETWD GLOOP GOBOTH GOlIST GOSUS GOTEMP GOTO GOTOPR GOTSS GOTSTE GOUT 5~~~ GP'iP 540~ G~B G~OElA ~1215~ GSBEND GSBPTR GSS1 .GSS2 GTBKLP GTEMP 0100 fZl14~ 7443 5641 5713 5716 5721 5124 5727 5732 5735 5657 57a5 5110 fZl150 al1fZ1 12104121 54fZ17 2fZ1a21 24fZ10 5677 571212 1131 5162 fZl2fZ1fZ1 6B23 7247 1564 IlJB"l GW~ERE HF'OUND HIGHWD HL.OOP HPTR H~CHAR H~LOP HRMES IAMLES IOL.EAC ICL.ECo IOLECI IOL.ElK IOLEPC IF' IGNORE I I XR P1MED IN iNCHAR INCEV INOEXl INOEX2 INLCTM INL.OOP INI.UPF INODUN INOPPP INOTTT INPLUP INPPTR INPUT INSERT INSRT5 INT INTAC INTCDF INTCIF INTECD INTEMP INTER INTEXT INTL 1421~ 7462 1674 72fZ11 1770 26"3 26Z0 112115 0311 0177 2711 1lJ532 1725 05"5 0Z53 fZl517 12"2 1174 "634 7251 62 2112160 1224 1222 1155 0165 1562 1'63 11i2J 12!!J.4 12'121 1321 4333 2722 IUI61 12'6 13m2 1323 21'6 6732 6725 6126 6731 6733 121315 2115 7414 24'4 34!1 '2~5 18127 12112113 ml2l!. 412165 fZl5'2 rll432 671QJ 6641 6645 4034 412163 4mQl7 212132 2121!2J 6434 6134 61'21 6711 6162 67!6 66~QJ 6744 6735 INTOU INWDTM IPNOPE IPOINT ISOEF'2 ISOIG ISOIM %S[T IS1T ISITOF' ISITF'U ISITlI ISLIT ISSOME ISUMIN ITSDEF' ITSDP ITSE ITSOP ITSF JBPENT JOIGIT JISOIG JMATCH JPUTCH JTXXIT JuSTa JUSTrllF' JUSTI!P JUST1 JUST2 KEYWD L4LUP LBEGIN LOF' LET I.EToO LETTER LF'XLUP L~.LF' LIMIT L.INBUF' LINENO LINF'IX LIST LIST2 LIST3 LIST4 LIST' LISTAL LISTLU L.ISTSO 6765 42164 42124 12134 3512 6532 1473 14137 4566 1215,a l11a 41134 4133 1644 112113 3514 3256 3263 122121 33mB 37m7 3124 3367 2;66 121777 3123 31,a 316a 3163 3145 .3147 21231 3664 '563 6662 "312 1212185 3446 2333 3B;" 12121213 '512 1210'2 2331 36~QJ 36421 36'5 366136;6 3616 3621 3617 L.ITRAL L.LLJMP L.L.LJMS L.L.LUUU L.LS L.NOEND LOADED L.OCCTR LOCTEM L.OCTMP L.OG L.OGACE L.OGF"WD L.OGOKW L.OWL.OC L.PTOUT L.SF" L.STL.OC L.UP L.UPF" MACHIN MAYi!ER MENDL.I MENOF'D MEVAL. MEVAL.G MGOL.IS MGSBEN MINUS ML.BEGI ML.ENO ML.INBU MNSONE MOREOI MOREIN MORERO MOVE MOVLUP MPy MPYLUP MTXXIT MULCL.R MULEXP MUL.XTE MU5TBE NOELAY NEwCHA NEWLIN NExT NEXT[R NEXTVA NINTEC 3131 7457 7446 7141lJ 6666 363121 4127 21045 12J671 1673 6114 617" 6167 6172 2171 7163 6661 216121 34215 21426 1lJ01210 4612 12J041 2363 7415 7431 121720 fl)525 1316 0173 121174 004f1) 121736 64711 4'UJfI) 1621 2f1)12 21172 5321 4552 32l2Jl 4571 3346 3363 4570 7421 2615 2611 12J6211lJ 12J673 1631 1457 NOBUMP NOCOMM NOINT NON8LN NONlER NOPARE NOPCR NORLFT NORMED NORMIT NORUBO NOSSl NOSS2 NOT NOTBAO NOT8IG NOTCR NOTF"RS NOTHER NOTKWO NOTNOW NOTSGN NOTTXT NOTVAR NOTX11lJ NPSPER NSYMTA NULCMO NULJOB NULL.OF' NUM8UF" o lQJfI) 121 011 0110 012 0122 013 0132 0137 014 0140A 01418 0143 017 01742 0175 0177 01774 02 02fJfI) 02140. 02162 0QJ11lJ 0212 0QJIlI? 0215 023 1366 0233 3"2 QJQJ~h 024" 02'3 51'1lJ 51tl 02'5 51~6 02'6A 02'68 65" 0111 026" 33'21 02' 03QJ5 51'2 032 3121 . 27.7 036 03'378 27'3 03'54 1162 03'155 12'3 03'7 01lJ'1 04 0160 041 21'0 o 4f1)fI) 1 7525 04114 1163 042 31~6 0421UJ 311115 04213 1164 054f1)fI) 5347 06211A 66!5 062118 71lJ1lI5 06212 67'5 01 01'2 070 67'4 07111lJ 12'2 011l1QJfI)A 2'611 O'lIlf1)B 34'" 0'11110C ;"!l6 071177 12" 01'2f1) 51!13 0'1'45 4"7 64!16 0"71 07'77 4"7 01'778 0'61f1) 43 .. 5 01611 '2611 0'1'1lJ3 21'4 01611 5:5" 07612 '262 01641A 187., 07'411B 2763 076411C '263 01673 33{6 017 211'11 01716A 6'.4 4633 12J335 12J134 311121 51lJ16 lQJ35 2216 6423 5221lJ 5212J7 5574 146121 1453 3427 2127 46221 3"23 21lJ61 12J435 21313 2f1)IlJQJ 3311J1 2236 11"5 5236 7555 IlJfI)I2J6 7454 7415 743121 5335 355121 05"4 2361 0165 2771 1'67 7265 7261 236" 12J775 2772 7266 5147 3315 7267 211121 3376 1162 21155 3373 5344 ", .. 63 0111lJ6C 07115 0"25A 01'2'8 01'37 0114QJ 01141 01'43 07145 07146 07153 0;162 0"63A 07'638 07'64A 07'64B 01'64C 071640 07'66 01'71lJ 07171 07172 07'73 07'174 01175 07'76 07'177 OAOO OB~IGH OBL.OW oeop ace OCML.IM oeOR OCOUNT ootv OF'LAG OF"LOW OJUMP OL.OOP ONE ONEOIM ONESS ONLY1 00'16111 00'736 opt OP2 OP3 OPOONE OPE OPERAN 34;3 2"5 311821 33;1 3122 180;4 31'5 4'43 QJ162 1264 :!lQJ4 2327 IIJt;4 3uii 1214 3112 3314 67;7 51'4 1IJ0;5 51;' 51'7 53.6 1566 6;;6 3312 71i~ .. 435 11;7 1165 71111 52i5 7115 ,113 71142 1132 11ill '1~5 12 6 1111'6 11!h. 1116 .. 11'6 33i2 '4'2 2326 IIIi3 11112 11121 12i3 11131 111'3 OPNUL OPOINT OPOTAB OPRST OPS OPUTC OTEMP OTHER OTSTl OUTD2 OUTDEL OUTDEV OUTIT OUTNUM OV PAeN PALl PANORM PAR'l PAAGER PASSCR PASSUM PBEGF'I PBIDL.E PBOMB PBUSY PCCUNT PCHKF'I PCOMMO PCOWT PDEVCO POL POLIST PEOIT PERMSY PERROR PEVAL. PEVALG PEXECU PEXP PF"INOI PF'IX PF"NERR PFPLOO PGET AD. PGETeL PGETCH PGETLI PGETL,R PGETOP PGETVA PGOLIS 1067 7~65 7073 7155 0026 7141 1271 3010 1112 1211'30 7146 121131 7QJ43 5QJI0 I2IQJ12 4742 "'1'0 121146 121147 I2IQJ47 0472 744'" 1716 7161 0367 7157 0744 0163 3357 0141 7442 I2IQJ36 7644 0120 1022 0QJ77 011211 2240 0103 5776 121672 01"6 5546 4575 0102 0115 0QJ32 0124 3QJ22 0111 0113 0164. PGOTOP PHRCHA PIGNOR PINCHA PINT PISITL PJSET PLBEGI PLETDO PLETTE PLIMIT PL.INBU PLINFI PL.IST PL.ITRA PL.OG PLoOT PL.OTB PLUS PMEVAL. PMPY PNBF"6 PNOCR PNONBL. PNOTNO PNUMBU POADD POF"LAG POP POP3 POPERA POTHER POUTIT POUTNU PPACl PPAC2 PPAC3 PPACE PPACS PPASSC PPOLIS PPERMS PPF"LOO PPF"ORI. PPINT PPOP PPRINR PPRINT PPRINU PPUSH PPUTCH PPXRA PRENT PAESET PRINBL. PRINCO PAINHA PRINQU PRINRE PRINSE PRINT PRINTC PRINTG PAINTH PRINTX PAINUM PRINVA PAL.OOP PRSUBR PRTEMP PATXRE PSON PSI<IPI PSL.OOP PSP'ACE PSTICK PSTOVA PS)(ERR PSYMTA PTABDE PTASF"L PTASL.E PT£N PTEXT PTI'OUT PTAIN PTUBIG PUSERF' PUSH PUTCOF" PUTCH PUTCIN PUTER PUTJ PUTL.CC PUTI.P PUTXRA PxrORL PXI.INB PXXCRL PXXEOF PXXEXI PXXL,IT PXXTHE 0Ul7 6140 0471 6141 5676 121175 2461 0172 121204 3UJ3 2561 121037 121161 2563 3377 5175 141210 1514 1312 1441 5160 5161 0157 0122 2566 0144 0157 6742 3551 4434 3127 2776 6743 0117 0042 0043 12'044 12'045 121046 01121 0125 2565 4141 1760 6160 1105 2241 0114 1123 011214 1133 716~ 64 23i6 013' 22'7 2303 2261 22~5 2242 23J2 ~1 3 2217 2216 22!2 3712 37.' 36'3 37ii 3724 IUJ42 37t2 '615 i6!7 0116 15., 01tl 01i2 0liu, 0115 5511 55'1 27'7 12114' 0"'6 7164 71'2 31121 5'45 2364 '1137 1741 '''23 '11'0 1'61 21'2 '1107 17'6 21"6 37~6 312' 2'64 3126 31S1 2'62 PieRDO ,5.' QBIDL.E ;2" QE"ROR 41;i QHACHA 71'6 RANDAE ·14;i R8SWCH 1135 REAO 1623 R[AOL.O 1'.6 READY '5i5 REAL.Tl 74;3 REJECT 74'3 REL.ATE 13'2 REMPAC 3",43 RESETl 7116 RESET2 71.i REITOR 3773 RETNEA 1113 RETURN RHAL.r 311'. RMLErT 6413 53;3 RNO RNOJMP 53;'" RTERR 73'3 RuBO 5573 RUN 2"2 RUN2IN 25'3 RUN2LU 25{4 RUN2NO 2537 RUNIN 2503 RUNLUP 2.65 RUNNOT 2';' SC~MOR 1"7 seRATC 24.1 SEARCH 1"1 S[TCLO 74'3 SETRAT 7.;3 S[TSGN 4'12 SETUP '.11 SGN 0'26 SIMPLY 3"6 SIN "24 SINCHA 71'2 SJUMP 12.11 SKIPIT 14'7 SLASH 1332 SLOOP 27.7 SLSHTM 1331 SNUMrL. 11164 SPACER 13;1 SPECIN 12114m SPL.ErT 11.4 SQ[XIT '451 1'" SQLOOP SQR SSERR SSF"IX SSONE SSTWO STAR START STICI(I STOP STOVAR SueR A SXERR TA8 TABOES TABOO TABF"LG TABOI( TABT~R TAN TB£G,.1 TEN THESI(I THISTX TIM TIMl TIM2 T~p TOOLON TPRINT TRAL.UP TRANSF" TRYAGI TRYSTE TST TSTF"X TSTP TTYIN TTYOUT TU81G TWIOTH TWOSS TXTPAK Ull21 UlllJl2I U11 U177 U1P U2P U411217 U5a11lJ U7 5435 5412 1570 4775 0344 0345 1327 1000 6430 2570 0341 2161 6441 5547 6367 6350 2345 6360 2362 5600 5572 0000 1353 3107 7477 0Q104 00135 02131 5162 63721 2105 2103 5133 0626 7421 7417 7431 7173 1165 2657 2357 11lJ77 32146 212136 02113 01lJ47 02111 1503 1504 021221 121 IlJ 34 02133 U7760 U7767 U7775 U7777 UABAD UAC1 UAC2 UAC3 UACCPT UA,DCB UADCIN UADCMY UADCN UCLC UCLOQP UCLS ueEVCO UDOAD UOOPER UF"F"UD UF'JMP UGETWO UGH1 uIEXT UIEXT2 UIEXT3 UIEXT4 UlNAe UJMP UJMS UMEVAI. UMOPER UNOERF' UPAGET UPARR2 UPARRO UPARRX UPCOMe UPF'IX UPF'UN UPJMP UREAL UREJT uSE USERF"N USETC USETF" USETM USETR USI<IPI UTEMP UTIM UUAC1 UUAC2 UUAC3 UUOATA UUOEVC UUrUOG UUJMP UUJMS UUMEVA UUNOAD UUftF"IX UUSETF' UUUJMP UUUJMS UUULLL UVP UWAIT UWAITC VA" VARTEM 0052 0Q135 0Q121 0Q150 062" 02137 0040 0Q141 ",453 0600 0613 0615 0622 0345 0217 0340 0Q156 0051 1363 121756 0757 02157 3562 0234 0243 0245 0260 1lJ631 VSC~lN VSCHLU VSCHNO WAIT WAITC WOTEMP WORD XEXECU XCISIT XCMUST xISIT XMUST XRESTA XXABS xxACPT XXA08 XXAOC XXATN XXBSLS XXCL.C XXCLEA XXCL.OS XXCLS X)(COMM xxeos XXCRL.F' XXOATA XXOEF XXOEL.A XXDIM XXEG xxEL. 02154 IlJI55 1lJ131 1321 4645 0653 4365 6457 5740 1lJ731 1132 0747 21136 0460 0456 7446 1620 1lJ411 0550 1lJ416 040a ,.61 0153 a'41 65 06'4 13661 13666 "'67 011' 131~' O122 01i7 06'3 146O 06'7 00~0 0130 187tl 1lJ3~2 "12 0437 tlJ4~12I 0343 0"3 35t4 34'5 3,tllJ '4'3 "'3 iI" 01'1lJ 1lJ412 41" '34' 4"3 '312 1113 ;1S4 '466 7223 '1'6 'ltllJ 72321 '221lJ 7486 '.'6 ;215 "'2 71{2 '226 '3.3 '333 '412 '3~6 '1.6 'Itl XxENO XXEOF' XXEQ XXEXIT XXEXP XX'INI XXF'N XxF'OR XX~E XXGET XXGOSU XXGOTO XX~T XXIF" XXINPU XXINT XXL.BFU XXI.E XXI.ET XXI.IS XXI.IST XXI.ITI XXL.OG XXLPT XXI.T )(XMINU XXNE XXNEXT XXNRUB XXOPEN xxflLOT XXflLUS XxflRIN XX'TP XXftTR xxPUT XXR8RA XX~EAD )(X~EAI. XXfIt·[JT XXfltEM XXfltETR XXfltNO XXfltSTO XXfltUB XXfltUN XXICR XxSEMI XXIETC XX.ETR XXIGN XxllN 7Z32 7'82 7Q1;4 7,jS ;126 "14 71187 72S' 7Q1'QI 71;3 7241 72.6 '0.1lJ 7Z.IlJ 72'3 7142 '118' 7Q1S' 72'1lJ 71.2 '1;6 "i6 ;123 13'1 ,QI;, 712' ;143 72;. 73'7 1113 ;~i2 'li3 7311lJ 13'4 13'7 11i3 71'i ;337 1~i6 7~;3 73i7 73ii, 71.' 73i2 13;2 7165 ;l'i ''''4 , •• 3 ;.35 ;137 ;1irl XXSL.AS XXSQR XXSTAR XX5TE:P XXSTOP XX,TA8 XXTAN XX TEXT XXTHEN XXTIME XXTO XXTTV XXTTVI XXTTVO XXUCOM XXUNAR XXUPAR XXuSE XXUUP' XXWA1T YYWA1T i!ERDON i!ERO i!F'IXEX i!i!ADB i!i!AOC 7131 7131 7127 7176 7312 7217 7115 7511 72'3 7214 7172 7211 7347 73'4 7462 7513 7133 7416 7212 7452 7456 5144 rlJ152 4767 0775 rlJ770 66 STATEMENT AND COMMAND SUMMARIES Summaries of the editing and program control commands available in 8K BASIC are presented below. Edit and Control Commands Command Abbreviation Action CTRL/C Stops a running program. and returns to the editing phase of BASIC. CTRL/O Stops output of a running BASIC program. Remains in this state until BASIC requests INPUT, an error occurs, or until another CTRL/O is typed. LIST LIS Lists the entire program in core. LIS n Lists line n through end of program. NO RUBOUTS Disables the RUBOUT key. RUBOUTS Enables the RUBOUT key. RUN RUN Compiles and runs the program currently in core. SCRATCH SCR Erases the current program from core. BASIC Statements Statement Example of Form DATA DATA nl, n2, ... nn Numbers nl through nn are to be associated with corresponding variables in a READ statement. DEF DEF FNB (x) == f(x) DEF FNB (x, y) ==f(x, y) The user may define his own function to be called within his program by putting a DEF statement at the beginning of a program. The function name begins with FN and must have three letters. The function is then equated to a formula f(x) which must be only one line long. Explanation 67 Statement Example of Form DIM DIM v(s) Enables the user to create a table or array with the specified number of elements where v is the variable name and s is the maximum subscript value. Any number of arrays can be dimensioned in a single DIM statement. END END Last statement in the program. Signals completion of the program. FOR-TOSTEP FOR v==fl TO f2 STEP f3 Used to implement loops; the variable v is set equal to the formula fl. From this point the loop cycle is completed following which v is incremented after each cycle by f3 until its value is greater than f2. If STEP f3 is omitted, f3 is assumed to be + 1. f3 may also be negative. GOSUB GOSUB n Allows the user to enter a subroutine at several points in the program. Control transfers to line Explanation n. GOTO GOTO n Transfers control to line nand continues execution from there. IF-GOTO IF fIr f2 GOTO n Same as IF-THEN. IF-THEN IF fl r f2 THEN n If the relationship r between the formulas f1 and f2 is true, trans- fers control to line n (n may also' represent an operation); if not, continues in regular sequence. INPUT INPUT vI, v2, ... vn Causes typeout of a ? to the user and waits for the user to supply the values of the variables vI through vn. LET LET v==f Assigns the value of the formula f to the variable v. LPT LPT Assigns line printer as output device. NEXT NEXT v Used to tell the computer to return to the FOR statement and execute the loop again until v is greater than or equal to f2. 68 Statement Example of Form Explanation PRINT PRINT aI, a2, ... an Prints the values of the specified arguments, which may be variables, text or format control characters (, or ;). PTP PTP Assigns high-speed paper punch as output device. tape PTR PTR Assigns high-speed paper reader as input device. tape READ READ vI, v2, ... vn Variables v I through vn are assigned the value of the corresponding numbers in the DATA string. REM REM When typed as the first three letters of a line, allows typing of remarks within the program. RESTORE RESTORE Sets pointer back to the beginning of the string of DATA values. RETURN RETURN Must be at the end of each subroutine to enable control to be transferred to the statement follQwing the last GOSUB. STOP STOP Terminates execution at that point at which the statement is reached in the program. TTY IN TTY IN Assigns a console terminal as input device. TTY OUT TTY OUT Assigns a console treminal as output device. During input to the editor or when executing an INPUT command, the following messages may be printed in response to the input: Message Explanation LINE TOO LONG The line just typed exceeded the available core buffer and must be retyped. DELETED The line has been deleted in response to an AL TMODE character and must be retyped. Back arrow is printed any time a RUBOUT or SHIFT/0 is used. The previous character is deleted. TTY BASIC prints TTY to indicate that there is no more input from the high-speed reader and that it is waiting for input from the Teletype. 69 appendix a loading procedures Initializing the system Before using the computer system, it is good practice to initialize all units. To initialize the system, ensure that all switches and controls are as specified below. 1. Main power cord is properly plugged in. 2. Teletype is turned OFF. 3. Low-speed punch is OFF. 4. Low-speed reader is set to FREE. 5. Computer POWER key is ON. 6. PANEL LOCK is unlocked. 7. Console switches are set to O. 8. SING STEP is not set. 9. High-speed punch is OFF. 10. DECtape REMOTE lamps OFF. The system is now initialized and ready for your use. Loaders READ-IN MODE (RIM) LOADER When a .computer in the PDP-8 series is first received, it is nothing more than a piece of hardware; its core memory is completely demagnetized. The computer "knows" absolutely nothing, not even how to receive input. However, the programmer can manually load data directly into core using the console switches. The RIM Loader is the very first program loaded into the computer, and it is loaded by the programmer using the console A-I switches. The RIM Loader instructs the computer to receive and store, in core, data punched on paper tape in RIM coded format (RIM Loader is used to load the BIN Loader descrJbed below.) There are two RIM loader programs: one is used when the input is to be from the low-speed paper tape reader, and the other is used when input is to be from the high-speed paper tape reader. The locations and corresponding instructions for both loaders are listed in Table A-I. The procedure for loading (toggling) the RIM Loader into core is illustrated in Figure A-I. Table A-I. RIM Loader Programs Instruction Location Low-Speed Reader High-Speed Reader 7756 7757 7760 7761 7762 7763 7764 7765 7766 7767 7770 7771 7772 7773 7774 7775 7776 6032 6031 5357 6036 7106 7006 7510 5357 7006 6031 5367 6034 7420 3776 3376 5356 0000 6014 6011 5357 6016 7106 7006 7510 5374 7006 6011 5367 6016 7420 3776 3376 5357 0000 After RIM has been loaded, it is good programming practice to verify that all instructions were stored properly. This can be done by performing the steps illustrated in Figure A-2, which also shows how to correct an incorrectly stored instruction. When loaded, the RIM Loader occupies absolute locations 7756 through 7776. A-2 SET SWITCHES 6-8 TO DESIRED NSTRUCTION FIELD* *DECTAPE USERS SHOULD LOAD RIM INTO FIELD 0 .Figure A-I. Loading the RIM Loader A-3 SET SWITCHES 6-8 TO FIELD IN WHICH RIM HAS 8EEN LOADED Figure A-2. Checking the RIM Loader BINARY (BIN) LOADERThe BIN Loader is a short utility program which, when in core, instructs the computer to read binary-coded data punched on paper tape and store it in core memory. BIN is used primarily to load the programs furnished in the software package (excluding the loaders and certain subroutines) and the programmer's binary tapes. BIN is furnished to the programmer on punched paper tape in RIM -coded format. Therefore, RIM must be in core before BIN can be loaded. Figure A-3 illustrates the steps necessary to properly load BIN. And when loading, the input device (low- or highspeed reader) must be that which was selected when loading RIM. A-4 - - - -1 Figure A-3 See FIOU"I' C2-1.C2-21 Loading the BIN Loader A-5 When stored in core, BIN resides on the last page of core, occupying absolute locations 7625 through 7752 and 7777. BIN was purposely placed on the last page of core so that it would always be available for use-the programs in DEC's software package do not use the last page of core (excluding the Disk Monitor) . The programmer must be aware that if he writes a program which uses the last page of core, BIN will be wiped out when that program runs on the computer. When this happens, the programmer must load RIM and then BIN before he can load another binary tape. Binary tapes to be loaded should be started on the leader-trailer code (Code 200), otherwise zeros may be loaded into core, destroying previous instructions. Figure A-4 lilustrates the procedure for loading binary tapes into core. A-6 - - ~ SEE FIGURE C2-31 F:gure A-4. Loading A Binary Tape Using BIN A-7 appendixb character codes ASCII-I! Character Set 8-Bit Character Octal 6-Bit Octal 301 302 303 304 305 306 307 310 311 312 313 314 315 316 317 320 321 322 323 324 325 326 327 330 331 332 260 261 262 263 264 265 266 267 270 271 01 02 03 04 05 06 07 10 A B C D E F G H I J K L M N a P Q R S T U V W X Y Z 0 1 2 3 4 5 6 7 8 9 11 12 13 14 15 16 17 20 21 22 23 24 25 26 27 30 31 32 60 61 62 63 64 65 66 67 70 71 Decimal Equivalent (AI Format) Character 96 160 224 # 288 $ 352 % 416 & 480 544 ( 608 ) 672 * 736 + , 800 864 928 992 / 1056 1120 1184 < 1248 1312 >? 1376 1440 @ 1504 [ 1568 1632 ] 1696 t(A)~ ~(-):! ·-992 Leader/Trailer -928 LINE FEED -864 -800 Carriage RETURN SPACE -736 RUBOUT -672 Blank -608 BELL -544 TAB -480 FORM -416 " 8-Bit Octal 241 242 243 244 245 246 247 250 251 252 253 254 255 256 257 272 273 274 275 276 277 300 333 334 335 336 337 200 212 215 240 377 000 207 211 214 Decimal 6-Bit Equivalent Octal (AI Format) 41 42 43 44 45 46 47 50 51 52 53 54 55 56 57 72 73 74 75 76 77 33 34 35 36 37 -1952 -1888 -1824 -1760 -1696 -1632 -1568 -1504 -1440 -1376 -1312 -1248 -1184 -1120 -1056 -352 -288 -224 -160 -96 -32 32 1760 1824 1888 1952 2016 40 -2016 1 An abbreviation for American Standard Code for Information Interchange. 2 The character in parentheses is printed on some Teletypes. B-1 INDEX AC1, 44 AC2, 44 AC3, 44 Acceptable nesting techniques, 25 ACE, 44 ACS, 44 Addressing, 45 Indirect relative, 47 Relative, 45 ALTMODE, 54 ANORM, 48 Argument, 36 Arithmetic operations, 3 Priority of, 4 Arithmetic statement, 10 Array, 25 Maximum size of an, 28 ASCII character set, B-1 Backslash, 9 BASIC compiler, 58 BEGFIX, 48 BIN loader, A-4 loading the, A-5 loading a binary tape, A-7 BKWD, 45 Character codes, B-1 Character set, B-1 Characters, Format control, 15 Checking the RIM loader, A-4 Coding formats (UUF), 43 Command, LET, 6 LIST, 55 LPT, 55, 57 PRINT, 6 PTP, 55, 57 PTR, 56 RUN, 56 SCR, 58 Command summary, 67 Commands, Editing and Control, 53, 67 Commenting the program, 9 Conditional transfer, 24, 30 Control characters, Format, 15 Control commands, Editing and, 53, 67 CTRL/C, 36, 57 CTRL/O, 57 DATA statement, 11 DEF statement, 42 Devices, I/O, 22 DIM statement, 27 Directing program control, 29 Dummy variable, 13, 39, 42 E-type notation, 2 Editing and Control commands, 53, 67 END statement, 9 Equal sign, Meaning of the, 5 Erasing a program in core, 58 Erasing characters and lines, 53 Error messages, 59 Evaluation, Order of, 4 Example Program, 7 Examples (UUF), 48 Exponential notation, 2 FAC, 44 FENTER, 44 FEXIT, 44 Field, 24 FIX, 48 Floating accumulator, 44 Floating-point format, 44 Floating-point instruction set, 45 Floating-point interpreter, 45 Floating-point package, 43 FNA function, 42 FOR statement, 22 Format control characters, 15 comma, 16 semicolon, 17 Fo~ats, coding (UUF), 43 Formatting output, 41 Formula, 22, 24 Function, 34 FNA, 42 GET, 39 INT, 35 PUT, 39 RND, 36 SGN, 35 TAB, 36 User-defined, 59 UUF, 43 Functions, 34 FWD, 45 X-I Generating random numbers over any range, 37 GET function, 39 GOSUB nesting, maximum level of, 33 GOSUB statement, 30, 31 GOTO statement, 29 I/O devices, 22 IF GOTO statement, 30 IF THEN statement, 30 Immediate mode, 6 Incremental value, 22 Index, 22 Indirect relative addressing, 47 Initial value, 22 Initializing the system, A-l INPUT statement, 14 Input/Output statements, 11 Instruction set, Floating-point, 45 INT function, 35 Integer function, 35 Introduction, 1 LET cormnand, 6 LET statement, 10 Level of GOSUB nesting, 33 List, 25 LIST command, 55 Listing and punching program, 55 Loaders, A-l Loading a binary tape (using BIN), A-7 Loading and operating procedures, 58 Loading procedures, A-l Loading the BIN loader, A-5 Loading the RIM loader, A-3 Loops, 22 Nesting, 24 LPT command, 55, 57 LPT statement, 19 Mass storage devices, 47 Maximum level of GOSUB nesting, 33 Maximum size of an array, 28 Meaning of the equal sign, 5 Minimum system configuration, 1 Mode, Immediate, 6 Nesting loops, 24 Nesting subroutines, 33 Nesting techniques, Acceptable, 25 Unacceptable, 25 Nesting, maximum level of GOSUB, 33 NEXT statement, 22, 23 NO RUBOUTS, 53 Normalized form, 44 Numbers, 2 Operating procedures, Loading and, 58 Operators, 3 Relational, 5 Order of evaluation, 4 Output, Formatting, 41 Parentheses, 4 PRINT command, 6 Print positions, 37 PRINT statement, 15 Print zones, 16 Priority of arithmetic operations, 4 Program control, Directing, 29 Programming errors, 60 PTP command, 55, 57 PTP statement, 20 PTR corranand, 56 PTR statement, 14 PUT function, 39 Random number function, 36 READ statement, 11 Reading a program, 56 Relational operators, 5 Relative addressing, 45 Indirect, 47 REM statement, 9 RESTORE statement, 12 RETURN, 54 RETURN statement, 31 RIM, A-l RIM loader, Checking the, A-4 Loading the, A-3 RIM loader programs, A-2 &~D function, 36 Rounding numbers, 36 RUBOUT, 53 RUN cormnand, 56 Running a program, 56 SCR command, 58 SGN function, 35 SHIFT/L, 9 X-2 SHIFT/O, 53 Sign function, 35 Sign-magnitude convention, 43 Statement, Arithmetic, 10 DATA, 11 DEF, 42 DIM, 27 END, 9 FOR, 22 GOSUB, 30, 31 GOTO, 29 IF GOTO, 30 IF THEN, 30 INPUT, 14 LET, 10 LPT, 19 NEXT, 22, 23 PRINT, 15 PTP, 20 PTR, 14 READ, 11 REM, 9 RESTORE, 12 RETURN, 31 STEP, 23 STOP, 10 TTY IN, 20 TTY OUT, 20 Statement numbers, 8 Statement summary, 67 Statements, 7, 67 Input/Output, 11 Transfer of control, 29 STEP statement, 23 STOP statement, 10 Stopping a run, 57 Subroutines, 30 Nesting, 33 Subscript, 27 Subscripted variables, 22, 25 Summary, Command, 67 Statement, 67 Supported options, 2 Symbol Table, 62-66 System configuration, minimum, 1 TAB function, 36 Table, Symbol, 62 Terminal value, 22 Terminating the program, 9 Transfer, Conditional, 24, 30 Unconditional, 29 Transfer of control statements, 29 TTY IN statement, 20 TTY OUT statement, 20 Two-dimensional matrix, 26 Unacceptable nesting techniques, 25 Unconditional transfer, 29 User-defined function, 59, 43 UUF function, 43 Variable, 3 Dummy, 13, 39, 42 Subscripted, 22, 25 Writing the program, 47 X-3 8K BASIC DEC-08-LBSMA-A-D READERrS COMMENTS Digital Equipment Corporation maintains a continuous effort to improve the quality and usefulness of its publications. To do this effectively we need user feedback--your critical evaluation of this document. Did you find errors in this document? If so, please specify by page. How can this document be improved? How does this document compare with other technical documents you have read? Job Title _______________________________________Date: ___________________ Name: Organization: ------------------------------------------------------Street: ______________________________Department: _________________________ City: _______________________State: ____________Zip or Country_____________ -------------------------------------------------------------Fold lIere------------------------------------------------------------ ------------------------------------------------ Do Not Tear - Fold Here and Staple. ----------------------------------------------- FIRST CLASS PERMIT NO. 33 MA YNARD, MASS. BUSINESS REPLY MAIL NO POSTAGE STAMP NECESSARY IF MAILED IN THE UNITED STATES Postage will be paid by: Digital Equipment Corporation Software Information Service Software Engineering and Services Maynard, Massachusetts 01754
Home
Privacy and Data
Site structure and layout ©2025 Majenko Technologies