Edu System Handbook Jan73
EduSystemHandbookJan73 EduSystemHandbookJan73
User Manual: EduSystemHandbookJan73
Open the PDF directly: View PDF .
Page Count: 638
Download | |
Open PDF In Browser | View PDF |
ADDITIONAL COPIES Additional copies of this handbook may be purchased for $5.00 per copy. Please send your order to the address below. DEC offers special discounts on quantity orders. Digital Equipment Corporation Communications Services, Parker Street Maynard, Massachusetts 01754 prepared by . small systems technical writing group programming department digital equipment corporation pdp-s handbook series· FIRST PRINTING, JANUARY 1973 The description and availability of the software products de.. scribed in this manual are subject to change without notice. The availability or performance of some features· of the software products may depend on a specific configuration of equipment. Consequently, DEC makes no claim and shall not be liable for the accuracy of the software products. Distribution of software products shall be in accordance with the then standard policy for each such software product. Copyright © 1973 Digital Equipment Corporation The following are registered trademarks of Digital Equipment Corporation~ Maynard, Massachusetts: FOCAL OS/8 PDP RSTS DEC DECtape Digital EduSystem ERROR REPORTING If you find any erro!s in this handbook, or if you have any questions or comments concerning the clarity or completeness oL this handbook, please direct your remarks to: Digital Equipment Corporation Software Information Service, Building 3-5 Maynard, Massachusetts 01754 ADDITIONAL COPIES Additional copies of this handbook may be purchased for $5.00 per copy. Please send your order to the address below. DEC offers special discounts on quantity orders. Digital Equipment Corporation Communications Services, Parker Street Maynard, Massachusetts 01754 11 The computer is an exciting contemporary piece of equipment. This fact alone explains some of the fascination that a comp~ter invariably stirs up among students, but it doesn't explain all of it. The powerful motivational capabilities which the computer demonstrates in every school that. installs one can only be explained by the way it is used. The computer is tireless. Unlike a student, it loves to do complex calculations. Separating theory from calculation in school assignments has always been a problem. Some of the most interesting and challen·ging concepts of math and science involve, unfortunately, an overwhelming amount of dull calculations. The student gets bogged down in the" arithmetic and never gets excited about the idea. Or, worse still, a less important concept is taught because its calculations come out even. The computer, by taking on all calculations and doing them quickly and accurately, opens up new possibilities for classroom study and student interest. The computer is immediate and unfailingly accurate. It does in seconds what people take minutes or hours to do. The speed of its responses make for powerful reinforcement. It challenges the student to think through the concepts as fast as it grinds through the calculations. The computer is anonymous. Real learning occurs when a student has an idea and tries it out. At the start, he isn't sure whether the idea is valid. Some students have no fear of being wrong and will tell the class their idea. Others are less willing to risk the ridicule of being wrong; The computer lets all students tryout their ideas and gain confidence in them. It treats all students alike; it has no favorites. It waits for the slower user and bounds ahead quickly for the brighter student. With a computer, a student competes with his past achievements, not with other students. Above all else, the computer is challenging. Why is it that a student who quits on a homework problem after trying it once will work tenaciously to get a program running right? Partly, it's iii the immediacy of the computer's response. Partly, it's the ease with which the student can change his program and try again. Partly, it's the fun of talking to·a machine and having it respond. But beyond aU that, there is something about the close interaction between a user and a fast, willing, logical machine which is tremendously challenging. In all these ways and more, the computer stimulates the student, stretches his thinking, provides an immediate andpertinent,application for skills learned in class. The impact on the teacher can be just as great as the impact on the student. Given motivated students, the dedicated teacher becomes even more dedicated. It is not unusual for a teacher to stay at school until five o'clock to give students more time on the computer. Computers have other uses around the schoo~ than instruction. For example, a computer can easily be programmed to grade tests, thereby saving precious teacher time, as well as providing more immediate feedback to students. Other tedious administrative chores such as attendance reporting, grade reporting, transcripts, and payroll can be performed on the computer. What will the computer mean in your school? Almost cert~inly it will mean that students learn and improve at a faster rate. Tests have shown that students who use the computer as part of their math class improve at four times the rate of those who are taught in the traditional way-not just honor students, not using a futuristic curriculum. A cross-section of students-black, white, Chicano, disadvantaged, rich, middle-class-in regular algebra classes improved four times as fast with the computer. The computer also means more thorough understanding coupled with tremendous student motivation. It means more dedicated teachers and an erasing of tedious administrative chores. It means contemporary education for today's world. The computer does not replace the teacher. Nor does the simple existence of the computer make a poor student into a superior student. But in school after school, the computer is turning the bored, lethargic student into an involved, eager student. We at Digital believe that this is the vital, first step to better education. And we firmly believe that computers are for all kids, not for a few geniuses. IV EDUSYSTEMS-SCHOOL COMPUTERS THAT MEET THE CHALLENGE It takes more than just hardware to make an effective school computer system. It takes a thoroughly tested combination of system components and instructional materials designed specifically for classroom use. Recognizing this fact, Digital Equipment Corporation has designed EduSystems-a complete line of computer systems tailored to the needs of schools and colleges. The basis of each EduSystem is. a PDP-8/E computer,l a terminal, and a BASIC language processor. All EduSystems utilize the well-known computer language BASIC. BASIC programs are simple combinations· of English words and decimal numbers. Students with no previous computer experience can be writing meaningful programs after as little as an hour of instruction. EduSyst~ms are compact, trouble-free, and engineered for use in the busy school environment. Even the largest EduSystem can be installed and used right in the classroom. All systems can run completely unattended (i.e., no operator is necessary). Each EduSystem is designed to handle a large number of student users. Time-sharing allows up to 16 students and teachers to work at the computer simultaneously. Batch processing allows hundreds of student runs per day. EduSystems are expandable; as school and student. needs in'crease, the configuration of the system may also increase. Starter systems (EduSystems 5, 10, 15, and 20) grow to be Intermediate Systems (Edl~Systems 25, 30; and 40); Intermediate Systems grow 1 Certain EduSystems are also availabJe on the PDP-l1 computer. Write to the Educational Products Group, Building 5-5, Digital Equipment Corporation, Maynard, Mass. 01754, for more information. v to be the Total System (EduSystem 50). The expansion modules can be installed right at the school. Expandable EduSystems are always the right size to meet a school's present demands. There is never the need to start out with too much computer or end up with too little. As the EduSystem computer expands, so does the BASIC language. Digital's Total Systems2 offer the most powerful BASIC language processors of any computers in their class. In addition, EduSystem 50 provides time-shared FOCAL and FORTRAN-D language processors, a time-shared Assembly Language package, and system utility programs. The effectiveness of EduSystems as classroom tools is well proven. Hundreds of schools starting out with EduSystem 10 or EduSystem 20 have since expanded to an Intermediate System, or even a Total System, while many others are continuing to support excellent programs of computer education without expanding their facilities at all. USING THE EDUSYSTEM HANDBOOK The EduSystem Handbook provides a complete user's guide for each individual EduSystem and a self-instruction course in the use of the BASIC language in general. Most EduSystem users will need to read only two' chapters of this handbook: Chapter 1, and the chapter concerning the EduSystem being used. Chapter 1 is a primer on the BASIC language, 3 allowing. the user to teach himself the fundamentals of BASIC and to familiarize himself with the EduSystem terminal keyboard. Many examples and exercises are included to aid the user in discovering the elements of the BASIC language. A user familiar with Chapter 1 can write simple BASIC programs and run them on any EduSystem.· Once the user knows the fundamentals of BASIC, he refers to the chapter ( chapters 2 through 9) concerning his particular EduSystem. The individual EduSystem chapters describe the features and extended capabilities of BASIC as it is used on the specific EduSystem. Each chapter also contains detailed operating instructions and error messages for the EduSystem. In addition, EduSystem 80 is a Total System available only on the PDP-II. Chapter 1 is derived from Teach Yourself BASIC, Volumes I and. II published by Technica Education Corporation. 2 3 vi each chapter contains a table summarizing the BASIC language capabilities of the EduSystem being described. Chapter 9 provides' a detailed description of EduSystem 50 capabilities, not only of the BASIC language but also' of FOCAL, FORTRAN-D, PAL-D (the assembly language), the EduSystem 50 Monitor, and all the system utility programs. The EduSystem 50 user will also find much helpful information in Introduction to Programming and Programming Languages, Volumes 1 and 2 of the PDP-8 handbook series. The EduSystem Handbook is designed to serve as the primary guide for users of all EduSystems. Users of each EduSystem will find many programming examples to facilitate their understanding of the system. A summary of the BASIC language capabilities of all Digital EduSystems is provided at the end of Chapter 1. , COMMON PROGRAMMING TERMS Such words as loop, jump, nesting, and array have special meanings to computer programmers. Familiarity with these terms is a prerequisite to learning the more advanced programming languages. The Index/Glossary at the end of this handbook defines many of the commonly used computer programming terms. vii V11I CHAPTER 1 TEAcH YOURSELF BASIC 1-1 Introduction Teletype Keyboard .......................................................... 1-3 • • • tI • • • • • • • • • • • • • • • • • I • • • • • • • • • • • • • • • • • • I '• • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • Getting Acquainted With BASIC .....................,................... Numerical Expressions ....................... ,; ........................... The PRINT Statement ................................. :.................. Floating Point Numerals ..................... ,....................... :..... Printing Messages ....,.............................................. ........... Exponents-Computing the Power of a Number ............ 1-5 1-9 1-11 1-15 1-17 1-19 Gathering Speed ................................................ ~ .... '............. 1-20 Variables .................................................................... :..... 1-20 Variable Expressions .............. ;......... ~ ............................. 1-24 Feeding the Beast .................................. " ............................ The INPUT Statement .................................................... The GO TO, Statement ................. .-.................................. READ and DATA Statements ......................................... The RESTORE Statement .................................. ............ More Messages ................................................................ 1-26 1-26 1-30 1-32 1-36 1-37 'You Can Count on It .......................................................... Loops ................................................................................ Loops Exposed ................................................................. FOR-NEXT Loops ... :...................................................... The STEP Clause ..... , ............................ ;......................... Variable FOR Statements ...................................,............. Extra for Experts ................................................... "........ 1-39 1-39 1-41 1-45 1-50 1-52 1-55 'IX Function Junction ................................................................ 1-57 The Integer (INT) Function ............................................ 1-57 The Square Root (SQR) Function .................................. 1-61 Finding Your Way .............................................................. 1-65 Flowcharts ...................................................................... 1-65 FOR...NEXT Loops in a Flowchart ................................ 1-71 Making Decisions ................................................................ 1-73 A Fork in the Road ........................................................ 1-73 The IF Statement ............................................................ 1-79 Varying Patterns .......................................... ,....................... 1-81. Rectangular Patterns ............................................. ......... 1-81 The TAB Function .......................................................... 1-86 Meandering .......................................................................... 1-89 Random Numbers ............................................................ 1-89 Constellations .................................................................. 1-93 Little Boxes ........................................................................ Subscripted Variables ...................................................... Generalizing ............... '" . ...... ..... ... .... .... ... ...... ... ..... ....... ... Variable Subscripts .......................................................... Subroutines ...................................................................... 1-97 1-97 1-1 01 1-102 1-105 Snoopy and the Red Baron ................................................ No Opinion .................................................................... More Choices .................................................................. Generation Gap .............................................. Reprise ............................................................................ 1-107 1-111 1-113 1-115 1-119 Kaleidoscope ........................................................................ Coin Tosser .......................................................... .......... Dice ................................................................................ 23 Matches ...................................................................... Rounding a Number ........................................................ Miscellaneous Math ........................................................ Say Something in Trigonometry ...................................... Do It Yourself Functions ................................................ 1-123 1-123 1-124 1-125 1-127 1-128 1-130 1-131 u .............. Past and Future BASIC ...................................................... 1-132 x CHAPTER. 2 EDUSYSTEM 5 Introduction ....................... " .......... ~ ........... ,.............. ,........... 2-1 System Components .......................................................... 2-2 System Expansion ............................................................... 2-2 BASIC Language Capabilities ................................................. Line Numbers ........ ,.: ............................................................ Single-Character PRINT Command .... '.............................. Multiple Statements Per Line ............................................ Immediate Mode .................................. INPUT Statement ...................................... '1 • • • • • • • • • • • • • • • • • • • • • • • • • • • • , 1 ••••••••••••••••••••••• 2-2 2-2 2-2 2-2 2-3 2-4 Program Editing ...................-........, .............. ~ ......~-................... 2-5 Error Messages ......................................... .............................. 2-5 Operating Instructions Initial Installation .:............................................................ Turning Off the System ....................................................... Restarting the System ...................................................... Reloading the Functions .................................................... Saving Programs on Paper Tape ........................................ Reloading Program From Paper Tape .............................. It CHAPTER 3 2-6 2;..6 2-9 2-9 2-9 2-9 2-10 EDUSYSTEM 10 Introduction ................................................ ............................ 3-1 System Components .......................................................... 3-1 System Expansion ............................................................ 3-2 BASIC Language Capabilities ........................... :.................. Line Numbers..................... ........... ........... ......................... Single-Character PRINT Command .................................. MUltiple Statements per Line .................................'........... Immediate Mode .............................................................. INPUT Statement ,.............................................................. 3-2 3-2 3-2 3-2 3-3 3-4 Program Editing ...... ,..... ~ ..... ,.. " ... ,...... , ........ ,..... ,.................... 3-6 Error Messages .................................... ................................... 3-7 xi Operating Instructions .......................................................... Initial Installation ................... ~.......................................... Turning Off the System .................................................... Restarting the System ........................................................ Reloading the Functions .................................................. Saving Programs on Paper Tape .................................... Reloading Programs From Paper Tape ............................ CHAPTER 4 3-8 3-8 3-10 3-11 3-11 3-11 3-12 EDUSYSTEM 15 Introduction ...................... ................................................. System Components ...................................................... .. ~ ~ 4-1 4-1 BASIC Language Capabilities ........................................... . 4-2 Entering Programs ......................................................... . 4-2 Using Random Numbers ............................................... . 4-2 Listing the Program ... ~ ................................................... . 4-3 Executing the Program ................................................... . 4-4 Privileged Control Commands ....................................... . 4-4 DEC tape System Storage Capability ................... ~ ........ .. 4-5 Advanced System Capabilities ........................................... . Running Very Long Programs ....................................... . U sing a Data File ........................................................... . Character Variables and String Capability .................... .. 4-6 4-6 4-7 4-8 Prograln Editing ................................................................. . 4-11 Error -Messages ................................................................... . Program Loading Errors ................................................. . Coding Errors ................................................................. . Program Logic Errors ................................................... . 4-12 Operating Instructions ...................................................... .. Loading the System ...................................................... .. Initialize the DECtape Unit ........................ '.............. .. Initialize Computer Memory ..................................... . System Building Dialog .................................................. .. Diagnostic Messages During System Building ........... . Turning off the System .................................................. .. Restarting the System ..................................................... . XJl 4-12 4-13 4-15 4-16 4-16 4-17 4-17 4-19 4-23 4-25 4-25 Saving Programs on Paper Tape .................................... Reloading Programs from Paper Tape ............................ CHAPTER 5 4-25 4-26 EDUSYSTEM 20 Introduction System Components ................................................. ~ .... .. System Expansion. ,.......................................................... ~. 5-1 5-1 5-2 EduSy~tem 20 BASIC ......................................................... . 5-2 Abbreviated Commands .................................................. . 5-2 Multiple Statements per Line ........................................ .. 5-4 Immediate Mode ............................................................ .. 5-5 INPUT Statement .......................................................... .. 5-6 Comments ........................... 5-6 Subscripted Variables ............. ,..............................-......... . 5-7 IF THEN Statement ...................................................... .. 5-8 Truncation Function (FIX) ........................................... . 5-9 CHR$ Function ......... -... ;................................................ . 5-9 ON ·GOTO Statement ............................. ~ ........................ .. 5-10 ON GOSUB Statement ................................................... . 5-10 RANDOMIZE Statement ............. ~ ................................ .. 5-11 8 •••••••••••••••••••••••••••••••••••••••••••• Error Mess~ges ................................................................... . 5-12 Program Editing .................... "............................................ . 5-14 Operating Instructions ....................................................... . Loading EduSystem 20 BASIC ...................................... .. Initial Dialog ................................................................... . System Reconfiguration ................................................ .. System Shutdown ............................ :.............................. . System Restart ............................................................... .. Program Storing Procedures ........................................... . Teletype Paper Tape Punch ....................................... . High-Speed Punch .................................................... .. Program Reloading Procedures .......................... ~ ......... .. Teletype Paper Tape Reader .................................... .. High-Speed Reader .................................................. .. 5-16 5-16 5-17 5-21 5-21 xiii 5-21 5-21 5-22 5-22 5,-22 5-22 5-22 CHAFfER 6 EDUSYSTEM 25 Introduction ...... " .................... , ........................................... 6-1 System Components ... ,................................................... . 6-1 System Expansion ................ :.................. " ...................... . 6-2 BASIC Language Capabilities ........................................... . 6-2 Abbreviated Commands ................................................. . 6-2 Multiple Statements per Line ......................................... . 6-2 Immediate Mode ............................................................. . 6-3 INPUT Statement .................. 6-4 Comments .. 6-4 IF THEN Statement ...................................................... .. 6-5 ON GOTO Statement ................................................... . 6-6 ON GOSUB· Statement ................................................... . 6-6 RANDOMIZE Statement ............................................... . 6-7 Truncation Function (FIX) .......................................... .. 6-8 II •• II ••• , ••• , •• I'" 1> • • • • • • • • • • • , ••••••••••••••••••••• , I I • • • I I • • I I • • • I I • • IIJ" ••••••••••••••••••••••••••••••••••• Extended System Capabilities ............................................ .. String Variables ............................................ ,.... ,........... . Reading String Data ................. ,................................. . Printing Strings ........................ " ....... ,................. ,....... . Inputting· Strings ......................................................... . Line Input .................................................................... . Working with Strings ................................................. . String Functions .......................................................... . . CHR$ Function .................................................... .. MID Function ............................... LEN Function ................. , ..... ,............................... CAT Function ................ Program Storage/Retrieval ............................................. . Storing User Programs ............................................... . Retrieving User Programs ......................................... . Running Very Long Programs .................................. .. Deleting Stored Programs ........................................... . Using Public Library Programs ................................ .. Data File Storage/Retrieval ........................................... . Creating Data Files ..................................................... . Reading Data Files .................................................... .. 1 •• I ••••••••••••••••••••• II I ' ' ' • • • I I • • • I ' • • • • I I I I • • • • • • • • • • • • I_I • • • • • XIV 6-8 6-8 6-8 6-9 6-9 6-10 6-11 6-11 6-11 6-12 6-1l 6-13 6~13 6-14 6-14 6-15 6-16 6-17 6-18 6-18 6-20 Listing Data Files ........................................................ Erasing Data Files ...................................................... Using Public Data Files ................. :............................ 6-21 6-22 6-22 Error Messages ......................... :............................................ 6-26 Program Editing' .................................................................. 6-28 Operating Instructions ........................................................ Loading EduSystem 25 .................................................... Initialize the DECtape Unit ........................................ Initialize Computer Memory ...................................... Answer System Dialog ................................................ Establish Terminal Extensions .................................... Cr~ate Data File Tape ................................................ Maintaining the Public Library ................................. ~.... Protecting DECtape. Files......... .................. ..................... Storing Programs on Paper Tape .................................... Reloading Programs from Paper Tape' .................. "'........ System Reconfiguration .................................................. System ·Shutdown ................ :............................................ System Restart ................................................................ 6-31 6-31 6-31 6-31 6-32 6-35 6-37 6-38 6-39 6-39 6-39 6 . .40 6-40 6-40· CHAPTER 7 EDUSYSTEM 30 Introduction . ..... ........ .... ........ ..... ........ ..... ....... ... ........ ...... ..... 7-1 System Components ......................................................... 7-1 System Expansion ... ~......................................................... 7-2 BASIC Language Capabilities ............................. ~.............. Using Random Numbers ............................... ;... ~............ Running Long Programs ................................................ Using a Data File ................................ ............................. Character Variables and String Capability ...................... 7-2 7-5 7-5 7-6 7-8 Using the Interactive Terminal............................................ Entering a Program ........................................................ Using Multiple Statements per Line ....... ~........................ Listing the Program ........................................................ Executing the Program ............ ;...................................... Loading a Card ·Program for Interactive Use ................ 7-11 7-11 7-12 7-12 7-13 7-13 xv Storing Program~ on Paper Tape ................................ .. Reloading Programs from Paper Tape ...................... :... .. Privileged Coritrol Commands ............................... :....... . Using th~ System Storage Capability ............................. . SAVE and UNSAVE Commands ............................. . CATALOG Command ............................................. . LENGTH Command ................................................. . OLD Command ......................................................... . Returning to Batch Mode ............................................... . Program Editing .......................................................... "," Writing and Running Card Programs .................................. . Writing a Program on Cards ........................................ .. Line Numbers .............................................................. . BASIC Statements ............ :... :..................................... . Statement Operand .................................................. .. Summary of Card Marking Procedure ...................... .. Submitting a Program to be Run ................................... . The NEW Card ......................................................... . The LIST Card ......................................................... . The RUN Card ........................................................ .. Summary ..................................................................... . Getting the Results of a Computer Run ........................ .. Using a Stored Program ................................................. . Interacting with the Operator ....................................... . Editing and Rerunning a Program ................................ .. Inserting Messages in the Program Printout .................. .. Sample Program ........................................................... . Problem .................................................................... .. Procedures ................................................................. . Printed Results ........................................................... . Executing Card Programs ................................................ .. Normal Batch Operation .................................... :.......... . Executing Card Programs Individually ......................... . Controlling a Batch Run ................................................. . BATC!I Command ................................................... . MAX Command ........................................................ .. fIEADER COlnmand ................................................. .. STACK Command ..................................................... . LOG Command ........................................................ .. xvi 7-14 7-14 7~14 7-15 7-15 7-16 7-16 7-17 7-17 7-17 7-18 7-18 7-19 7-20 .... 7-20 7-22 7-23 7-23 7-24 7-24 7-24 7-25 7-26 7-27 7-27 7-28 7-28 7-28 7-28 7-29 7-29 7-29 7-30 7-31 7-31 7-31 7-32 7-:32 7-33 Hands-On Interaction Versus Batch ................................. ~ 7-33 Enors Messages .. "...... ~ Batch Mode Program LoadiNg Errors ........................... . Interactive Mode Program Loading Errors ................... . Coding Errors """"""""""" ~"".""""""""""""""""""""""""""""" .. """"."""."""."""". Program Logic Errors .... ;; ............................................. . II • • ••••••••••••••••• ' ••••••••••••••••••••••• •••••••••• 7-34 7-34 7-35 7-36 7-37 7-38 Loading EduSystem 30 ................................................ .. 7-38 Initialize the DECdisk ................................................. . 7-38 Initialize the DECtape Unit ...................................... .. 7-38 Initialize Computer Memory ....................................... . 7-39 System Building . Dialog ................... :............ .-................ . 7-39 Diagnostic Messages During System Build ................. . 7-43 Turning Off the System ........................ :........................ . 7-47 Turning On the System ................................................. . 7-48 Restarting EduSystem 30 ..................... ~ ........................ . 7-48 DF32 or RF08 Disk ................................................. . 7-48 TC01 DECtape ......................................................... . 7-49 TD8E DECtape ....................................................... ~ .. 7-49 Using Optional Hardware ............................................. . 7-50 LP08 Line Printer ................................................. ;.. .. 7-50 High-Speed Paper Tape Reader/Punch ..................... . 7-50 Punched Card Input .................................................. .. . 7-51 Operating Instructions ....-................................................... . Calculating Available Storage CHAPTER 8 7-52 EDUSYSTEM 40 Introduction System Components ....................................................... . System Expansion ......................................................... . BASIC Language Capabilities ........................................... . Advantages and Applications ...................................... .. EduSystem 20 """"""",,""""""""""""""" EduSystem 30 ........................................................... . t·." ••• ,,"" ••• """"" •••• ,,"",, •• ,,""""" •••• Language Summaries .................................. ~ .................... . BASIC Statements and Commands ............................... . xvii 8-1 8-1 8-2 8..2 8-2 8-2 8-3 8-4 8-4 Batch Control Cards ...................................................... BASIC Functions and Arithmetic Operations ................ 8-8 8-9 Error Message Summaries .................................................. EduSystem 20 ................................................................ EduSystem 30 ................................................................ Batch Mode Program Loading Errors ................ ,....... Interactive Mode Program Loading Errors ................ Coding Errors ............................................................ Program Logic Errors ................................................ 8-10 8-10 8-12 8-12 8-12 8-13 8-15 Loading and Operating Instructions .................................... Initializing the DECdisk ................................................ Building EduSystem 40 on Disk .................................... Starting EduSystem 40 .................................................... 8-16 8-16 8-16 8-20 CHAPTER 9 EDUSYSTEM 50 Introduction ........................................................................ User Programs ................................................................ User Files ................................................ ........................ System Configuration ....................................................... System Expansion ..........................................................' 9-1 9-2 9-2 9-3 9-4 EduSystem 50 Monitor ...................................................... Calling the Monitor ............. ~ .... ~ ..................................... Logging into EduSystem 50 .......................................... Logging out of EduSystem 50 ........................................ System Library Program Control .................................... Communication with Other Users .................................. System Status Reports .................................................... Resource Sharing ......................................... ;.................. Error Messages ................................................................ 9-4 9-4 9-6 9-8 9-10 9-11 9-12 9-12 9-16 System Library Programs .................................................... General File Characteristics ............ .............................. Controlling the Execution of System Library Programs .: .. Returning to the Monitor ......................................... ;...... 9-17 9-18 9-20 9-21 XVlll BASIC ... _............................................................................. 9-23 Truncation Function, FIX(X) ........................................ 9-24 ON· GOTO Statement....................................................... 9-24 SLEEP Statement ..... ;...................................................... 9-24 Comments ... ".......................-.............................................. 9-25 Blank Lines ................................................................... :. Multiple Statements per Line .......................................... Editing BASIC Statements ....... ;.............. ~ ....................... Saving Compiled Programs .............................................. File Protection ..... :.: ........................................................ Project~Program~er Numbers ................................ :....... Restricted Accounts ....................... ,................................ Catalog ForriI~t ....................................... :........................ Strings in BASIC ....................,......................................... Reading String Data ~ ................................................... Printing Strings .............................................................. - Inputting Strings .......................................................... Line Input ................................... c. ••••••• , • • • • • • • • • • • • • • • • • • • • • • • • Working with Strings .................................................... The CHANGE Statement............................................ The CHR$ Functi,on .................................................... Program Chaining ...... ,.... ,. ................................................. Disk Data Files ................................................................. 9-26 9-26 9-26 9-27 9-27 9-28 9-28 9-29 9-29 9-29 9-31 9-31 9-32 9-33 9-34 9-36 9-36 9-38 File Rec.ords ..................... "......................................... 9-38 Opening a Disk File .................................................... Reading/Writing Disk Files ........................................ Closing/Deleting Disk Files ........................................ DECtape Data Files ........................................................ DECtape File Records ....... ;........................................ Opening a DECtape File ............................................ Reading/Writing DECtape Files ................................ Closing DECtape Files ................................................ Using DECtape Data Files with OS/8 FORTRAN .... Line Printer Output ........................................................ Paper Tape Output .......................................................... Internal Data Codes ........................................................ 9-40 9-40 9-42 9-43 9-43 9-44 9-45 9-46 9-46 9-47 9.-47 9-48 Numeric Data .............................................................. 9-48 String Data ....... .......... ..... ......... ...... ....... ...... ............ .... 9-50 Error Messages ......................................................... ........ 9-50 xix FOCAL .............................................................................. Using FOCAL Commands .............................................. FOCAL Overview ............................... ,...... ,..................... Numbers ............................................. ,...... ,..................... Variable Names .............................................................. Arithmetic Operations ..... =.............................................. Priority of Arithmetic Operations ................................ Enclosures .................................................................. Input/Output Commands .............. .......... ................ ........ TYPE Command ........................................................ ASK Command ...... ~ ........................................... ,•...... Text Output with ASK ............................................ Computational Command. ............................................... SET Command .......................................... :.................. Control Commands ........................................................ GO or GOTO Command ................................................ IF Command................................................................ If with Less Than Three Line Numbers .................. Arithmetic Comparison with IF Command ............ DO Command .............................................................. Nested DO .............................................................. RETURN Command .................................................. QUIT Command .-....................................................... FOR Command .......................................................... FOR with a DO ...................................................... Nested FOR and DO .............................................. Subscripted Variables .................................................. COMMENT or CONTINUE Command ...... ;............. Edit Commands ......... ,...... ,............................................. WRITE or WRITE ALL Command .......................... ERASE and ERASE ALL Commands ., ...................... MODIFY Command .................................................... Library Commands ..... ,..................................................... LIBRARY SAVE ........................................................ LIBRARY CALL ...................................................... LIBRARY DELETE ......................................... ,........ LIBRARY LIST ........................................................ Error Messages with Library Commands .................... Estimating Program Length ..........................._................. Debuggl'ng ............................. , ....................................... . xx 9-61 9-61 9-62 9-63 9-63 9-64 9-64 9-65 9-66 9-66 9-67 9-68 9-68 9-68 9-68 9-68 9-69 9-69 9-70 9-71 9-71 9-72 9-72 9-72 ' 9-73 9-73 9-74 9-74 9-75 9-75 9-76 9-76 9-78 9-78 9-78 9-79 9-79 9-79 9-80 9-81 Using the Error Diagnostics ........................................ Using the Trace Feature ............................. ~ .............. FOCAL Functions .................... ;..................................... Sine Function (FSIN) ................................................ Cosine Function (FCOS) .......................................... Exponential Function (FEXP) ..... ~ .............................. Logarithm Function (FLOG) .................................... Arctangent Function (FATN) ............ ~ ....................... Square Root Function (FSQT) .................................. Absolute Value Function (FABS) .............................. Sign Part Function (FSGN) ........................................ Integer Part Function (FITR) .................................... Random Number Function (FRAN) ........................ FOCAL Output Operations ................... ~ ........................ Control Characters .......................................................... ~ Reading FOCAL Paper Tapes .................. o . . . . . . ._ . . . ........... FORTRAN-D .. .......... .......... .............................. ................ Calling FORTRAN-D .................... ;............................... Using FORTRAN-D ........................................................ Line Format .................................. .................................. Statement Numbers .. ................................. ................. Statement Continuation Character . ............................. FORTRAN Statements .................................................. Comment Statements ......... :................... ~.................... Character Set .............................................................. Constants . .................................................................... Integer Constants .................................................... Real Constants .......................................................... Fixed and Floating-Point Representation ................ Variables .................................................................... Integer Variables ..................................................... Real Variables ......... ........... ..................................... Scalar Variables ...................................................... Array Variables ...................................................... DIMENSION Statement ............................................ FORTRAN Arithmetic .................................................... Arithmetic Operators .................................................. Use of Parentheses .................................................. Arithmetic Expressions .............................................. XXI 9-81 9-82 9-82 9-83 9-83 9-84 9-84 9-84 9-85 9-85 9-85 9-86 9-86 9-86 9-87 9-88 9-95 9-95 9-96 9-97 9-98 9-98 9-99 9-99 9-100 9-100 9-100 9-101 9-101 9-102 9-103 9-103 9-103 9-104 9-104 9-105 9-105 9-106 9-107 Arithmetic Statements ............................... ,................ 9-108 Multiple Replacement .......................... " ................ 9-109 Mode Conversion .................................................... 9-110 Functions ................................................... "............. .. 9-110 Program Control ........................................... ............... .. 9-111 END Statement .......................................................... 9-111 STOP Statement .......................................................... 9-111 PAUSE Statement ........................................................ 9-112 GO TO Statement ...................................................... 9-112 Example of Integer Summation .................................. 9-113 IF Statement ................................................................ 9-113 DO Loops ................................................................... 9-115 CONTINUE Statement............................................ 9-117 Computed GO TO ...................................................... 9-118 FORTRAN Input/Output .............................................. 9-118 Data Formats .............................................................. 9-119 ASCII Coded Data ................................................ 9-119 Binary Coded Data ................................................ 9-119 Input/Output Statements ............................................ 9-119 ACCEPT and TYPE Statements ............................ 9-120 READ and WRITE Statements .............................. 9-121 Variable Specification in I/O Statements .................... 9-121 FORMAT Statement .................................................. 9-123 The A Format Specification ........................................ 9-124 Input Formats .............................................................. 9-125 Integer Values-the I Format .................................. 9-125 Real Values-the E Format .................................... 9-126 Output Formats .......................................................... , 9-126 E and I Formats ...................................................... 9-126 Format Control Specifications .................................. 9-127 Hollerith Output ...................................................... 9-127 Imp!ementation Notes .................................................... 9-128 Double Subscripts ........................................................ 9-128 Substatement Feature .................................................. 9-129 Error Checking ............................................................ 9-130 FORTRAN-D Source Program Restrictions .............. 9-131 FORTRAN-D Compiler and Operating System Core Map ................................................................ 9-131 FORTRAN-D Error Diagnostlcs .................................... 9-133 Compiler Compilation Diagnost!cs .............................. 9-133 xxii Compiler Systems Diagnostics ..................................... 9-135 Operating System Diagnostics...................................... 9-136 ~ .PAL-D Assembler .............................................................. Introduction ................... ................................................. . EduSystem 50 PAL-D ....... :............................................ Example of a PAL-D Program ........................................ 9-137 9-137 9-137 9-138 Utility Programs ............................. :.................................... Symbolic Editor ....................................... ........................ Loader ............................................................................. Octal Debugging Technique ............................................ Catalog (CAT) ................................................................ System Status (SYSTA T) ....................,............................ 9-145 9-145 9-149 9-150 9-153 9-154 Programs for Paper Tape and DECtape Control ................ PIP (Peripheral Interchange Program) ............................ PIP Conventions ................................ ........................... Paper Tape to Disk Transfers ...................................... Disk to Paper Tape Transfers .................................... High-Speed Reader/Punch Assignments .................... BIN Format File Transfers ................. :....... ~ ................ Moving Disk Files .......... :......................................... \... Deleting Disk Files ................................................... .... BASIC File Transfers .................................................. SAVE Format File Transfers ............. ......................... COpy Program ................................................................ Using and Calling COpy .......................... "................. Loading'Files from DECtape ...................................... Saving Disk Files on DECtape .................................... Listing Directories ...................................................... Deleting Files ........................................................ ;..... Deleting all Existing Files on a Device ...................... Example of COpy Usage ............................................ AdvaDletl Monitor Cootmands ............................................ Introduction ............................................................. ......... Control of User· Programs .............................................. Defining Disk Files .......................................................... Creating a Disk File ........................ :........................... Opening and Closing a File ............... ;.......................... Extending, Reducing, and Renaming a Disk File ...... 9-157 9-157 9-157 9-157 9-158 9-158 9-159 9-159 9'-160 9-160 9-160 9-161 9-161 9-162 9-163 9-163 9-164 9-164 9-165 9-167 9-167 9-168 9-169 9-170 9-170 9-171 xxiii Protection Codes Error Conditions ...................................................... .. Saving and Restoring User Programs ............................ .. Utility Commands ......................................... "............... .. 9-171 9-173 9-174 9-177 Writing Assembly Language Programs ............................. . Introductioll ................................................................... . Console I/O .................................................................. .. Files and Disk I/O .......................... :............................. .. Assignable Devices ............ ,............................................ . Program Control ............ "................................................ . Program and System Status ........................................... . PDP-8 Compatibility ............................................... ,....... . 9-179 9-179 9-180 9-183 9-190 9-195 9-197 9-200 Storage Allocation ............................................................... . Storage Map .................................................................. .. File Directories ............................................................... . Prqject-Programmer Numbers ................................... ,.. .. 9-205 9-205 9-205 9-206 ••••••••••• , ••••••••••••• , •••••••••••••••••••••••••••• II APPENDICES Appendix A Read-In Mode Loader ................................ A-I Appendix B Character Codes .... ...................................... B-1 Appendix C EduSystem 50 Monitor Command Summary C-1 Appendix D EduTest ........................................................ D-1 LIST OF TABLES Table Table Table Table Table Table Table Table Table Table 1-1 1-2 1-3~ 2-1 3-1 4-1 5-1 5-2 5-3 6-1 BASIC Statements ...... ,............................... . BASIC Edit and Control Commands ....... . BASIC Functions and Arithmetic Operations EduSystem 5 BASIC Statement· Summary EduSystem 10 BASIC Statement Summary EduSystem 15 BASIC Statement Summary EduSystem 20 BASIC Statement Summary EduSystem 20 BASIC Function Summary EduSystem 20 Error Messages ................ ~. EduSystem 25 BASIC Statement Summary XXIV 1-134 1-139 1-144 2-11 3-5 4-26 5-2 5-3 5-12 6-23 :Table Table Table Table Table Table Table Table Table Table Table Table Table Table Table Table Table Table Table 'Table Table Table Table Table 6-2 6-3 7-1 8-1 8-2 8-3 8-4 8-5 8-6 8-7 8-8 8-9 8-10 9-1 9-2 9-3 9-4 9-5 9-6 9-7 9-8 9-9 9-10 9-11 Table 9-12 Table 9-13 Table Table Table Table Table Table Table Table Table Table Table 9-14 9-15 9-16 9-17 9-18 9-19 9-20 9-21 9-22 9-23 9-24 \ EduSystem 25 BASIC Function Summary 6-26 EduSystem 25 Error Messages ................. . 6-26 EduSystem 30 BASIC Statement Summary 7-2 Statements ................................................. . 8-4 Edit and Control Commands .................... .. 8-6 Batch Control Cards ................................... . 8-8 Functions ................................................... . 8-9 Arithmetic Operations ............................. . 8-10 EduSystem 20 Error Messages ................. . 8-10 Batch Mode Program Loading Errors ....... . 8-12 Interactive Mode Pro'gram Load:ng Errors 8-13 Coding Errors ........................................... . 8-14 Program Logic Errors ............................... . 8-15 LOGOUT Options ..................................... .. 9-10 Monitor Error Messages- .......................... .. 9-16 Internal Data Codes .................................. .. 9-49 BASIC Error Messages ............................ .. 9-50 Non-Fatal Error Messages ......................... . 9-55 EduSystem 50 BASIC Language Summary .. 9-56. FOCAL Command Summary ................... . 9-89 FOCAL Functions ..................................... . 9-92 FOCAL Error Messages ........................... . 9-93 FORTRAN-D Statement Summary ........... . 9-132 FORTRAN-D Compiler C6mpil~tion t'ICS ................................................. , · . D lagnos 9-134 FORTRAN-D Compiler Systems · st'ICS ................................................ .. 9-135 D lagno FORTRAN-D Operating System t'ICS ................................................. . 9-136 · D lagnos EduSystem 50 Symbol List ...................... .. 9-139 P AL-D Error Diagnostics .................. ,......... . 9-142 Symbolic Editor Operations Summary ....... . 9-146 EDIT Command Summary ...................... .. 9-147 ODT Command Summary ........................ .. 9-151 PIP Option Summary ................................. . 9-161 COpy Option Summary .......................... .. 9-165 Monitor Program Control Commands ....... . 9-169 Monitor Utility Commands ...................... .. 9-178 EduSystem 50 Internal Character Set ...... .. 9-192 EduSystem 50 lOT Instruction Summary .. .. 9-202 xxv Table A-I Table D-l RIM Loader Programs .............................. .. EduTest Error Messages ............................ A-I D-I0 LIST OF ILLUSTRATIONS Figure Figure Figure Figure Figure Figure Figure Figure Figure Figure Figure Figure Figure Figure Figure Figure Figure Figure Figure 4-1 7-1 7-2 7-3 7-4 7-5 7-6 7-7 7-8 8-1 8-2 9-1 9-2 9-3 9-4 9-5 9-6 A-I A-2 "System Building Dialog ................................ 4-20 EduSystem 30 BASIC Card .......................... 7-18 Line Number Example ................................ 7-19 Statement. Example ...................................... 7-20 EduSystem 30 BASIC Template .................. T-21 Marking the Statement Operand .................... 7-22 Completed BASIC Cards ............................ 7-23 BASIC Program Deck .................................. 7-25 System Building Dialog ................................ 7-44 Building EduSystem 40 ................ .'............... 8-18 Starting EduSystem 40 .................................. 8-21 Number Representation ................................ 9-102 Program Flow ................................................ 9-112 Legal and Illegal Nesting Techniques ............ 9-116 Program Branching in DO 'Loops ................ 9-11 7 EduSystem 50 Storage Map ........................ 9-205 File Directories ............................................ 9-206 Loading the RIM Loader .............................. A-2 Checking the RIM Loader ............................ A-3 XXVI 1 teach yourself: basic INTRODUCTION BASICl is a conversational computer language which enables a human to carry on a "dialog" with a computer. We will "talk" to the computer by using a Teletype2 like the one shown below. Your -terminal may be an alphanumeric cathode ray tube (CRT) DECterminal or a high-speed DECwriter. Operations with these terminals are, in most cases, identical w.ith the Teletype, so we ., will only discuss the Teletype here. OFF REL. B. SP. ON STARTSTOPFREE~ OFF LINE o LOCAL BASIC (Beginner's All-purpose Symbolic Instruction Code) is a trademark -registered by the Trustees of Dartmouth College. 2 Teletype is a registered trademark of the Teletype Corporation. 1 1-1 Using the Teletype, we type messages to the computer, requesting it to carry out operations. The computer performs the required operations and prints the results on the same Teletype. If we make certain mistakes or if we ask the computer to do something "it cannot do, it may print an error message. For example, if we type DO THE HOMEwORK ON PAGE 257 (and press the RETURN key) INHAT1 the computer may respond by printing a message such as WHAT? The actual response depends on the EduSystem that you are usmg. If you wish to use the computer, you must: Learn what the computer can do and what the computer cannot do. Learn a language, such as BASIC, so that you can instruct the computer to do things within its capability. Communcate with the computer by means of the Teletype. We will begin by assuming that you know little or nothing about computers and will try to lead you through the following four levels of "know-how." 1. You know nothing about computers. If you wish to .use a computer to help you solve a problem, you describe the problem to Susan. Susan uses the computer and returns the answer to you. 2. You can operate the computer (Teletype), using a program supplied by another person. The program, however, is gibberish to you-incomprehensible! 3. You can read and understand programs written by others but are unable to write original programs of your own. 4. Computerland is yours! You can invent your own original problem-solving pro~edures, write them in the BASIC language, check them out on the computer, correct them ("debug" them) if necessary, and obtain the desired results. This chapter is designed to help you learn the fundamentals of BASIC. Many examples and exercises are included to aid you in discovering the elements of the BASIC language. 1-2 Teletype Keybourd BASIC programs must be written using the symbols that appear ~n the Teletype keyboard. A diagram of the Teletype keyboard lS shown below: CD '*" fT\ f7'\ f7\ ('$\ 17\ fa\ f-"\ fl\ f \ f.\ ~ VV'-V-.V\.:.J\'v\'ve\"v\'vVV\V ~ f \ f \ r:;;) ~ ~ ( ) f \ (;;;\ A (@\ ~ {;;\ ~\.::J~\':"'\'v\'yY\::..J\.:J\V\:...J~~ 8oe~vG)eDOOCDeCD@ee 8 Q()'OOOCDCDOG(D 8 SPACE No other symbols may be used. For example, the following symbols are commonly used in mathematics, but may not appear in a BASIC program because they are not on the keyboard. ~ f3 a s On the keyboard diagram, locate the keys with the foHowing symbols: ABC 0 E F G H I J K L M N Letters: o Digits: 1 234 567 B 9 0 Special: .. P Q R STU V / wx y z - To type any of the above symbols, simply press the appropriate key. For example, to type the letter S, press the key on which S appears. 1-3 \ Here is another copy of the key~oard chart so you won't have to turn the page back. e>cbCDC)G)(D0660cbcb© ~(\(\~~~()(\(';;;\:-ff\e0 ~ \.V \!..J \.!..) \V.\V v \V \.:J \.V ~ ~ @ee 80GJGJG)evQO(D,e: 8 OOOG)O ~ Q)OC)Q) 8 Locate the SHIFT keys. There are two of them, located at the left and right ends of the bottom row of keys. When we refer to a character that is typed while the SHIFT key is held down, we will show it as SHIFT/Character. For e~ample, if we want you to type a ~ (back arrow) we will tell you to type SHIFT/O. We have drawn arrows to call your attention to the keys with tlte following special characters. It () * .... t + To type any of these characters, you must hold either SHIFT key down and press the key that has the desired character. The space bar looks like this: SPACE Use it to insert spaces as you type. (;;\ ~ Locate the RETURN key: Now you are ready to start "talking" to the computer. 1-4 GETTING ACQUAINTED WITH BASIC Imagine that we are seated at the teletype and that (perhaps with some help) we have attracted the attention of the computer. We will begin with some absurdly simple programs. If you try these programs; remember to press the RETURN key at the end of each line that you type. If you make a mistake, the compu~er may print'an error message. Ignore it-retype the line. Here we go! SCR 10 PRINT 7 99 END RUN 7 First, we type SCR and' press the RETURN key. The computer SCRatches (erases) any old program in its memory. Then we enter our BASIC program, consisting of two statements. Each statement is on' a separate line. The program is in the computer's memory. We tell the computer to RUN the program. It does and 'prints the re- sult, 7. The BASIC program is shown again below. 10 PHtNT' 7 99 END It consists of two statements, a PRINT statement and an END statement. Each statement begins with a line number. Read onit gets better. ' 1-5 Let's do something a little more exciting. SCR First, we SCRatch the preceding program. 1~ PRINT 3+4 99 END And then enter a new program. This program also has two statements. RUN We tell the computer to RUN the program. 1 It does, The result is 7 since 3 + 4= 7. 20 30 40 40 PRINT PRINt' PRIIf! PRINT 3-4 3*4 3/4 3/4 Then we type LIST and press the' RETURN key. LIST 10 PRINT PRINT PRINT PRIN_T END 20 30 40 99 Let's add three more statements. We use 20, 30 and 40 as line numbers. 3+4 3-4 3*4 3/4 The computer LISTs the program in its memory. Note that there are five statements and that they are listed in line number order. O.K., let's RUN the program. RUN 1 Here are the four results, one for each of the first four statements in the program. -1 12 Exercise 1. Examine the preceding program, then write the symbol that is used to tell the computer to perform each of the following arithmetic operations. OPERATION SYMBOL Addition Subtraction Multiplication Division 1-6 Remember these things. WE TYPE TO TELL THE COMPUTER TO SCR SCRatch (erase) the program in memory. RUN RUN the program in memory. LIST LIST the program in memory. The statement 10 PRINT 3+4 tells the computer to evaluate the numerical expression 3 print the result. In this case, the result is 7. + 4 and The statement tells the computer to evaluate the numerical expression 3*4 (3 times 4) and print the result. This time, the result is 12. The statement 99 END simply marks the end of the program. Every BASIC program musj have an END statement. Each statement begins with a line number.' A line number may be any counting number in the range: 1 ~ line number :::;;; 2046 . Larger EduSystems permit line numbers to 9999, but 2046 is plenty for most programs. Instead of numbering statements with consecutive counting numbers (1, 2, 3, etc.) we use 10, 20, 30 and so on. This' gives us room to insert a new statement between two old statements. For example, if we had already entered a program using 10, 20, 30, 40 and 99 as line numbers, we could insert a sta,tement between statement 20 and statement 30 by using 25 as the line number of the new statement. 1-7 Exercise 2. Do not use the computer to do this exercise. Instead, pretend that you are the computer. We have entered the following program into your memory and told you to RUN the program. Do it. 10 20 30 40 99 PRINT PRINT PRINT PRINT END 12+3 12-3 12*3 12/3 RUN We entered this program, consisting of five statements, into your memory. O.K., computer, RUN the program .. Indicate your answer by filling in the blanks. Exercise 3. You are·still the compuer. We will add a statement to the program we entered in the preceding exercise. 50 PRINT 2*3+4 We add this statement. LIST LIST the program in your memory. '-. RUN- Now RUN the program. 1-8 Numerical Expressions The computer prints the value of a numerical expression as a decimal numeral. The following table shows examples of computerprinted values of numerical expressions. ' . EXPRESSION VALUE REMARKS 3.14 -123 3.14 -123 A decimal numeral is a decimal numeral 2+3+4 5-3+4 2*3*4 2*3/4 9" 6 24 1.5 2+3+4=5+4=9 5-3+4=2+4=6 2*3*4....:... 6*4 = 24 2*3/4 = 6/4 = 1.5 2*3 +4 2 + 3*4 35 - 2*3 112+3 2 + 3/4 24/2*3 10 14 29 3.5 2.75 36 2*3 + 4 = 6 + 4 10 2 + 3*4 = 2 + 12 14 35 - 2*3 35 - 6 = 29 1/2 + 3 = .5 + 3 3.5 2 + 3/4= 2 + .75 2.75 24/2*3 = 12*3 = 36 11(2+3) (2+3)/4 24/(2*3) .2 1.25 4 1/3 2/3 100/3 200/3 .3333333 .6666667 33.33333 66.66667 = = = = = = = . 11 (2 + 3) = 115 .2 (2 + 3)/4 5/4 1.25 24/ (2*3) = 24/6 =4 = Value rounded to seven significant digits. NOTES 1. The operations are done in left to right "order. 2. All multiplications and/ordivisions are done before any additions and/ or subtractions. To evaluate 24/2 *3 the computer first divides 24 by 2, obtaining 12. Then it mUltiplies 12 by 3, obtaining 36. 3. We use parentheses to modify the order in which operations are done. 1-9 NOTE 1. NOTE 2. NOTE 3. Your turn-but let someone else use the computer while you work the following exercises. Exercise 4. You are the guest star on the television program "Computer for a Day." To win the grand prize (7 microbucks) you must evaluate each of the following numerical expressions. Go! (1) 3*4+5 _ _ _ __ (2) 3 + 4*5 _ _ _ __ (3) 3/4 + 5 _ _ _ __ (4) 3 + 4/5 _ _ __ (5) 3*4/5 _ _ _ _ __ (6) 3/4*5 _ _ _ __ (7) 3*(4 + 5) _ _ __ (8) 3/(4*5) _ _ __ (9) 3/(4 + 5) _ _ __ (10) 3/4/5 _ _ _ __ Use your computer to check the answers. Did you win the prize? If not you can still win by finding a computer that evaluates numerical expressions the same way you do. Good lu~k! Exercise 5. Complete the following table showing BASIC expressions that correspond to given mathematical expressions. MATHEMATICAL EXPRESSION (1) 2 x 3 + 4 -:- 5 BASIC EXPRESSION 2*3 (2) 37(43 - 19) + 4/5 37*(43 - 19) (3) 3.14X 5 X 5 (4) 2 3+4 (5) 73 - 25 29 + 53 Back to the computer to check your answers. 1-10 The PRINT Statement Previously, we used PRINT-statements of the following form: . n where PRINT e n = line number e = numerical expression For example: 10 PRINT 3+4 Imenumber~ PRINT----------~ numerical expression _ _ _.....;.t A PRINT statement of this· form directs the computer to computethe value (simplest form) of the numerical expression e and to print the result on the Teletype. The following program illustrates a PRINT statement that has more than one numerical expression. SCR As usual, we first SCRatch any leftover program. 10 PRINT 3+4" 3-4" 3*4~ 3/4 99 END Next, we enter the program. The PRINT statement includes. four expressions. RUN Let's RUN the program. 7 -1 12 .75 Since the PRINT statement has four expressions, the computer prints four results. 1-11 A more general form of the PRINT statement is shown below. n PRINT - list of expressions For example, 10 PRINT 3+4" 3··4" 3*4" 3/4 line number -.J PRINT----.... list of expressions --------001 Remember these things: • A PRINT statement can contain more than one expression. • One result is printed for each expression in a PRINT statement. • If a PRINT statement contains more than one expression, then the expressions must be separated by commas. • Up to five (5) results per line are printed. If there are more than five expressions in -the PRINT statement, additional results are automatically printed on the next line; For example, the statement will cause the computer to print the following results. RUN 1 12 2.4 1-12 .15 6" I Exercise 6. Do not use the computer for this exercise. Instead, pretend that you are the computer and RUN each of the following programs. 10 PRINT 1,2,3,4,5,6,1,8,9,10,11, 12 99 END RUN 10 PRINT 1*2,2*3,3*4,4*5,5*6,6*1,1*8,8*9 99 END RUN Exercise 7. Each new PRINT statement causes a new line to be printed. RUN this program. 10 20 30 40 50 60 10 99 PRINT PRINT PRINT PRINT PRINT PRINT PRINT END 1,1*1 2,2*2 3,3*3 4,4*4 5,5*5 6,6*6 1,1*1 Once again ... Each new PRINT statement printed. causes a new line to be RUN 1-13 If we use a semicolon (;) instead of a comma to separate expressions, the results will be packed mor,e closely together. For example, try this one on your computer. SCR Goodbye, old program! 10 PRINT 3+4;3-4;3*4;3/4 Note the s(~micolons (;). 99 END Watch the spacing in the results be- low. The results are "packed" more closely together than if we had used commas. RUN 7 -1 12 .75 When we use semicolons to separate expressions, the computer will print up to 17 results per line. The actual number, however, depends on the number of digits that it must print. For example, 10 PRINT 1;2;3;4;S;6;7an9; H~ill; 12;1:3; 14: 15; 16; 17; lR.:19 99 END RUN 1 18 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 19 The first 17 results were printed on the first line - the 18th result on the second line. Let's see what happens as the numbers get larger. 10 PRINT 1112;123;1234'12345;123456;1234567 99 END RUN 1 12 123 1234 12345 1234056 1.234567E+06 This is a floating point numeral. We describe floating point numerals in the next section. 1-14 Remember these things: • If a PRINT expression, contains more than one expression, then the expressions must be separated by commas (,) or semicolons (;). • If commas are used for spacing, up to five results per line are printed. If semicolons are used, the results are ':packed" more closely together. The actual spacing depends on the size of the numbers involved. • If you want to find out more about spacing - experiment! EXPERlMEN~ Floating Point Numerals Floating point notation is similar to scientific notation. The computer does it this way. 10 20 30 40 50 60 70 PRINT PRINT PRINT PRINT PRINT PRINT PRINT 10 100 1000 10000 100000 1000000 10000000 In the program each number is expressed in "standard" or "common" notation. 99 END RUN 10 100 1000 10000 100000 1.000000E+06 1.000000E+07 The numerals are printed' in standard notation, exactly as they are written in the PRINT statements. But these are printed as {loating point numerals. 1-15 The following examples show the same number expressed in "standard" notation, scientific notation and floating point notation. If a number is larger than 6 digits, its numeral will be printed in floating point notation. STANDARD NOTATION SCIENTIFIC NOTATION 1000000· 10000000 100000000 1000000000000 1X 1X 1X 1X FLOATING POINT 1.000000E + 06 1.000000E + 07 1.000000E + 08 1.000000E + 12 106 107 lOS 1012 Let's see how BASIC handles small numbers. 10 PRINT .1 20 PRINT .001 30 PRINT .000000001 99 END RUN .1 If a number has more than 2 decimal places, its numeral is printed in floating point notation. 1.000000E-03 1.000000E-09 • Exercise 8. Complete the following table showing the numerals in scientific notation and standard notation corresponding to numerals given in floating point notation as they might be printed by the computer. FLOATING POINT 1.00000E + 09 SCIENTIFIC NOTATION 1 X 109 1 X 10-9 STANDARD NOTATION 1000000000 .000000001 1.00000E - 09 2.00000E + 09 2.00000E - 08 2 X 109 2 X 10-8 3.00000E + 12 6.02000E + 23 6.02 X 1023 2000000000 .000000000000000123456 1.23456E - 16 1-16 Printing Messages The PRINT statement in the following program directs the computer to print a message. The "message is enclosed in quotation marks. 10 PRINT "I LIKE PEOPLE" 99 END RUN Let's RUN the program. The computer types the message. I L IKE PEOPLE Here is another example. 10 PRINT ttGOOD MORNING" 99 END RUN GOOD MORN ING Unfortunately, if you RUN this program in the afternoon, the computer will still print GOOD MORNING The next example illustrates the difference between a numerical expression and the value of a numerical expression. 10 PRINT "3+4-",3+4 END 99 RUN 3+4= 7 This program directs the computer to print the message "3 + 4 =" followed by the value of 3 + 4. READY. 1-17 If you didn't like the spacing in the printed results, you can use a semicolon instead of a comma to control the spacing. 10 PRINT "3+4:";3+4 99 END RUN Semicolon spacing. 3+4:7 Exercise 9. You be the computer. RUN the following program without using the computer-you do the work and fill in the blanks. 10 PRINT "IF I WERE. A COMPUTER,," 20 PRINT "1·'0 DO ARITHMETIC LIKE THIS" 30 40 50 60 99 PRINT PRINT PRINT PRINT END "3+4.";3+4 "3-4-"J3-4 "3*4-"J3*4 "3/4-";3/4 RUN IF I WERE A COMPUTER" I'D DO ARITHMETIC LIKE THIS Your work is here. REMEMBER THIS: Anything enclosed in quotation marks in a PRINT statement is printed exactly as it appears. No arithmetic is performed. 1-18 Exponents-Computing a Power of a Number The following program illustrates a new idea power of a number. 10 PRINT "5*5-5.2-"J5'2 20 PRINT "2*2*2-2. 3-" ;2"3 30 PRINT ~3*3*3-3'4·"J3'4 computing a 99 END The t is on the bottom row of keys. Hold the SHIFT down when you wish to type t. RUN 5*5-5 '2- 25 2*2*2-2'3- 8 3*3*3-3'4- 81 We' use the t key when we want to. tell the computer to compute a power of a number. In math, we write 2 3 , but in BASIC we write 2 t 3. Remember· -BASIC notation is not math notation even though there are similarities. Here are some examples showing the values of expressions in which the t is used. EXPRESSION VALUE 2t5 3t2 + 4t2 (2 + 3)t4 32 25 625 REMARKS = = 2t5 2*2*2*2*2 32 3t2 + 4t2 = 9 + 16 25 (2 + 3)t4 = 5t4 = 5*5*5*5 = 625 = Exercise 10. Write the value of each expression. EXPRESSIO~ VALUE YOUR REMARKS It3 7t2 3t3 4t5 Unless parentheses are used to change the order, the computer does powers first, then multiplications and divisions, then additions and subtractions. (See Note 2, page 1-9.) 1-19 GATHERING SPEED Variables In mathematics, we have great freedom in selecting symbols to use as variables. We use the letters A - Z of our alphabet, the letters of the Greek alphabet and, in fact, any symbol that we may "invent" for this purpose. In BASIC, however, we must restrict you in your choice of symbols. For now, we impose this rule: A BASIC variable may be any letter of the alphabet. That is, any of the following may be used as a variable: ABCDEFGHIJKLM NOPQRSTUVWXYZ In BASIC, each variable refers to a distinct location in the computer's memory. It may help you to think of the computer's memory as a set of 26 boxes, labeled A through Z, like this: A H 0 V B I P W C -D J Q X K R Y E L S Z F M T G N U We call these boxes locations. Each location can hold one number at anyone time. This number is the value of the variable corresponding to the location. Exercise 11. LET A = 3. In other words, take pencil in hand and write the numeral "3" in the box labeled "A." Then do the following in similar fashion: (1) LET B =4 (2) LET P = 3.14 1-20 (3) LET Z =-1 The following example shows how we assign a value to a variable in a BASIC program. Assign the value 3 to the variable A. Print the value of A. 10 LET A-a 20 PRINT A 99 END RUN And here it is (the value of A, that is) . a A more general form of the LET statement is shown below. n where LET v e n = line number v = BASIC variable e = numerical expression " For example, Here is some additional evidence .. You may wish to RUN the following program. Don't forget to SCRatch! SCR 10 LET Aa.3· 20 LET' B-4 30 LET C-3+4 40 LET D-3-4 50 LET E-3*4 60 LET.F-3/4 7,0 LET 6-3'4 80 PRINT AJBICJDJEJFJG (Note.the semicolons.) :~~/l'\ 3 4 7-1 12 .75 81 1-21 Let's see what happens-blow by blow-.as the computer RUNs the program. Below is a trace of the program from the preceding page. The trace shows the value of each variable after the statement on the same line has been carried out by the computer. STATEMENT A B C D E P G 10 LET A = 3 3 20 LET B = 4 3 4 +4 3 4 7 40 LET D = 3 - 4 3 4 7 -·1 50 LET E = 3*4 3 4 7 12 60 LET F =3/4 3 4 7 -·1 _. 1 12 .75 70 LET G = 3 t4 3 4 7 -·1 12 .75 81 80 PRINT A'B'C'D'E'P'G , .' , , , , 3 4 7 -·1 12 .75 81 99 END 3 4 7 -1 12 .75 81 30 LET C = 3 The trace is an important idea-from now on, we will depend on it. Therefore, you had better learn how to (1) read a trace and (2) do a trace. .. Exercise 12. Trace the following program . STATEMENT P Q 10 LET P = 5 20 LET Q = -123 30 LET R 40 LET S = 57.3 = 2 *3 + 4* 5 50 PRINT P, Q, R, S 99 END 1-22 R S The LET statement directs the computer to compute the value of the expression to the right of the "=" symbol and assign this value to the variable that appears to the left of the "=" symbol. This value replaces any previous value of the variable. For example, REMARKS STATEMENT A 10 LET A = 1 1 Assign the value 1 to A. 15 PRINT A 1 Print the current value of A. 20 LET A = 2 2 Assign the value 2 to A. 25 PRINT A 2 Print the current value of A. 30 LET A = 3 3 Assign the value 3 to A. 35 PRINT A 3 Print the current value of A. 99 END 3 If we RUN the program above, we obtain the following results. RUN 1 2 3 Exercise 13. Without using the computer, RUN each of the following programs. (Fill in the blanks.) 10 LET X-3 20 LET X-S 30 LET X-7 40 PRINT X 99 END RUN 10 LET X-3 20 LET Y.S 30 LET Z-7 40 PRINT X;Y;Z· 99 END Rl,1N P.S. On EduSystems, you don't have to type the word LET in an expression. In other words, 10 A =1 is equivalent to 10 LETA = 1 To be consistent with Dartmouth BASIC, we'll use LET in this manual but you don't have to on your EduSystem. 1-23 Variable Expressions A variable expression is an expression that contains a variable. For example, the following are variable expressions: A-B A A/B 2*X -c P/Q + c/n A*(B + C) 3.14*R t 2. We evaluate a variable expression by assigning values to its variable or variables and carrying out-the indicated operations. For example, A *B is a variable expression with variables A and B. If A = 3 and B = 4, then the value of A*B is 12. But if A = -7 and B = 5, then the value of A*B is --35.' VARIABLE EXPRESSION A VALUE(S) OF VARIABLE(S) =3 = -123 A = 12 and B = 7 A A A-B A 4 X = 3.14 X =-6 2*X = P = 35 and Q 5 p= 2 and Q = 3 P/Q C=8 C=O c= -12 -C A*(B = 3 and B = + C) 3.14*R t 2 A = 3, B = 4, C = 5 R=3 1-24 VALUE OF EXPRESSION 3 -123 5 -1 6.28 -12 7 .666667-8 0 12 27 28.26 Each of the following programs directs the computer to evaluate one or more variable expressions and print the result or results. We use LET statements to assign values to variables. 10 LET A-3 20 LET a-4. 30 PRINT A*B 10 LET A-3 20 LET B-4 30 PRINT A+B 99 END 99: END RUN RUN 12 7 Exercise 14. Without using the computer, complete each RUN by filling the blank with the result. 10 LET A-3 20 LET B-4 30 PRINT AlB 10 LET A-3 20 LET B-4 30 PRINT A-B 99 END 99 END RUN RUN Exercise 15. The following program illustrates the use of variable expressions. Trace the program by filling in the blanks under the headings "A" through "G." PROGRAM A B 10 LET A= 3 20LETB = 4 30 LETC=A + B 40LETD=A-B 50LETE= A*B 60 LET F = AlB· 70 LET G·= AtB 80 PRINT A;B;C;D;E;F;G 99 END 1-25 C DEF G FEEDING THE BEAST The INPUT Statement In this section, we introduce a statement called the INPUT statement. But first, let's solve a problem that may point up the need for the INPUT statement. Problem. The area A of a circle of radius R is given by the formula: . where 7f' = 3.14 We want to use the computer to compute the areas of three different circles. These circles have radii R == 2, R == 3, and R ---:- 8. Here is a step-by-step description of how we could use a computerto solve the problem. seR First, SCRatch any old program. 10 LET R-2 20 PRINT R,3.14*Rt2 99 END Here is our program. It will work for R = 2. RUN Let's RUN it. 2 For R 10 LET R-3 Do NOT type SCR. Instead, enter a new Statement 10. RUN 3 28.26 For R = 2, the area is 12.56. = 3~ A = 28.26. 10 LET R-8 Again-change Statement 10. RUN And RUN the program. 8 200.96 For R 1-26 = 8, A = 200.96. We can reduce the amount of work required to solve the problem on the preceding page by using the INPUT statement. Here is a program that uses an INPUT statement to permit input ofa value of R. 10 INPUT,R 20 PRINT R,3.14*Rt2 We enter this program. And tell the computer to RUN it. 99 END t The computer types a question mark and stops. RUN 1 For a second, we sit and contemplate that question mark. What does the computer want? Of course! It wants a value for R. So we enter 2 as the value of R and press the RETURN key. The computer then prints 2 12.56 O.K., here is a RUN for R on your computer. = 2, R = 3 and R = 8. Try this one SCR SCRatch any previous' program. 1121 INPUT R 2121 PRINT R,3.14'*fif2 Enter the program. 99 END RUN RUN the program. 12 2 12.56 RUN 13 3 RUN, the program again. 28.26 RUN 18 8 Enter 2 and press RETURN. For R :::: 2, A := 12.56. Enter 3 and press RETURN. For R = 3, A = 28.26~ RUN the program again. 21210.96 Enter 8 and press RETURN. For R 8, A 200.96. = 1-27 = The general form of the INPUT statement is line number INPUT list of variables For example, 10 INPut A.. B,C line number INPUT list of variables Note that only the variables in the list are separated by com~as. There is no comma following the word "INPUT" and there is no comma after the last yariable in the list. The INPUT statement directs the computer to type a question mark and then stop and wait. Now you must understand that computers are very patient-if you don't cooperate, the computer will simply wait-and wait-and wait. To prevent this from happening, all you have to do is feed the computer-it's hungry-it wants data. Remember these things: • The INPUT statement causes the computer to type a question mark. • When the question mark appears, the pperator must enter one value for each variable in the INPUT statement. The values are entered in the same left to right order as the variables appear in the INPUT statement. o Don't forget to type commas between values. o After entering the last number, press the RETURN key. If you have done everything correctly, the computer will proceed. Here is another example. 17 INPUT A"B .. C 23 PRINT A*CB+C) 99 END RUN 13,,4 .. 5 27 Since there are three variables, we must enter three values. = If A 3, B A*(B + C) 1-28 = 4, C = 5, then = 27. Exercise 16. There is something wrong with each INPUT statement shown below. For each one, circle the mistake and write the reason. I~CORRECT STATEMENT REASON 10 INPUT ,A,B,C, 20 INPUT X,Y, 30 IMPUT P,Q,R,S,T 40 INPUT A+B 50 INPUT I;J;K 60 INPUT AA,BB, 70 INPUT AB C Exercise 17. We ran two simple programs. Here they are but some things are missing. Complete each RUN by filling in the blanks. 10 I NPUT A;B, C 20 PRI NT A .)0 PRI NT B, C 12 INPUT U,V,W,X 25 PRINT U,U+V 36 PRINT W,W*X 99£ND 99 END RUN 1-2,-3,-4 RUN 1_- 7 12 3 45 1-29 The GO TO Statement The following program appeared on page 1-27. 10 INPUT R 20 PRINT RI3.14*Rt2 99 END When we used it, we had to type RUN for each value of R. (See page 1-27.) To eliminate the need to type RUN for each new value of R, we add the following GO TO statement. 30 GO TO 10 (This directs the computer to "GO TO Statement 10.") Here is a RUN of the modified program. Try it on your computer. seR First, let's SCRatch. 10 1 NPUT R 20 PRINT R,3.14*Rt2 30 GO TO 10 99 END RUN Then enter the program. 12 2 13 3 18 8 1 12.56 28.26 200.96 Here is our GO TO statement. Now let's RUN the program. Each time after printing the results the computer does a GO TO 10 and automatically restarts at the INPUT statement. How do we tell the computer we are finished? Hold CTRL down, press C, and release. The computer will stop. 1-30 The GO TO statement has the general form line number GO TO line number The GO TO statement directs the com"" puter to GO TO the statement that has this 30 For example: GO TO 10 line number GO TO line number Exercise 18. Do not use the computer to answer this. If you were a computer and you came to the following statement, what would you do? . 115 GO TO 45 Exercise 19. Complete the following program to convert from degrees Centigrade to degrees Fahrenheit. In math notation, the formula is F 10 INPUT C =~ 'C + 32 (You write the formula-in BASIC.) 20 LET F- 30 PRINT C"F 40 PRINT 50 GO TO (00 TO where?) 99 END RUN 10 0 32 If C = 0, then F = 32. 1100 100 212 If C = 100, then F = 212. 137 37 (Hint: Body temperature) 1 Give F, what is C? 77 1-31 READ and DATA Statements Whenever possible, we prefer providing data (values of variables) by means of the READ and DATA statements. The following program is a modification of our "Area of a Circle" friend on page 1-26. 10 READ R 20 PRINT R,3.14*Rt2 This is a READ statement. 30 DATA 2,3,8 This is a DATA statement. 40 GO TO 10 99 END RUN Here are the results." On each line, the value of R is on the left and the value of the area is on the right. 12.56 28.26 200.96 2 3 8 DATA ERROR AT LINE 10 This message may be different or even omitted. It simply means that the computer has READ all the DATA. The statement 10 READ R tells the computer to read one value of R from the list of values in the DATA statement. Each time the READ statement is executed, the computer reads the next value from the DATA statement. In other word~, the computer remembers what values have already been read. . If there is no more data to be read in the DATA statement, the computer stops automatically. 1-32 Here is another example using the READ and DATA statements: Four students' named Frodo, Sam, G and alf, and Strider have each takep three quizzes. Their scores are: .. STUDENT FIRST SCORE SECOND SCORE THIRD SCORE Frodo 66 81 75 Sam 91 88 95 Gandalf 78 78 62 Strider 80 83 86 We have written a. program to compute the. arithmetic mean (average) of three scores and have run it for the above data. 10 20 30 40 90 91 92 93 99 READ XIY .. Z LET M-(X+Y+Z)/3 PRINT X.. YIZ .. M GO TO 10 DATA 66 .. 81 .. 75 DATA 91 .. 88 .. 95 DATA 78 .. 78 .. 62 DATA 80 .. 83 .. 86 END We use X, Y, Z to denote the first, second and third scores. Frodo's scores. Sam's scores. Gandalf's scores., Strider's scores. RUN 66 91 78 80 81 88 78 83 75 95 62 86 74 91.33333 72.66667 M ~ DATA ERROR AT LINE 10 , The averages of the three scores are in this column. DATA statements may be' placed anywhere in the program. They must, however, have line numbers smaller than the line number of the END statement. 1-33 The general form of the READ statement is For example: list of variables READ line number 10 READ X, Y, Z line number The variables are separated by [ commas. READ list of variables Exercise 20. There is probablyH something wrong with ~ach of the following READ statements. For each one, circle the mistake (if possible) and write the reason. INCORRECT STATEMENT REASON 10 READ, A,B,C 20 READX,Y 30 REED P,Q,R,S,T 40READA+B 50 READ I;J;K 60 READ AA,BB 70 READ ABC 80 READ 3.14 The READ statement directs the computer to read one value from the DATA statement for each variable in the READ statement. If there are two or more DATA statements in a program, the values in the statement with the smallest line number are used first, then the data in the statement with the next smallest line number and so on. 3 Depends on the system ... EXPERIMENT! 1-34 The general form of the DATA statement is: line number For example: line number 90 ,list of numerals DATA DATA 66, 81, 75 . J DATA··-- - _..... list of numerals _ _ _ _..I Expressions such as 2 + 3 are not allowed in the list. Exercise 21. There is something wrong with each of the following DATA statements. For each one, circle the mistake and write the reason. INCORRECT STATEMENT REASON 10 DATE 1, 2, 3,4 20 DATA 112,2/3,3/4 30 DATA A, B, C, D, E 40 DATA, 3.7, 2.9 50 DATA 3.7,2.9, The following three sets of DATA statements are equi\.:alent. 90 DATA 2,3,6,8, 12, 15, 19,27,33,26,47, 59 90 DATA 2,3,6 91 DATA 8,12,15; 19,27 92 DATA 33, 26, 47, 59 90 DATA 2, 3, 6, 8,12,15 91 DATA 19, 27, 33, 26,47, 59 That's right, the numerals in the list are separated by commas. 1-35 The RESTORE Statement The RESTORE statement allows you to reuse DATA statements, beginning with the lowest numbered DATA statement in the program. An example of the use of the RESTORE statement is shown below: 10 20 30 40 50 60 70 DATA 2,,3,,6 DATA 8,,12,,15 READ A"B .. C.. D· PRINT A"B"C"D RESTORE READ E"F PRINT E"F 99 END The RESTORE statement at line 50 allows the READ statement at line 60 to obtain values 'from the DATA statement at line 10 RUN 2 2 6 3 3 8 Without the RESTORE statement, an error message would have occurred, indicating a lack of data for the READ statement at line 60. ' Exercise 22. Without using -the computer, RUN each of the following programs. (Fill in the blanks.) If you wish, check your answers with the computer. 10 DATA 1,,2 20 READ A"B 30 PRINT A"B 40 RESTORE 50 DATA 3,,4 60 READ C.. D 70 PRINT C"D 99 END RUN 10 READ X 20 PRINT X 30 RESTORE 40 READ Z 50 PRINT Z 60 DATA 4 .. 1.. 2 70 DATA 3 .. 5 .. 7 99 END RUN 1-36 More Messages We can make the results more readable by including' a statement that causes the computer to print a heading. For example Print a heading. 5 PRINT "RADIUS"~"AREA" 10 READR 15 DATA 2~3 .. 8, 20 PRINT R~3\14*Rt2 25 GO TO 10' c 99 EN·D RUN RADIUS AREA 2 12.56 3 28.26. 8 200.96 DATA ERROR AT LINE.10 Exercise 23. Time to. play computer. Without using the com- . puter, RUN the following program. 10 PRINT "L·'~ "R" ~ "L* 10+Rtf~ "L*8+R" 13 READ L~R 21 PRINT L~R.L.10+R~L*8+R· 27 GO TO 13 85 DATA 0~7"1.0~1.1.1.1.;'2,,.e .. 1,,7 99 END Headings RUN Numerical results 1-37 Exercise 24. We have written a program to compute the a triangle, given the base B and the height H as data. AREA'" ~rea of t BH =BH/2 We want to complete the following table. B II 7 6 8 12 5 9 23 17 AREA Here is our program. Complete it by filling in the DATA stat.ement. Then, if you can get on the computer, RUN it and cqmplete the above table. 10 PRINT "B","H","AREA" 20 READ S,H 30 PRINT B~H,B.H/2 ~" GOTO 20 90 DATA 99 END 1-38 YOU CAN COUNT ON IT ~oops Let's teach the computer to count. That is, let's develop a program to direct the computer to generate and print consecutive counting numbers. The counting numbers are: 1, 2, 3,A, 5, 6, 7, 8, ... Here is our program and a RUN as evidence that it does what we claim. Beware! If you RUN the following program, you may have trouble stopping the computer. Check with someone who knows how to interrupt your computer. 10 LET K:1 20 PRI NT K 30 LET K :K+l 40 GOTO 20 Assign the value 1 to K. Print the current value of K. Increase the vf\lue of K by 1. Go around again. 99 END RUN Let's RUN the program. I 2 3 4 5 6 7 If we don't interrupt the computer, it will go on and on-printing counting numbers. We· can interrupt the computer by holding the CTRL key down and pressing C. and so on. The above program contains a loop. The loop is described below. 10 LET K-1 20 PRINT K 30 LET K-K+l 40 GO TO 20 99 END This is a loop. The statements in the loop are repeated indefinitely. Each time through the loop, the current .value of K is increased by 1 and the loop is repeated. 1-39 If you are confused by the statement 30LETK BEFORE =K + 1 STATEMENT AFTER K 1 30 LET K=K+ 1 K 2 K 2 30 LET K=K+ 1 K 3 K 3 30 LET K=K+ 1 K 4 Remember the general form of the LET statement. line number LET variable expreSSIOn The expression may be any BASIC expression. The LET statement directs the computer to evaluate the expression and then assign the value to the variable. If the-expression is a' variable expression, it is evaluated using the current values of its variable or variables. Therefore, the statement LET K = K + 1 directs the computer to evaluate the expression K + 1 using the current value of K and then assign the new value to K. Exercise 25. Show the value· of the variable after the statement has been executed. STATEMENT BEFORE AFTER K 25 30 LET K·= 1 K E 6 40 LET E=E+2 E 1-40 Loops Exposed In order to clarify what happens as the computer executes the program, we will "unwrap" the loop and trace it. The following trace shows the value of K following the execution of each statement in the program. Under the heading "OUTPUT" we also show results printed by the computer. We have traced the program seven times through the loop. Study this trace carefully. We will ask you to do several such traces. STATEMENT K 10 LET K = 1 1 OUTPUT REMARKS 20 PRINT K 1 30 LET K=K+ 1 2 40 GO TO 20 2 1 First time through the loop. 20 PRINT K 2 30 LET K=K+ 1 3 40 GO TO 20 3 2 Second time through the loop. 20 PRINT K 30 LET K = 1 +1 40 GO TO 20 3 4 4 3 Third time through the loop. 20 PRINT K 4 30 LET K=K+ 1 5 40 GO TO 20 . 5 4 Fourth time through the loop. 20 PRINT K 5 30 LET K=K+ 1 6 40 GO TO 20 6 5 Fifth time through the loop. 6 20 PRINT K 30 LET K=K+ 1 7 7 40 GO TO 20 6 Sixth time through the loop. 7 20 PRINT K 30 LET K ,= K + 1 8 40 GO TO 20 8 7 Seventh time through the loop. and so on! 1-41 Exercise 26. Without using the computer, show the first five results printed by the computer under control of each of the following programs. (Fill in the blanks.) 10 LET X-I 20 PRINT X 30 LET X-X+2 40 GO TO 20 99 END 10 LET E=2 20 PRINT E 30 LET E=E+2 40 GO TO 20 99 END RUN RUN and so on. and so on. Exercise 27. Complete each program (fill in the blanks) so that when we run the program, the computer will produce the results shown. 10 LET J20 PRINT J 30 LET J. 12 LET P- 25 PRINT P 33 LET p. 40 GO TO 20 41 GO TO 99 END 99 END RUN RUN 0 1 1 2 2 4 3 4 8 16 and so on. and so on. 1-42 Exercise 28. This is a trace of one of the programs shown in Exercise 26. Complete the trace for three times through the loop. '. STATEMENT X 10 LET X = 1 . 1 20 PRINT X 30 LET X=X+2 40 GO TO 20 1 3 3 OUTPUT REMARKS First time through loop. 1 20 PRINT X 30 LET X=X+2 40 GO TO 20 Second time. 20 PRINT X 30 LET X=X+2 40 GO TO 20 Third time. 20 PRINT X and so on. Fourth time and we quit! Exercise 29. Here are two variations on previously written programs. For each one, show -the first four results. 1,0 LET K-0 20 30 40 99 LET K-K+l 'PRINT K GO TO 20 END RUN and so on. 10 20 30 40 99 LET K-l PRINT 2*K LET K-K+l GO TO 20 END RUN and so on 1-43 Exercise 30. Trace the following program four times through the loop~ 10 LET A-I 17 LET B-1 25 30 36 43 LET C-A+B PRINT A LET A-S LET Bille 50 GO TO 25 99 END STATEMENT A B REMARKS C These statements are done once. 10 LET A= 1 17 LET B = 1 25 30 36 43 50 LET C=A+B PRINT A LET A=B LET B =C GO TO 25 First time through loop. 25 30 36 43 50 LET C=A+B PRINT A LET A=B LET B = C GO TO 25 Second time through loop. 25 30 36 43 50 LET C=A+B PRINT A LET A=B LET B =C GO TO 25 Third time through loop. 25 30 36 43 50 LET C=A+B PRINT A -LET A=B LET B = C GO TO 25 Fo~rth 1-44 time through loop. FOR-NEXT Loops The loops we have used so far do not terminate by themselves. They go on, and on, and on .... until someone manually interrupts. Now let's look at a loop that terminates automatically. This loop makes use of two new statements caned the FOR statement and NEXT statement. 10 FOR Ka1 TO 5 20 PRINT K 30 NEXT K We call this a FOR-NEXT loop. 99 END RUN .Let's Run it and see what happens. 1 2 3 We did not interrupt. The computer stopped cally. 1& 5 automati~ Perhaps the following trace will help you understand how a .FOR-NEXT loop works. STATEMENT K OUTPUT REMARKS 10 FOR K = 1 TO 5 1 20 PRINT K 30 NEXT K 1 2 1 First time through loop. K~ 5. Do it again. 20 PRINT K 30 NEXT K 2 3 2 Second time through loop. K ~ 5. D it again. 20 PRINT K 30 NEXT K 3 4 3 Third time through loop. K ~ 5. Do it again. 20 PRINT K 30 NEXT K 4 5 4 Fourth time through loop. K ~ 5. Do it again. 20 PRINT K 30 NEXT K 5 6 5 Fifth time through loop. K> 5. Stop the loop! 99 END 6 K starts at 1. . Everything stops. 1-45 A FOR-NEXT loop consists of three things. 1. A FOR statement 2. A NEXT statement 3. A set of statements between the FOR statement and the NEXT statement. A FOR-NEXT loop begins with a FOR statement and ends with a NEXT statement. The set of statements between FOR and NEXT is called the body of the loop. Here is a "pictorial" representation for a FOR-NEXT loop. 10 FOR X _ l : 12 :J0 The same variable must be used in both places. body of the loop 50 NEXT X Here is another example. I 10 20 30 99 FOR N-2 TO 7 PRINT N NEXT N END This FOR statement defines a set of values for N. The set is: [ 2, 3, 4, 5, 6, 7 ] RUN 2 ... 3 4 _ 5 6 7 ....- - - -...... The body of the loop is executed repeatedly, once for each value of N defined by the FOR statement. Every FOR statement must have a NEXT statement and every NEXT statement must have a FOR statement. Has it occurred to you that the value of tht;: variable increases by one each time throu'gh,the loop? 1-46 Exercise 31. In each program, circle the body of the FORNEXT loop. 10 PRINT "RADIUS","AREA" 20 FOR R-2 TO 4 30 PRINT R,3.14*Rt2 40 NEXT R 10 20 25 30 40 99 END RUN . RADIUS 2 3 4 PRINT ,"RADIUS··,"AREA" FOR R-2 TO 4 LET A-3.14*Rt2 PRINT R,A NEXT R 99 END AREA 12.56 28.26 50.24 RUN RADIUS AREA 12.56 28.26 50.24 2 3 4 Remember these things. • The FOR statement defines a set of values for the variable. • The body of the loop is executed for each member of the set. • The NEXT statement causes the body of the loop to be executed again, using the next member of the set. However, if all members of the set have already been used, then the NEXT statement directs the computer to move on to the statement following the NEXT statement. The following shows the set of values defined for the variable in each example of a FOR statement. We have omitted line numbers. FOR Statement Variable Set of Values for the Variable FOR J = 0 TO 3 J [ 0, 1, 2, 3 ] FOR 1=1 TO 1 I [ 1} FOR A= 3 TO 5 A [ 3, 4, 5 } FOR X= -2 TO 2 X [ -2, '-1,0, 1, 2 } FOR B = 1 TO 0 B Empty - the loop is skipped. Do you see a pattern? Try the following exercises. 1-47 Exercise 32. Complete the following table. FOR Statement Variable FOR N == 1 TO 6 N FOR C = 0 TO 5 .C Set of Values for the Variable FOR W=-3 TO 0 FOR E= 12 T0.12 FOR T=7 TO 5 The next three are tricky. Be brave-guess! FOR X =.5 TO 2.5 FOR Y = 1 TO 2.5 . FOR Z=.5 TO 3 Exercise 33. Time to play computer. RUN each program as if you were the computer. 10 fORX=2 TO 4. 20 PRI NT X,X*X 30 NEXT X· 99 END RUN 12 fOR K:1 IO 3 23 LET P:2tK 30 PHI NI K,P 37 NEXT K 99 END RUN 1-48 Instead O'f using the cO'mputer to' grind O'ut numbers, let's use it to' print patterns. 10 FOR Kal TO 8 20 PRINT "**********" 10 FOR K-l TO 7 20 PRINT "XOXOXOXOX" 30 NEXT K 99 END NEXT.K END 30 99 RUN RUN ********** ********** ********** ********** ********** ********** ********** ********** xoxoxoxox XOXOXOXOX XOXOXOXOX xoxoxoxox XOXOXOXOX XOXOXOXOX XOXOXOXOX 10 PRINT "XXXXXXXXX" 20 FOR Kat TO 5 10 FOR K-I TO 3 20 PRINT "+-+-+-+-+-+-+" 30 40 99 30 PRINT "XOOOOOOOX" 40 NEXT K PRINT "-+-+-+-+~+-+-" NEXT K END 50 PRI NT "XXXXXXXXX" 99 END RUN XXXXXXXXX XOOOOOOOX RUN +-+-+-+-+-+-+ -+-+-+-+-+-++-+-+-+-+-+-+ -+-+-+-+-+-+_. +-+-+-+-+-+-+ -+-+-+-+-+-+- xooooooox xooooooox XOOOOOOOX xooooooox XXXXXXXXX Exercise 34. Write a program to' generate each pattern . . ******* * * * * * * * * * * * * * * ******* +-+-+-+-+-+-+ -+-+-+-+-+-++-+-+-+-+-+-+ -+-+-+-+-+-++-+-+-+-+-+-+ -+-+-+-+-+-++-+-+-+-+-+-+ -+-+-+-+-+-++-+-+-+-+-+-+ 1-49 . The STEP Clause A variation of the FOR statement is shown in the following program. 10 FOR K-I TO 9 STEP 2 20 PRINT K 30 NEX1' K Note the STEP clause. 99 END The STEP 2. clause causes the value of K to increase by 2 each time. You can verify this by examining the printed results. RUN I 3 5 7 9 The following shows the set of values defined for the variable in each FOR statement. We have omitted line numbers. FOR Statement Values of the Variable FOR E = OTO 10 STEP 2 E= 0, 2,4,6, 8,10 = 0 TO 11 STEP 2 E= 0, 2,4,6, 8,10 FOR E = 1, 1.5,2, 2.5, 3 W = 1,1,1, ... FOR X = 1 TO 3 STEP.5 X FOR W = 1 TO 7 STEP 0 Exercise 35. Complete the following table. FOR Statement Values of the Variable FOR T = OTO 6 STEP 3 T= FOR N = 1 TO 5 STEP 1 N=, FOR K = 100 TO 130 STEP 10 FOR X = OTO 1 STEP .25 K= X= Now--be careful on the next two! FOR E = OTO 0 STEP 2 E= FOR B = 3 TO 0 STEP-l B= 1-50 In the following example, we use a space-saving trick. 12 t.B'R X-0 TO 12 STEP 2 23 PRINT X, 35 NEXT X 99 END RUN o 10 2 12 " Aha! Note the comma. 6 II 8 Exercise 36. If the PRINT statement ends with a comma, results are printed across the page, with up to five results per line. Here is another example-we call it program COUNTDOWN. 10 20 30 40 50 60 70 FOR N=10 TO 1 STEP -1 PRINT N.. NEXT N PR):NT "BLAST-OFF I I." FOR K-l TO 55 PRINT ">"J NEXT K 99 END A semicolon to the rescue~. , RUN 10 5 9 4 8 3 7 2 6 1 BLAS]" -0 FF I I I »»»»»»»»»»»»»»»»»»»»»»»»»>,»» 1-51 Be sure to RUN this program on your computer. Variable FOR Statements By using variables instead of numerals, we obtain variable FOR statements such as the one in the following program. 10 INPUT N .....~7.::::====Seeit! 20 fOR K=ITO N ..... 30 PRI NT K 40 NEXT K 50 GOTO 10 99 END Variable FOR-NEXT loop. N_-----------We =3 = enter RU ... 13...... 1 2 3 ------------- 3, K 1, 2, 3. _ We enter 5 as the value of N. 15.-4 1 For N as the value of N. 2 3 For N = 5, K = 1, 2, 3,4, 5 We enter 0 as the value of N. The FOR loop is skipped because "10 1 5 >N. and so on. Change one statement in the above program. 1 NP U T N Here is the change. . FOR K=1 TO N ~ PRI NT .. *"~ ---And we added this statement. NEXT K · . If you want to know why, RUN PRI NT the program without it. 50 GOTa 10 99 END We enter 3 as the value of N. 10 20 30 4£1 45 RUN 13 *** 17 ******* and so on. And the computer prints 3 asterisks. We enter 7 as the value of N. And the computer prints 7 asterisks. Carryon-you pick the value of N. 1-52 Another example. Study it carefully. 10 INPUT A.. B 20 FOR X-A TO B 30 PRINT XJ 40 NEXT X 50 PRINT 60 GO TO 10 , The semicolon packs 'em in. 99 END RUN 13 .. 8 3 4 5 678 3 4 11 .. 13 1 2 5 6 7 8 9 10 11 Let's trace the above program for- A 13 = 3, B = 8. OUTPUT STATEMENT A B· 10 INPUT A, B 3 8 == A TO B 3 8 3 8 8 3 4 3 40 NEXT X 3 3 30 PRINT X; 40 NEXT X 3 3 8 4 4 8 5 30 PRINT X; 40 NEXT X 3 3 8 5 6 5 30 PRINT X; 40 NEXT X 3 8 6 3 8 6 7 30 PRINT X'; 40 NEXT X 3 8 7 7 3 8 8 30 PRINT X; 40 NEXT X - 3 3 8 8 8 9 Sixth time X> B. Stop the loop! 50 PRINT 60 GO TO 10 3 3 8 9 A carriage return 8 9 and a line feed. 10 INPUT A, B and so on, 20 FOR X 30 PRINTX; X 12 8 1-53 REMARKS First time X~B Second time X~B Third time X~B Fourth time X~B Fifth time X~B 8 Exercise 37. The following program directs the computer to compute and print the sum and the arithmetic mean of N numbers. Trace it. 1" READ N s." 2" LET 30 FOR K-l TO-N The value of N is in Line 90. "" READ X The values of X are in line 91. 50 LET S-S+X 60 NEXT K 70 PRINT N~S Here is the value of N. (See Line 10.) And here are the values of X. Note that there are N values. .. S/N 90 DATA 3 91 DATA 87 .. 73 .. 95 99 END STATEMENT N s K X OUTPUT 10 READ N 20 LET S= 0 30 FOR K = 1 TO N 40 READ X 50LETS=S+X 60NEXTK 40 READ X 50LETS = S + X 60NEXTK 40 READ X 50 LETS = S+X 60NEXTK 70 PRINT N, S, SIN 99 END Exercise' 38. How would you modify the two DATA statements to compute the mean of the numbers: 75, 66, 83, 75, 98? 90 DATA 91 DATA 1-54 Extra for Experts The examples on this and the following page may help you discover more things about the FOR statement and how it is used. We also encourage you to experiment-tryout your own ideas on the computer. You may wish to guess how something works and then try it out. \ 10 INPUT A,B,H 20 PRINT. "RADIUS","AREA" 30 FOR R-A TO B STEP H 40-PRINT R,3.14*Rt2 50 NEXT R 55 PRINT 60 GO TO 10 Compare! 99 END RUN 12,8,3 RADIUS 2 (A= 2, B AREA 12.56 The value of R is stepped from 2 to 8 in steps of. 3. 78.5 5 8 = 8 and H = 3) 200.96 Another example-another idea. 10 20 30 40 50 60 READ N FOR K-N*N TO N*CN+l) PRINT KJ NEXT K PRINT GO TO 10 90 DATA 3,7 We can use any BASIC expression. Note the semicolon. Causes a line space. That is, prints a blank line since there is no list following the word PRINT.. 99 END RUN 9 49 10 11 11· 50 51 52 53 54 55 DATA ERROFf, AT LINE 10 1-55 56 Results for N = 3 Results for N = 7 We can have a loop within a loop. 10 PRINT ·'I""nJ9' 15 PRINT 20 FOR 1·-1 TO 2 30 FOR J-l TO 3 ] ] --Inside loop 40 PRINT I"J 50 NEXT J 60 NEXT I 4!II...... -41.. __-- Outside loop 99 END RUN 1 J 1 1 1 2 2 2 i J.. ~1 ] Inside loop .......- - - Outside loop ..... -..-- Inside loop We can use a loop within a loop to print a pattern of M rows with N asterisks in each row. ~--N asterisks per row ...... 11-- M rows Try this program without the PRINTS in Lines 60 and 80. (7 rows, 12 asterisks per row) Here they are. Seven rows of aster.....- - - - - isks with 12 asterisks in each row. 1-56 FUNCTION JUNCTION The Integer (INT) Function The integer (INT) function returns the value of the nearest integer not greater than x. Let's see how it works. 10 PRINT INT(0)~INT(1)~INT(e)~INT(3.14)~INT(7.99) 99 END RUN o e 1 3 7 From the results, we see that: INT(O) = 0 INT(3.14) = 3 INT( 1.) = 1 INT (7.99) = 7 . INT(2)= 2 Here are some rules you can count on. • If X is a whole number, then INT(X) = x. .For example, INT(O) = 0 INT(2)= 2 INT(I)= 1 INT(3)= 3 • If X is a positive number or zero, then INT(X) is the whole number part of X. For example, INT( 123.45) = 123 INT(.75) = 0 INT(2.99) = 2 INT(O.75) = 0 Exercise 39. Complete the following. (1) INT(4) = _ _ __ (2) INT(12345) = _ __ (3) INT(O.999999) = _ _ 4 (4) INT(27.0l) = _ _ (5) INT( 12/4) = 4 (6) INT(13/5) = ___ 4 Evaluate the numerical expression first, then apply the INT function to the result. . 1-57 The INT function is useful in solving problems such as the fol- . lowing. Let a be a whole number and let b be a natural number. Divide b into a to obtain a whole number partial quotient, q, and a whole number remainder, r. For example, let a = 28 and b = 7. Partial quotient, q 4 7 = 4. (28 28 o Remainder, r = O. Next let's try a = 97 and b =5~ 19 Partial quotient, q = 19. 5(97 5 47 45 2 Remainder, r = 2. . Once more - this time a = 29 and b = o 32. Partial quotient, q = O. 32/29 o Remainder, r 29 = 29. - We can write a mathematical sentence relating a, b, q and r, as follows. a = bq For example, +r where 0 97 ~ r < b. = 5 x 19 + 2 a= b xq 1-58 +r Note that r < b. Let's solve for r: r =a - bq And let's remember that q is the whole number part of a/b. Here is a program to compute q and r given input values of a and b. 10 PRINT ··A"~"B··~"Q"~"R" • 20 READ AlB 30 LET Q-INTCA/B) 40 LET R-A-B*Q 50 PRINT AIB~Q~R . 60 GO TO 20 70 DATA 281719715~29132 99 END Note how we compute q and r. RUN B A 28 Q 97 7 5 29 32 R 01 2 4 19 o 29 DATA ERROR AT LINE 20 Exercise 40. Complete the following trace of the RUN of the preceding program. STATEMENT . 10 PRINT "A","B","Q","R"· 20 READ A,B 30 LET Q INT (AlB) 40 LET R A - B *Q 50 PRINT A,B,Q,R 60GO TO 10 = = A B 28 28 28 28 28 20READA,B 30 LET Q INT(A/B) 40 LET R A - B *Q 50 PRINT A,B,Q,R 60 GO TO 10 = = 20 READA,B 30 LET Q INT(A/B) 40 LET R A - B *Q 50 PRINT A,B,Q,R 60GOTO 10 = = and so on. 1-59 7 7 7 7 7 Q 4 4 4 4 OUTPUT R 0 0 0 A B Q R 28 7 4 0 Exercise 41. Let x be a 2-digit whole number. That is, x is a whole number such that: 10 ~ x ~ 99 We define a number y as follows. y = sum of the digits 'of x. For example, = 10, then y = 1 + 0 == 1 if x = 25, then y = 2 + 5 =: 7 if x = 99, then y = 9 + 9 =: 18 if x Complete the following program to compute y for a given value of x. RUN it for the DATA shown. 10 20 30 40 50 70 80 90 READ X PRINT X"Y GO TO 10 DATA 10,,15,23,,37,,40,,99 99 END Exercise 42. Let z be the number obtained by reversing the digits of x. For example: = = if x 10 then z = 01 if x = 37 then z = 73 if x 99 then z 99 =1 = Modify your program of Exercise 41 so that the computer computes the value of z instead of the value of y. EXPLORE! Try the INT function on negative numbers (non-integers as well as integers). Can you give a general definition of the INT function? 1-60 The Square Root (SQR) Function We assume that you know how to compute square roots of numbers. Let's find out. Exercise 43. Complete each of the following: 1. A square root of 4 is _--'--______________ 2. Another square root of 4 is ______________ Here is how we instruct the computer to compute square roots. 10 PRINT 99 END SQR(4)~SQR(25)~SQR(100),SQRC0) RUN 10 5 o If X is any non-negative number (positive or zero), then SQR(X) is the non-negative square root of X. If you try to take the square root of a negative number, you may obtain an error message. 10 PRINT SQRC-4) 99 END Note the error message. RUN ARGUMENT ERROR AT LINE 10 The symbol SQRO which we use in BASIC corresponds to the symbol r" which we use in mathematics. Perhaps you recall that, is used to mean the non-negative square root of a. -Va is used to mean the negative square root of a when a >,0. 1-61 Here is a program to compute the two square roots of a. 10 20 30 99 INPUT A PRINT SQRCA),-SQRCA) GO TO 10 END RUN 14 -2 2 14096 64 10 o 12 1.414214 -64 o -1.414214 By using the FOR-NEXT root table. 10 20 30 99 If a = 0, there is no negative square root. These answers are approximations to the square roots of 2. loop~ you can build your own square FOR X-I TO 10 PRINT X,SQR(X) NEXT X END RUN 1 2 3 4 5 6 7 8 9 10 1 1.414214 1.732051 2 2.236068 2.44949 2.645751 2.828427 3 3.162278 To obtain the square root table of your choice, modify the FOR statement. Exercise 44. How would you write the FOR statement to obtain a square root table with values of X running from 0 to 1 in STEPS of.2? 1-62 If we know the lengths of two sides of a right triangle, we can compute the length of the third side by applying the Pythagorean theorem. For example, suppose c.is the length of the hypotenuse and a and b are the lengths of the other two sides, as indicated in the diagram. Given a and b, we want to comp~te c. C=,Ia>+~b a Let's use the computer. 10 20 30 40 90 99 READ A"B LET C-SQRCAt2+Bt2> PRINT A"B"C GO TO 10 DATA 3,,4,,12,,5,,1,,1 END {Data for 3 triangles) RUN 3 4 5 12 5 1 13 1 1.~14214 DATA ERROR AT LINE 10 From the results we see that If a = 3, b = 4 then c == 5 If a = 12, b = 5 then c = 13 If a= 1, b = 1 then c = 1.41421 Exercise 45. Suppose we know the values of c and a. You write the program to compute and print the value of b. Then use your program to obtain the value of b for each of the _following. 2 - 1-63 LOOK BOTH WAYS LOOK BOTH WAYS Look back-where have we been? Loops SCR FOR NEXT SQR expressions LET INPUT variables INT LIST + floating point * t READ PRINT messages RESTORE END DATA RUN Look ahead-more BASIC-·where will it lead? IF RND < > ABS COS STOP ATN REM RETURN ON ... GOTO Subscripted variables SGN DIM Arrays flow charts DEF 1-64 LOG TAN GOSUB SIN EXP FINDING YOUR WAY Flowcharts A flowchart is like a road map. A road map helps you find your way through unfamiliar terrain-a flowchart helps you find your way through a computer program. If you want to, use a road map, you must learn how to read it-true also of a flowchart. We will start with easy flowcharts and show you how to r.ead them. Here is a flowchart of'a program to generate 'counting numbers. When you read a program follow the line numbers. When you read a flowchart, follow the arrows. 10 LET K-l 20 PRINT K 30 LET K-K+l 40 GO TO 20 99 END ,;' ,,;' ./ /' /' ./ Note that this arrow corresponds to the GO TO statement. In this flowchart there is no box corresponding to the END statement. If you prefer, you can draw horizontal flowcharts instead of vertical flowcharts. I LETK=1 ~4. . _L_E_T...,K_r--K_+_'_~1 ~31 "..--..., 1-65 Here is a flowchart with an END box. LET R=3 H LET A-3.14*R'2 ~10-LE-!~R-_3~ ~ ~ PRINT R,A ~ 20 LET A-3.14*Rt2 ' 30 PRINT R,A------------~ 99 END--------------------------~ In the above flowchart, we showed the END box because it is actually executed in the program, causing the computer to stop. What next? An INPUT box. 10 20 30 40 INPUT R LET A-3.14*Rf2 PRINT R,A GO TO 10 99 END \ This END is never actually executed by the computer; so we don't show it in the flowchart. Note the shapes of the boxes used in the :Ilowchart so far. 5 From now on, we will usually omit this reminder. 1-66 Confused? More examples may help. 13 INPUT A,B LET Q-INTCA/B) 37 LET R=A-B*Q 2~ ~3 PRINT A,B,Q,R 52 GO TO 13 99 END RUN 779,12 79 12 6 7 7 ? and so on. To save space, we might do the above flowchart like. this I or like this J INPUT A,B We simply put two LET statements in one LET box in order to save space. If there are two or more statements in a box, execute them in order from top to bottom. 1-67 Exercise 46. Below are flowchart boxes in the order in which we introduc.ed them. Note the shape and write the type of box (INPUT, END, LET, etc.) beneath each shape. ~ 0 C _ _) How do we indicate a GO TO statement in a flowchart? ---- .. Exercise 47. Complete the flowchart of the following program. C--,-_ 10 INPUT AID 20 PRINT A 30 LET A-A+D 1&0 GO TO 99 END 20 Exercise 48. Write the program that corresponds to the following flowchart. Use our line numbers. 12 ----------------------- 24 ---------------------------------------------------48 -------------------------36 60 ----.-------------------- 99 LET K= K+1 What does the program do? That is, what does it direct the computer to do? Predict the results, then RUN the program on the computer. 1-68 We use the same box shape for READ as we do for INPUT. But there is no flowchart box corresponding to a DATA statement. 10 READ A~B 20 LET C-A*B 30 PRINT A,B .. C 40 GQ TO 1090 DATA 3~I&~S~-7 99 END RUN 3 5 1& 12 -7 -35 DATA ERROR AT LINE 10 - Let's put the computation directly into the PRINT statement (program) or the PRINT box (flowchart). 10 READ X,N 20 PRINT X~N .. X+N 30 GO TO -10 60 DATA 2 .. 3,10,10 99 END RUN 2 10 3 10 5 20 DATA ERROR AT LINE 10 Remember: Use C ______) 1-69 for either INPUT or READ. Messages? How do we show them in a flowchart? Easy . . . 10 PRINT "GOOD MORNING t ' 99 END Note the quotation marks. Another example10 20 30 40 50 PRINT "RADIUS", t'AREA" READ R PRINT R,3.11&*Rt2 GO TO 20 DATA 2,3,8 99 END RUN RADIUS AREA 12.56 28.26 200.96 2 3 8 DATA EUROR AT LINE 20 If you don't like OUf style of flowchart, invent your own. Like ... ~~CATCH ANSWER 1-70 - FOR-NEXT Loops in a Flowchart , Remember FOR-NEXT loops? We show them in a special way in a flowchart. 10 FOR Klill TO 5 - FOR - 20 PRINT KJ K =1 TO 5 30 NEXTK 99 END RUN PRINT K 1 2 3 La 5 NEXT K Another one-this time with a STEP clause. 10 FOR E-e TO 10 STEP 2 PRINT E 39 NEXT E 99 END FOR 26 E-0 TO 10 STEP 2 RUN PRINT 'E o 2 1.& 6 8 I NEXT E 10 We include the END box in the flowchart above because it is actually executed-stopping the computer after all numbers specified by the FOR-NEXT loop have been printed. 1-71 Exercise 49. <;omplete the flowchart of the following program. 10 INPUT A.,.B"H 20 FOR X=ATO B STEP H 3~ PRINT X 40 NEXT X 50 GO TO 10 99 END Exercise 50. Draw··a flowchart of the following program. Draw your flowchart here. ~ 10 20 30 49 50 INPUT N FOR Kul TO N LET P-KtK PRINT K"P NEXT K 99 END RUN 15 1 2 3 1& 5 1 4 27 256 3125 K t K increases rapidly, doesn't it?! 1-72 MAKING DECISIONS A Fork in the Road The road divides into two paths ... which way? < ... This way? --------< , or this way? You must decide; In a flowchart we use a diamond shaped box to indicate a decision point based on a condition. One arrow into the box We write the condition inside the box. YES Two arrows out of the boxone labelled "YES" and. one labelled "NO" NO The condition in the box must have exactly two possible outcomes. • If the condition in the box is TRUE, follow the arrow labelled YES. • If the condition is FALSE, follow the arrow labelled NO. Examine the condition in the decision box above and complete the following table showing which path to follow for given values of A andB. Value of A 3 Value of B o 4 2 7 1 ,-1 -2 -1 5 7 o Which Path? (YES or NO) 1-73 Which is larger, 3 or 41 Which is larger, 5 or 21 If A = 3 and B = 4, which is larger, A or B1 If A = 5 and B = 2 which is larger, A or B1 .._ _ _ _ _ __ In the flowchart below, trace the path for A = 3, B = 4 and the path for A 5, B 2. You may wish to mark these paths in two different colors. = = PRINT A The flowchart directs the computer to print the larger of two numbers, A and B. = Suppose you mark the path for A 3, B =: 4 with a red pencil and the path for A 5, B 2 with a green pencil. Which path would we follow (red or green) if = = = 0, B = 21 _ _ _ _ __ A = 7, B:= 71 _ _ _ _ _ _ _ A = - 1, B == =- 21 _ _ _ __ A = 1, B = 01 ____ ._ _ _ A Let's translate the flowchart into a BASIC program. 1-74 ~ 10 INPUT A,B 20 IF A>B THEN 50 ~---t 30 PRINT B~ 40 GO TO 10 . 50 PRINT A 60 GO TO 10 99 END This is an IF statement. It corresponds to a decision box in a flowchart. ... Fol1ow me if and only if A> B. Prove it! RUN the program. RUN 13,4 4 15,2 5 If A A =3,B.=4. JJ is larger than A. A = 5, B = 2. A is larger than B. = 3 and B = 4 the computer executes statements 10, 20, 30 and 40. If A = 5 and B = 2 the compu.er executes statements 10, 20, ~ 50 and 60. Let's trace the program. We follow the computer as it executes each statement and show the values of A and B after each statement is carried out. For a PRINT statement, we also show what is printed under the heading "OUTPUT." STATEMENT A B OUTPUT 10 INPUT A,B 3 4 20 IF A> B THEN 50 30PRINTB 3 3 4 4 4000 TO 10 10 INPUT A;B . 5 2 20 IF A> B' THEN 50 50 PRINT A 5 5 2 2 60 GO TO 10 10 INpUT A,B 7 7 20 IF A>B THEN 50 30 PRINT B 7 7 7 7 ? REMARKS = 4 5 First case: A 3, B = 4. A>B is FALSE. Continue with Statement 30. Go around again. Second case: A = 5, B=2. A>B is TRUE. Go to Statement 50 and proceed. Go aroul1d again. Third case: A 7, B = 7. A>B is FALSE. Continue with Statement 30. = 40 GO TO 10 and so on. 1-75 7 Exercise 51. Complete the following program and flowchart directing the computer to print the smaller of two numbers, A and B. 10 INPUT 20 30 PRINT 40 GO TO 50 PRINT 60 GO TO 99 END RUN A,B B 10 A PRINT A 10 13.4 3 15.. 2 2 Exercise 52. We have written a program directing the computer to print two numbers in ascending order with the smaller on the left and the larger on the right. You do the flowcbart here; 10 INPUT A.B 20 IF AB and set C = A. ~ B is TR VE, our guess is correct. In this case, follow the YES path. But if C ~ B is FALSE, we were wrong. We acknowledge our mistake and set C B. = By either path, C MAX(A, B) 'maximum of A and B. So we print the value of = = C. Again, there are two possible paths through the flowchart. Mark them in two colors. If you mark the path for A= 3, B = 4 in green and tne path for A 5, B 2 in red, which path (green or red) should we follow if = A = = 2, B = I? _ _ _ _ _ _.::-- A = 9, B = 10? _ _ _ _ __ A =7,B= 71 _ _ _ _ _ _ _ A =O,B= -1 1· 1-77 ~~_ __ O.K., here is the BASIC program to go with the flowchart on the preceding page. Note how we write statement. 10 INPUT A, B 20 LET C=A 30 IF C>=B THEN 50 40 LET C=B 50 PRINT C'" I 60 GO TO 99 END ~ In an IF ' . . . . . Follow me if and only if C ~ A = 3,B = 4. B is TRUE. 10 RUN C=4. 13,4 4 15" 2 5 = A 5, B C=5. = 2. Your turn ... complete the following trace of the above program. STATEMENT ABC 10 INPUT A,B 3 20 LET C;:j A 3.. 30IFC> ::::tBTHEN50 3 OUTPUT REMARKS 4 ~ "",3 4 C 3 40LETC =B ~ B is FALSE. Yau carryon. 50PRINTC r 60 GO TO 10 10 INPUT A,B 5 20LETC-:A 5... 30 IF C >= B THEN 50 5 " 2 ~ ,..5 2 5 1-78 TRUE or FALSE? Where to next? The IF Statement The IF statement directs the computer to examine a relation between two expressions and then follow one (and only one) of two paths depending on whether the relationship is TRUE (YES) or FALSE (NO). In general, the IF statement looks like this: where n IF n = line number of the IF statement el = any BASIC expression el r THEN e;! t e;! = any BASIC expression r anyJegal BASIC relation (see below) t = line ~umbef of th'e statement executed next if and only if el r e;! is TRUE = Relation between .~ two expressions, el and e2 ~ For example, 35 IF X INT(X) THEN 60 el e2 THEN t t IFt t tr n t t t is TRUE if X is an integer. X = INT(X) is FALSE if X is not an integer. Here is a handy table showing BASIC relations and corresponding mathematical ralations. MATH < > ~ ~ :f= BASIC RELATION < > <= >= <> Equal to Less·than Greater than Less than or equal to Greater than or equal to Not equal to 1-79 A Problem. Write a program directing the: computer to tell us whethe,r a n;umber is positive, negative or zero. Let's solve it. Since there are three possibilities (X > 0, X < 0, or X 0),: we can't solve the problem with a single IF statement. But we can do it with two IF statements. = For example, If X > 0 is FALSE, then X < 0 or X= O. Which one? There are three possible paths through the program. Mark them in three colors. What color path if X = 7? _ __ What color path if X = - 3?_ __ What color path if X = O? _ __ Exercise 53. Write a BASIC program to go with our flowchart. RUN nfor X 7, X -3 and X O. = = = 1-80 VARYING PATTERNS Rectangular Patterns We wrote a program to print rectangular patterns on the Teletype. We ran it ... here is what happened. Rows I ?12.29~~ __-------------------- ***************************** ***************************** ***************************** ***************************** ***************************** ***************************** ***************************** ***************************** ***************************** -***************************** ***************************** ***************************** Columns Our program lets us specify the number of rows and columns in this rectangular pattern. This pattern has 12 rows and 29 columns. That is, it has 12 rows and there are 29 asterisks in .each row. Using our program, we can direct the computer to print rectangular patterns with as many rows as we want. The number of columns, however, is limited to 72 since there are only 72 printing positions across the paper. In the above pattern, there are 12 x 29 = 348 asterisks in all. Let's RUN the program again. 13, 10 .........-------------This time we want 3 rows, columns. ********** ********** ********** Here they are . . . count them. Now let's look at the program. 1-81 10 Below is part of the program. This part directs the computer to print one row of asterisks with N asterisks in the row. 10 INPUT N 15 PRI NT N specifies the number of asterisks to be printed in the row. Here is the heart of the program. It causes the computer to print N asterisks, all in one row because the PRINT statement ends with a semicolon. 30 FOR C: 1 .TO N 40 PRI NT "*"; 50 NEXT C 60 PRINT 80 GO TO 1,0 99 END This PRINT causes a carriage return and line feed to occur after all the asterisks have been printed. RUN Let's try it. 110 N = 10, so the computer prints a row with 10 asterisks. ********** 120 N=20, ******************** How many asterisks? 172 N = 72. Computer prints 72 aster- isks. = 73 , . , can't get them all on one line', N ************************************************************************ 175 ************************************************************************ * The 73rd asterisk ended up h~re. The computer will print up to 72 asterisks on one line ... but no more. If N > 72 then the computer prints 72 asterisks on the first line and continues on the next line. Suppose N = 200. How many lines it take to print the "row" of 200 asterisks? will 1-82 By adding three statements and changing the INPUT statement in the preceding program, we get a program to print a pattern consisting of M rows with N asterisks in each row. 10 INPUT M,N 15 PRIr'lT Which lines did we add? 20 FOR R"l TO M 30 FOR c~ I TO N 40 PRINT n*n.: One row with· N asterisks 50 NEXT C M rows 60 PRINT 70 NEXT R ') \ 75 PRINT 80 GO TO 10 99 END RUN This program has a "loop within a loop." Does it work? RUN it. = 5, N = 12. 15,12 We enter M ************ **********~* ************ ************ ************ The computer prints a rectangular pattern with 5 rows and 12 columns. 1 1,7 A 1 by 7 pattern (1 row, 7 columns). ******* * * * * * And a 7 by 1 pattern (7 rows, 1 column). We finish with a 1 by 1 pattern. * P .S. How about a null (empty) pattern? 1-83 Exercise 54. If you are tired of seeing asterisks before your eyes, change this 'Statement ~ 40 PRINT to this_ . .... 40 ~40 r or t hIS--- ""'''J PRINT "X" J PRINT "I'" or to the statement of your choice. Then RUN the program again. Exercise 55. Start with our program on page 1-83. Change the INPUT statement to • 10 INPUT M and change one other statement so that the modified program will print right triangular patterns, like these. RUN ---- -------1 I This pattern ~as 2 rows with, 1 asterisk in Row 1 and 2 asterisks in Row 2. 12Ar * ** !3~·~--------------------------'--~1 ** *** ;4 -~.- This pattern has 3 rows with 1 asterisk in Row 1, 2 asterisks in Row 2 and 3 asterisks in Row 3. _______________________________ ** *** **** --, This pattern has 4I rows with 1 asterisk in Row 1, . . . and so on. For an INPUT value of M, the pattern has M rows with 1 aster- . isk in Row 1, two asterisks in Row 2, three asterisks in Row 3, ... , M asterisks in Row M. 1-84 In the following program, we use a "brute force" approach to tell the computer to print a "leaning tower" pattern. 10 PRINT "********" 20 PRINT " ********" 30 PRINT" **"''''****'' 40 PRINT" ********" 50 PRINT " **",***",,,,,, 60 PRINT " "''''*'''****'' 70 PRINT .. "'****"'*"''' 80 PRINT " *******"''' Each PRINT statement tells the computer to print a certain number of spaces followed by 8 asterisks. . 99 END spaces RUN . . *"'**"'**'" *"''''**''''''''' "''''**'''*** ******** ******** . ******** ******** ******** \ You can use the·" brute force method to print just about any pattern you wa~t. spaces Let's make the tower lean the other way ..' 10 PRINT .. 20 PRINT " 30 PRINT " 40 PRINT " 50 PRINT" 60 PRINT." 70 PRINT" 80 PRINT " 99 END ********" ********" ********" ********" Print 7 spaces, then 8 asterisks. ********" Print 6' spaces, then 8 asterisks. ***",***",,, And so on. ********" "'**"'**"'*" RUN *******'" ",**",,,,*,,,,,,. ******** ******** "'***"'**'" "'**"'''''''** ***"'''''''*''' *******"', 1-85 The TAB Function Yes, we're leading up to something . . . here is another way to do the first leaning tower pattern. 10 PHINT TAB(0);"********" 20 PRINT TAB(1);"*** ••••• " 30 PRINT TAB(2);"** •• ***." 40 PRINT TAB(3)J"******.*" 50 PRINT TAB(4);"*.**** •• " 60 PRINT TABCS)}"******.*" 70 PRINT TAB(6);"* •• ***.*" 80 PRINT TAB(7);"****.***" 99 END RUN ******** * •• **.** *.****** .* •• *.** ******** *.*** ••• ******** ***.** •• We wrote this program primarily ... to introduce the TAB function. The TAB function causes the computer to spaee over to the printing position enclosed in the ( ). We hope your version of BASIC provides the TAB function ... if n9t; you might as well skip the rest of this section. fi If your computer does provide the TAD function, read on! EXAMPLE EXPLANATION TAB(7) Space the teletypewriter over to printing Position 7. TAB(25) Space the teletypewriter over to printing Position 25. There are 72 printing positions across the page . . . they are numbered through 71. ° **************************************************** 'pOSit jon ° Position 37 Position 71 Your turn ... circle printing Positions 10, 20, 30, 40, 50, 60 and 70 above. 6 EduSystem 10 does not include the TAB function; larger systems do. 1-86 In general, the TAB function looks ]ike this TAB(e) where e is any BASIC expression. The expression is evaluated and the computer spaces the Teletype to the position specified by the value of the expression. If the value of e is not a whole number, then the computer ~paces the teletype to the whole number part· of the value of e. EXAMPLES EXPLANATION TAB(K) Move to Position K. TAB(R - 1) Move to Position R -1. TAB (2*X + 3) Move to Position 2*X (0 ~ K ~ 71) (0 + 3. ~ (0 R -1 ~ ~ 71) 2*X + 3 ~ 71) Here is yet another way to print the leaning tower pattern. 10 FOR R= 1 TO 8 1 ).: 20 PRINT TAB( 30 NEXT R T 99 EN D . RUN RI. ******** ******** ******** ******** ******** ******** ******** ******** u********" . Space over to printing Position R - 1. When R 1, this is Position 0; when R = 2, this is position 1; and so on. = The computer cannot space the Teletype ; FOR C= 1 TO 8 PRINT U."; NEXT C PRINT NEXT H END 20 30 40 50 60 70 80 99 FOR R= 1 TO 8 PRINT TAB(8-R); FOR Co: 1 TO 2.R-l PRINT "."; NEXT C PRINT NEXT R END Exercise 58. By adding an INPUT statement and changing a few things in the programs of the preceding exercise, you can get a pr • • • • .. • • ••••• • ••••• • * probability of printing a star is Y2. The probability of printing a space is 1/2 • , Let's look more closely at statement 35. 35 IF INT(2*RND(O)) =1 THEN 50 The possible values are 0 and 1 . - - - The following statement will also do the job. Try it! 35 IF Because RND(O) < 1/2 THEN 50 ~RND(O) < .5 is TRUE about V2 the time. RND(O) <.5 is FALSE about 1;2 the time.' 1-94 In the following pattern the probability of printing a star is 1/10 and the probability of printing a space is 9/10. LOOK FOR CONSTELLATIONS ... MAKE UP YOUR OWN ... ARE ANY SIGNS OF THE ZODIAC HERE? 142,65 -* * ** * * ** ** * * * * * * * ** * * * * * * * * *' * * •• **. * * ** ** * * * * ** **... * ... * * * ** * * * * * * ** * ** * * * * * * * * * * * * * * * * ** * ** * * * ** * * * * * * * * ** * * ** * * * ** * ** * * * * * ** ** * * ** * * * * * * * * *** * * * * * * * * ** * ** * * * ** * * * * * * * * * * '" * * * * * ** *.* • ... ** * ** * * * * ** * * * ** * * • ... * ** * ,.; ** ** ... * * *• ... * ... ... ** • ... * * ... ***... * *... * * * • ... •• * • * * *... ...* ... **... * * * * ... * * * * ... '" * * * * * ** * * * >I< Did you look at it from the left? The right? The top? 1-95 Exercise 63 . Write a program to generate random patterns like -the one on the preceding page. You can do it by changing one statement in our program on page 1-94. RUN it-look for constellations. Exercise 64. Modify your program of the preceding exercise so that the probability of printing a star is 1/20 and the probability of printing a space is 19/20. RUN it-look for constellations. Exercise 65. Why not enter the probability of printing a star along with M and N? Begin your program with the statement 10 INPUT M, N, P where M is the number of rows, N is the number of columns, and P is the probability of printing a star. But note: P must be entered as a decimal numeral such as .5 or .1 or .05. Here is a RUN of our program. 120,65,.1 * ** * * ** ** * * * * * * * * * * ** * * * * * * * * * * * * * ** * * * * * ** * * * * ** ** * * * '" * ** ** * * * ** * * * * * * ** * * 1-96 * * * * * ** * * * * * * '" * * * * '" * * * * * * * * * ** ** * * ** ** * * * - * * * LITTLE BOXES Remember . . . in BASIC, a variable refers to a location in the computer's memory. You can think of the variable as the name of the location. A 1-1_. . . variable/ : / location"/' A location is a "box" in which we can store a number. Here is a box (location) with a number in it. A I ~ 37 Ii The number in the location is the value of the variable. (The value of A is 37.) Subscripted Variables Are you acquainted with subscripted variables? Here is a sUbscripted variable .. X3 This is the SUbSCriPt------ The symbol 'xa' is read 'x sub 3.' Here are some additIonal examples of subscripted variables. Po C7 ks Xl Y4 al X2 Z2 r2 Xa Zl Read 'a 1 ' as 'a sub l' Read 'C7' as 'c sub 7' Read 'r2' as 'r sub 2' and so on. W9 1-97 In BASIC, we can use subscripted variables, but we write them in a slightly different way. Like this: Here is a BASIC subscripted variable--------••X(3) This is the subscript ------1 The subscripted variables X ( 1 ), X (2) and X (3) each correspond to a location X(l)D X(2)D X(3)D Exercise 66. LET X(l) = 73. In other words, take pencil in hand and write the numeral "73" in the box labelled" X (l ) ." Then do the following in similar fashion. (l) LET X(2) = 67 (2) LET X(3) = 85 Suppose that X ( 1 ), X (2) and X (3) are scores obtained on three quizzes. Here is a program to compute and print the average score (the arithmetic mean of the three scores). 1 0 LET X ( 1 )". 7 3 12 LET X( 2)=67 14 LET X( 3)-85 20 LET S=X(1)+X(2)+X(3) 30 LET M-S/3 40.,."PRINT M 99 END RUN 75 Quiz 1. The score is 73. Quiz 2. The score is 67. Quiz 3. The score is 85. Add the three scores, then divide the sum by 3 and print the result. Yes, we know you can write a shorter program . . . but did you learn anything about subscripted variables? 1-98 Here is a better program. INPUT X( 1>.X(2).X(3) ~ LET S=X(1)+X(2)+X(3) LET M=S/3 . PRINT M 50 PRINT With 60 GO TO 1 0 three 99 END RUN 10 20 30 40 ?73.67.85~~.---------------~ 75 1 this program, we INPUT the scores. x (1)1 --II 7_3 L...._ _ _ X(2) I 6_7......1 X (3) 1L-_ _ _8_5 ......1 L -_ _ _ ..........- - - - - - - - - - - O.K., enter your scores. Exercise 67. Complete the following program to compute and print the arithmetic mean (average) of four scores: X ( 1 ), X (2), X (3) and X ( 4 ) 10 INPUT 20 LET 5= _ _ _ __ LET Me _ _ _ __ ~0 40 PRINT M 50 PRINT 60 GO TO· 99 END RUN R UN your program for the following sets of data. Each set consists of four scores. 73,67,85,83 82,88,97,90 ? 1 SHOW THE RESULTS OF THE RUN 1-99 Next, let's change our program so that the data is called in by means of a READ statement instead of an INPUT statement. 10 15 20 30 40 60 80 81 82 83 99 PRINT "XC 1 ) It, "XC 2)", "XC 3)", "MEAN'" READ XCl),XC2),XC3) LET S-X(1)+XC2)+XC3) LET M=S/3 PRINT X(1),XC2),XC3),M GO TO 15 DATA 7 3 , 6 7 , 8 5 } DATA 82,88,97 Four sets of data. Each. set has DATA 93,89,95 three scores. DATA 17, 11 , 61 END RUN XC 1> 73 82 93 77 X(2) 67 88 89 71 XC 3) 85 97 -95 67 MEAN 75 89 92.33333 71.66661 DATA ERROR AT LINE 15 Exercise 68. Change the above program to a program to compute and print the mean of four numbers X ( 1), X (2), X (3), and X ( 4 ). Show the modified program below along with a RUN for the following sets of data: 73,67,85,83 82,88,97,90 1-100 Generalizing But what if there are five scores or six scores or se~en scores? Shall we write a separate program for each case? Why not write one program that takes care of any number of scores ... let's try. We want to write a program to compute the arithmetic mean of N numbers (quiz scores, golf scores, measurements ... you name it). Since we have N numbers, let's call them ~ X(l), X(2), ... , X(N). We tried the following program but it didn't 'work. We kept ,getting error messages. 10 20 30 10 20 30 40 50 60 70 71 72 73 99 READ N Our computer didn't like these two READ X(1),X(2),. •• , X ( N ) : : 7 statements. LET.S-X(I)+X(2)+ ••• "LI5T READ N READ X( 1 )"XU3),,000,,'X(N) LET S=X N. Therefore the loop terminates. 1-103 Exercise 69. Let's continue the trace that we began on the preceding page. We will show the statements; you fill in the K, Sand M columns. Remember ... we left X( 1), X(2) and X(3) as follows. X(1)[_ _ 73__ 1 __67__1 X(3)1_____85_1 X(2) ___ STATEMENT N 30LETS=O 3 33 FOR K == 1 K s M OUTPUT 3 35 LET S = S + X(K) 37 NEXT K 3 3 35 LET S = S + X (K) 37 NEXTK 3 3 35 LET S = S + X(K) 37NEXTK 3" 3 40 LET M = SIN 50 PRINTN, S, M 60 GO TO 10 and so on. 3 3 3 Exercise 70. For each program segment (portion of a program) fill in the affected locations. 10 FOR N= 1 TO 4 20 LET peN )-2tN 30 NEXT N 70 75 80 85 LET F( 1 ) FOR Kc:2 TO 6 LET FCK)c:K*F(K-l) NEXT K P( 1) D P(3) C] F(1) C] F(3) C] C] F(5) 1-104 D P(4) D F(2) D F(4) D P(2) F(6) D Subroutines A new idea-subroutines-and three new statements, GOSUB, RETURN, and STOP. Let's use them in a rewrite of the program on page 1-103. 10 ......... 20 30 40 50 60 READ N GOSUB 100 LET M-S/N PRINT N .. S.. M GO' TO 10 STOP -.~100 110 120 130 140 15& 160 110 FOR K-l TO N READ X(K) NEXT K LET 5=0 FOR Kal TO N LET S=S+X(K)' NEXT K RETURN 300 310 320 330 999 DATA DATA DATA DATA END 3 .. 13 .. 3 .. 82 .. 4 .. 13 .. 5,66 .. main program subroutine 61 .. 85 88",91 data 61 .. 85 .. 83 18 .. 11 .. 82,15 base This program has a main program, one subroutine and a data base. The subroutine in lines 100-170 is called by the GOSUB in line 20. Now, RUN the above program. The results should be the same as for the program on page 1-99. When the GOSUB in line 20 calls the subroutine, the computer goes to line' 100 and executes the commands from line 100 to 160. The RETURN statement in line 170 sends the computer to the line following the GOSUB (line 30) that sent the computer to the subroutine. The STOP statement in line 60 sends the computer to the END statement, thus signaling the completion of the program. A program may contain more than one subroutine. Suppose that we wish to' print. headings for each of the columns printed by the above program. We can do this by adding one statement to the main program and inchidin~ one more subroutine. 1-105 5 GOSUB 200 new main program statement 200 PRINT "N"" "S"" "M" 210 PRINT 220 RETURN new subroutine Now LIST the program and then RUN it. 5 GOSUB 200 10 READ N 20 GOSUB 100 40 PRINT N" S" M 50 GO TO 10 60 STOP 100 FOR K- 1 TO N 110 READ X(K) 120 NEXT K 130 LET S"'0 140 FOR K-l TO N 150 LET S-S+X(K) 160 NEXT K 170 RETURN 200 PRINT "N"" "s"" "M" 210 PRINT 220 RETURN 300 DATA 3,,73,,67,,85 310 DATA 3,,82,,88,,97 320 DATA 4,,73,,67,,85,,83 330 DATA 5,,66,,7S,,71,,82,,75 999 END RUN N 3 3 4 5 M S 225 267 308 372 DATA ERROR AT LINE 10 (II 0 (II '" A program may have many GOSUB's, each .of which go to the same subroutine; this is especially helpful when the same (or similar) statements appear more than once in the same program. When you use subroutines, keep them distinct from the main program. This is normally done by placing them after the main program. Remember that the last statement in the main program must be a STOP or a GO TO (e.g., GO TO 999-the END statement) . 1-106 SNOOPY AND THE RED BARON It is 1976 and the candidates for President of the United States are Snoopy and the Red Baron. We conducted a poll by asking 29 of our friends to respond to the following question. Who should be President in 1976? Circle the number to the left of the candidate of your choice. 1. Snoopy 2. Red Baron You guessed it . . . we are going to write a program to direct the c~mputer to count the votes for each candidate, Snoopy and the Red Baron. First, let's record the 29 votes in one or more DATA statements. Remember, each vote is a "1" or a "2." 91 DATA 2,1,2,1,1,2,2,2,1,1,2,2,2,1,1 92 DATA 2,2,1,1,2,2,2,1,2,1,1,1,2,2 Before continuing, we ask you the following questions. How many votes did Snoopy get? _ _ _ _ _ _ _ _ _ __ How many votes did Red Baron get? ___________ Add the number of votes obtained by Snoopy and the number obtained by the Red Baron. The total should be 29 . .'. if not, check your work. 1/ ! 1-107 We think you answered the questions on the preceding page as follows. 1. You counted the number of "Is" in the two DATA statements. The result is the number of votes obtained by Snoopy. 2. Then you counted the number of "2s" in the two DATA statements. The result is the number of votes obtained by the Red Baron. That's fine, but we are going to use a different method. First, we define two subscripted variables and assign the value zero (0) to each. Like this: C(I)r=~ C(2) I_____ _0.......1 Then we read the 29 votes, one by one. If the vote (V) is a "1" we increase the value of C( 1) by one. But if the vote is a "2," we increase the value of C (2) by one. After we have rea,d all 29 votes, C ( 1) will contain the number of votes for Snoopy and C (2) will contain the number of votes for the Red Baron. Here is the program and the results of a RUN. If you don't understand the pro10 20 30 40 50 gram, study the trace on the next page. LET C( 1 )=0 LET C( 2)=0 FO R K- 1 TO 29 READ V LET C(V)=C(V)+1 60 NEXT K 10 PRINT C(I),C(2) 91 DATA 2 .. 1 .. 2,1, 1,2,2,2,1,1,2,2,2,1,1 92 DATA 2 .. 2,1, 1,2,2 .. 2,1,2,1,1,1,2,2 99 END RUN 13 16 t..-------+L----- vote count for Snoopy. L , - - - v o t e count for the Red Baron. 1-108 Exercise 71. Study the following partial trace of our vote count, ing program and fill in the missing information under the K, V, C( 1) and C(2) columns. STATEMENT v K 10 LET C(1)= 0 20 LET C(2) = 0 - C(1) C(2) 0 0 0 0 0 30 FOR K = 1 TO 29 1 40 READ V 50 LET C(V) = C(V) 60 NEXTK +1 1 1 2 2 2 2 0 0 0 0 1 1 +1 2 2 3 1 1 1 1 1 1 1 1 1 40 READ V 50 LET C(V) = C(V) 60NEXTK +1 3 3 4 2 2 2 1 1 1 1 2 2 40 READ V 50 LET C(V) = C(V) 60 NEXT K +1 40 READ V 50 LET C(V) = C(V) 60NEXTK +1 40 READ V 50 LET C(V) = C(V) 60NEXTK +1 40 READ V 50 LET C(V) = C(V) 60NEXTK +1 40 READ V 50 LET C(V) '= C(V) 60NEXTK and so on. 1-109 Exercise 72. We conducted another poll, asking the same question. But this time, we asked 32 people to votle for Snoopy or the Red Baron. Here are the votes. 1, 1, 2, 1, 2, 2, 2, 2, 1, 1, 2, 1, 1, 1, 1, 1 2, 2, 1, 2, 1, 1, 2, 2, 2, 1, 1, 1, 2, 1, 1, 2 Use our program to process the above data. You will have to change Lines 30, 91 and 92. Exercise 73. Conduct your own poll. Then use our program to process the data. You will probably have to change Lines 30, 91 and 92. Exercise 74. Figure out how to use the following program to count votes. Change it to count the votes of either Exercise 68 or 69. 10 READ N .. 20 LET C(I)=0 25 LET C(2)=0 - 30 FOR K=1 TO N ~~~-----------------40 READ V 50 LET C(V)=C(V)+1 60 NEXT K 70 PRINT C(I) .. C(2) 90 DATA 29 ~ 91 DATA 2 .. 1 .. 2 .. 1.. 112 .. 2 .. 2 .. 1.. 1.. 2 .. 2 .. 2 .. 1 .. 1 92 DATA 2 .. 2 .. 1 .. 1.. 2, 2, 2,1 .. 2,1 .. 1, 1 .. 2, 2 99 END RUN 13 N votes ~ 16 1-110 Value of N. No Opinion Here is a slightly different questionnaire. Who should be President in 1976? Circle the number to the left of the candidate of your choice. 1. Snoopy 2. Red Baron 3. No Opinion We asked 37 people and got the following votes. 1,3,1,.2,3,1, J, 2,3, 1, 1,2,1,1,2, 1,2,2,2 2, 1, 3, 2, 2, 1, 2, 1, 1, 3, 1, 1, 2, 3, 1, 1, 2, 3 How many votes for Snoopy? _ _ _ _ _ _ _ _ _ _ _ __ How many votes for the Red Baron? _ _ _ _ _ _ _ _ __ How many No Opinions?_--------------TOTAL of above categories? ______________ Now we hav.e three categories, so we use three subscripted variables. C(l) I___~]C(2) Snoopy I . Red Baron ~ I C(3) I L...--_ - - - - - - ' No Opinion I Exercise 75. Change our program of Exercise 74 into a program to process data such as the above (three categories instead of two) . You will have to add a line to set C(3) to zero, change Line 70 and, of course, change Lines 90, 91 and 92. 1-111 Exercise 76. In a newspaper, the results of a poll might be presented in a table such as the following. CANDIDATE VOTES PERCENT Snoopy 17 46% Red Baron 13 35% No Opinion 7 19% (% of total vote)J Modify your program of Exercise 75 so that the results are printed in a table like the one shown above. Exercise 77. But suppose there are three candidates. For example, our questionnaire might look like this. Who should be President in 1976? Circle the number to the left of the candidate of your choice. 1. Snoopy 2. Red Baron 3. Lucy 4. No Opinion Write a program to count votes obtained by using the above questionnaire. Invent your own data . . . print results in a table similar to the table in Exercise 76. 1-112 More Choices We have used questionnaires with two choices, three choices and four choices. In each case, the choices have been political candi-. dates or a "No Opinion" category. Our categories don't have to be political, however. Here are several questionnaires that you can use to gather data. Do so . < • then use the program on the following page to compute the results of each of. your polls. Which breakfast cereal do you prefer? Circle the number to the left of your choice. What is your favorite musical group? Circle the number to the left of your choice. 1. Beatles ·2. Blood, Sweat and Tears 3. Crosby, Stills, Nash & Young 4. Jefferson Airplane 5. Lawrence Welk 6. Rolling Stones 7. None of the Above 1. 2. 3. 4. Trix Total Cheerios No Opinion What is your favorite individual sport? Circle the number to the left of your choice. 1. 4. 7. 10. 13. 16. 19. Badminton Fencing Handball Roller Skating Surfing Track None of Those Listed . 2. 5. 8. 11. 14. 17. Bowling Golf· IceSkating Snow Skiing Swimming Water Skiing 3. Boxing 6. Gymnastics 9. Karate 12. Squash 15. Tennis 18. Wrestling If someone circles two or mOre choices, throw out their ques- tionnaire ... our program can't handle this case. 1-113 Here is our program. The lines that begih with the word "REMARK" are remarks! They have no effect on the execution of the program. You may insert a REMARK line wherever you please. 100 200 2110 220 -300 310 320 330 400 410 420 500 510 600 610 620 63~ 640 7f60 710 720 730 900 901 902 903 999 REMARK***THE P~OPLE·S POLL REMARK***M IS THE NUMBER OF CATEGORIES (M<:99) Dlf1 C (99)~ Let's talk about this below. READ M R~MARK***SET C(l),C(2), ••• ,C(M) ALL TO ZERO FOR K:l TO M LET C(K):0 NEXT K REMARK***PRINT A HEADING PRINT "CATEGORY", "VOTES" PRI NT REMARK***THERE ARE N VOTES READ N REMARK***READ N VOTES AND COUNT BY CATEGORY FOR K:l TO N READ V LET C(V):C(V)+1 NEXT K RiMARK***PRINT RESULTS (M LIHES,2, NUMBERS P~R LINE) FOR K:l TO M PRINT K,C(K) NEXT K R Ef1ARK***BEGI N DATA LISTS DA TA ..........- - - - - - - Put your value of M here. DATA ... Put your value of N here. DATA ,. Record your votes, beginning here. END Use as many DATA statements as necessary. *** O.K., now RUN it! *** The statement 2.10 DIM C(99) is a DIMension statement. 7 It tells the computer to permit subscripts of C up to and including 99. Without a DIM statement, the largest permissible subscript is 10. We chose 99 arbitrarily. We could have c;:hosen 25 or 100 or 150 or any limit we wanted. 7 Not necessary on EduSystems 20 or 25. 1-114 Generation Gap Snoopy and the Red Baron ... a new questionnaire. Q1. Who should be President in 1976'1 Circle the number to the left of your choice. 1. 2. 3. Snoopy Red Baron No Opinion Q2. Circle the number to the left of the phrase that describes your age group. 1. Under 30 years old 2. ·30 years old or older. The first question has three possible responses (1, 2 or 3) and, the second question has two possible responses (lor 2). Each completed questionnaire gives us two numbers. For example, /1,2 ~ L__ t . A vote for Snoopy ... by a person 30 years old or older. We conducted a survey. We asked 32 people to vote, therefore we got back 32 pairs of 'numbers . , .64 numbers in all. 1, 2, 2, 1, 3, 2, 1. 1. 2. 2, 2. 2. 1, 1, 2, 1, 1,2,2,2,2,2, 3, 1 2,2, 1, 1, 1, 1,2,2, 1,2, 3,2,2, 2,2, 1, 1, 1, 1, 1, 1, 1, 1,2 1, 1, 1, 2, 2, 1, 1, 2, 2, 2, 1, 1, 3, 1, 1, 1 Begin here and circle or underline each pair of numbers. The first number in each pair is the vote (1, 2, or 3) and the second number in each pair is the age group of the voter, . How many people under 30 voted for Snoopy? How many people 30 or older voted for Snoopy? 1-115 · Fortunately, BASIC permits us to use variables with two subscripts. UNDER 30 30 OR OVER Snoopy C(1,I) IC(1, 2) Red Baron C(2, 1) .IC(2, 2) No Opinion C(3, 1) IC(3,2) Here is a variable with two subscripts: First subscript - , - - - Second subscript _ _ _.L Have you guessed the following? = number of votes for Snoopy by people under 30. C( 1,2) = number of votes for Snoopy by people 30 or over. C ( 1, 1) C(2, 1) = number of votes for Red Baron by people under 30. Your turn. Complete the following. C(2, 2) = _ _ _ _ _ _ _ _ _ _ _ _ _ _ __ C(3, 1) = ________________ C(3, 2) = _ _ _ _ _ _ _ _ _ _ _ _ _ _ __ Here is our data again, copied from the prec:eding page. Use it to fill in the boxes (C(1,l), C(I,2), etc.) at the top of the page. We suggest that you look at each pair of nuinbers and, for each pair, put a mark in the appropriate box. After you have used all pairs, simply count the number of marks in each box and write in the number. 1, 2, 2, 1, 3, 2, 1, 1, 2, 2, 2, 2, 1, 1, 2, 1, 1,2, 2,2,2,2, 3, 1 2,2,1,1,1,1,2,2,1,2,3,2,2,2,2,1,1, 1, 1, 1, 1, 1, 1,2 1, 1, 1,2, 2, 1, 1, 2, 2, 2, 1, 1,3, 1, 1, 1 1-116 Here is a BASIC program to count the votes. We have included several REMARKS to describe what's happening. ' 100 200 210 220 230 240 250 300 310 320 330 340 350 400 410 420 430 440 450 900 901 902 903 999 REMARK***SNOOPY~RED BARON AND THE GENERATION GAP REMARK***PUT ZEROS IN THE BOXES FOR 1= 1- TO 3 FOR J= 1 TO 2 LET .c 7 DIM--list of subscripted variables The above DIM statement tells the computer that: The subscript of A must me The sUbscript of B must be ~ ~ 20. 30. The first subscript of C must be ~ 20. The second subscript of C must be ~ ~ 5. The first subscript of D must be The second subscript of D must be ~ 12. 7. If you don't mention a subscripted variable in a DIM statement, then the computer assumes that its subscript or subscripts must be less than or equal to 10. 1-120 Below are two programs. RUN each program using the given data. Describe to yourself. what each program does, then make up your own data and RUN it again. 10 15 20 25 30 35 40 45 50 55 60 65 70 80 81 82 83 84 85 99 DIM K(50).Ae50) READ N FO R J- 1 TO N READ KeJ) Maybe you can figure NEXT J program does without LET S:a0 . it! FO R J:a 1 TO N READ AeJ) lF AeJ)<>KeJ) THEN 60 LET S-5+ 1 NEXT J PRINT S GO TO 35 DATA 12 DATA 2.1.2. 3. 4~ 1.3.2. 1.4.4.1 DATA 2.1.1.3.4.1.3.1.1.3.4.2 DATA 2. 1~ 2. 3. 3. 1. 3~ 2. 1.4.4. 1 DATA 1.1.1,3,4.1.3,2.2,4.4,1 DATA 3,4.2, 1,4. 1,2,4, 3.4, I, 3 END 100 200 210 220 230 300 310 DIM X(30) READ N F'OR K-l TO N READ XC K) NEXT K FOR J-l TO N-l FOR K-J TO N 3~u. xeJ)-X(K)LISL_ 100 DIM X( 30 .. 200 READ N 210 FOR K=l TO N 220 READ XCK) 230 NEXT K 300 FOR J=l TO N-l 310 FOR K-J TO N 320 IF X(J). M THEN 260 250 IF H=INTCH) THEN 252 251 GOTO 260 252 IF H>0 THEN 254 253 GOTO 260 254 IF H<4 THEN 280 260 PRINT "YOU CHEATED',I 'LL GI \IE YOU ANOTHER CHANCE. Jt 270 GOTO 215 280 LET M=M-H 290 IFM=0 THEN 410 300 REMARK***THE COMPUTER 310 LET R=M-4*INTCM/4) 320 IF R<>1 THEN 350 330 LET C=INT(3*RND(0»+1 340 GOTO 360 350 LET C=(R+3)-4*INT«R+3)/4) 360 LET M=M-C 370 IF M=0 THEN 440 375 PRINT 380 PRINT "I TOOK";C;"MATCHES" 390 GOTO 200 ,,400 REMARK***SOMEBODY \/JON ( SEE LINES 290 AND 370> 410 PRINT 420"PRINT "I \NON'!' BETTER LUCK, NEXT TIME. 430 GOTO 100 440 PRINT 450 PRINT "O.K. SO YOU wON. LET'S PLAY AGAIN." 460 GOTO ,100 999 END It We show a RUN on the following page (we lost). 1-125 WE STAHT WITH 23 MATCHES. WHEN IT IS YOUR TURN, YOU MAY TAKE 1,2, OR 3 MATCHES. THE ONE wHO MUST TAKE THE LAST MATCH LOSES. THERE ARE NOW 23 MATCHES HOW MANY MATCHES DO YOU TAKE?? 3 / Human (that's me) takes 3 matches. Computer takes 3 matches. I TOOK 3 MA TCHES THERE ARE NOW 17 MATCHES HOw MANY MATCHES DO YOU TAKE?? 2 I TOOK 2 MA TCHES THERE ARE NOw 13 MATCHES HOw MANY MATCHES DO YOU TAKE?? 3 I TOOK 1 MATCHES THERE ARE NOW 9 MATCHES Quite illegal! HOw MANY MATCHES DO YOU TAKE?? 4 / . YOU CHEATED! I ILL GI VE YOU ANOTHER CHANCE. We got caught! HOw MANY MATCHES DO YOU TAKE?? 1 I TOOK 3 MATCHES THERE ARE NOW 5 MATCHES HOW MANY MATCHES DO YOU TAKE?? 2 I TOOK 2 MATCHES Nice try, but again / 'we got caught. THERE ARE NOW 1 MATCHES HOW MANY MATCHES DO YOU TAKE?? 0 YOU CHEATED! llLL GIVE YOU ANOTHER CHANCE. HOW MANY MATCHES DO YOU TAKE?? 2 YOU CHEATED! I'LL GIVE YOU ANOTHER CHANCE. HOW MANY MATCHES DO YOU TAKE?? 1 I WON"! BETTER LUCK NEXT TIME. Can you beat the computer? Try it! 1-126 Rounding a Number Sometimes we want to round a number. If you don't know what we mean by "round," study the following program and the RUN of it. 10 20 30 40 50 60 70 -80 99 REMARK*** ROUND TO THE NEAREST INTEGER PRINT" X....... X ROUNDED" PRINT READ X LET R-INT =C9/5>*T+32 GOSUB 100 PRINT FNF'CX> GOTO 10 STOP REMARK***READ AND TEST DATA READ X IF X>-273 THEN 140 PRINT "INVAL I D DATA" RETURN DATA -'40,0,100,23,9,37,-274 END RUN -40 32 212 73.4 48.2 98.6 INVALID DATA -461.2 DATA ERROR AT LINE 110 The DEF statement in line 10 defines a function FNF which may then be used elsewhere in the program. Defined functions must have three letter names, starting with FN. The format of the DEF statement is as follows: (line number)DEF FNF(T) = (9/5)*T + 32 argument 1-131 formula argument F may be any letter. The argument (T) has no significance but must be; the same on both sides of the equal sign. The formula may be expressed in terms of numbers, several variables, other functions (INT, SQR, etc.), or mathematical expressions. Om:e the function has been defined, it is called in the same manner as other BASIC functions, e.g. FNF(X). Only one DEF statement is permitted in an EduSystem 10 program. The larger EduSystems allow multiple DEF statements in a program. Exercise 86. Define a function to find the area of a circle. Remember that the formula is: A = 3.14xR2 or as we say in BASIC A == 3.14*R t 2 Use the function to find the areas of circles with radii of 6, 8, and 12. Use the computer to check your answers. PAST AND FUTURE BASIC Look back ... you have learned a lot about the language called BASIC. • Direct Statements9 SCR, RUN, LIST • Statements: PRINT, END, LET, INPUT, GO TO, READ, DATA, FOR, NEXT, IF, DIM, REMARK, GOSUB, RESTORE • Operations: +, -, *, /, t • Relations: =, <, >, <=~ >=, <> • Functions: INT, SQR, TAB, RND • Also: Numerals, numerical expressions, variables, variable expressions, traces, messages, loops, flowcharts, subscripted variables Briefly mentioned: • The SIN, COS, TAN, and ATN functions • The LOG, EXP, ABS, and SGN functions 9 A direct statement does not have a line number. It is executed immediately (when you press RETURN) instead of being stored in the computer's memory for later execution. Some people use the term "immediate statement" i:qstead of "direct statement." 1-132 Now you can "say" simple things in BASIC, but you are not yet fluent. As with any language, if you want to become fluent, you must use the language and also learn more about it. Look ahead . . . more to learn about BASIC . . . things that we haven't covered at all or have only mentioned briefly. • Statements DEF, GOSUB, ON . . . GO TO ... , RESTORE, RETURN, STOP • Logical Operations: AND, OR, NOT • Functions: ABS, ATN, COS, EXP, LOG, SIN, TAN The above are included in many versions of BASIC. But there are also some hopped-up versions of BASIC that have additional features. Look for: • Strings and String Variables • String Functions • Files Where do you look? For each EduSystem there is a chapter in this handbook that describes the exact characteristics of the language for that EduSystem. The following chart summarizes the BASIC statements, edit and control commands, and functions and indicates the EduSystems on which they are available; 1-133 Table 1-1. -I w BASIC Statements Statement Format Description Input/ Output CLOSE CLOSE DATA CLOSE CLOSEf DATA n 1 ,n 2 , ••• nn GET GET f,l,r INPUT INPUT V1 ,V 2 , ••• vn INPUT# INPUT#, V KILL KILL F$ LINPUT LINPUT v$l! V$2"" v$n LPRINT LPRINT e1 ,e 2 , ... ell Close open ouput data file. Close file f. Numbers n 1 through nn are variables for READ. Read record r, form as in line 1, from file f. Get VI' through VII input from Teletype. Get v (can be numeric and! or string variable) from input data file. Delete a stored data file named by F$. Get long character string from Teletype. Print values of specified text or expressions on line printer or high-speed paper tape punch. .;:... EduSystems 5 10 15 20 25 30 40 50 x x x x x x x x x x x x x x x x x x x x x x x x Table 1-1 (Cont.). Statement Format Description OPEN OPEN f,n$ OPEN A$ FOR INPUT Open a file named n$ as file f. Open an existing data file named by A$. Create or reopen an existing data file named by B$; x is number of blocks reserved for this file. Open a file; go to line n if unavailable. Print values of specified text, variables, or expressions. Format control (, or ;). Write data (numeric or string) onto die output data file .. Write record r, form as in line 1, in file f. Read variables v 1 through vn from DATA list. Reset DATA pointer to beginning value. OPEN B$ FOR OUTPUT,x '","'" '\.;) ""'" BASIC Statements OPEN-ELSE OPEN fELSEn PRINT PRINT eH e2 , ••• en PRINT# PRINT#,n PUT PUT f,l,r READ READ RESTORE RESTORE VI V1 ,V 2 , ••• vn EduSystems 5 10 1,5 20 25 30 40 50 x x x ·x x x x x x x x x x x x x x x x x x X x x x x x x x x Table 1-1 (Cont.). Statement Format Description RESTORE * RESTORE * RESTORE$ " RESTORE$ Reset DATA pointer for numeric data only. Reset DATA pointer for character string data only. Delete file from disk storage. Record data n l through nn on mass storage file . UN SAVE WRITE .... ....w I 0\ BASIC Statements UNSAVEf WRITE n 1 ••• n1l Transfer of Controls GO TO GOTOn IF-GO TO If el r e2 GO TO n IF-THEN ON-GO TO IF el r e2 THEN n IF el r e2 THEN x ON el GO TO 11 ,1 2 , ••• l n Loops and Subscripts DIM DIM v(d 1),v(dl'd 2 ) EduSystems 5 10 15 20 25 30 40 50 x x x x Transfer control to line n. If relationship r between e 1 and e2 is true, transfer control to line n. Same as IF-GO TO. I f relationship r between e 1 and e2 is true, then perform executable BASIC statement. Computed GO TO. x x x x x x x x x x x x x x x x Dimensions, variables subscripted. x x x x x x x x x x x x x: x x x x x ,x x "X x x Table 1-1 (Cont.). .... ....w I -..J BASIC Statements EduSystems 5 10 1520 25 30 40 50 Statement Format Description FOR-TO-STEP FOR v=el TO e2 STEP e3 x x x x x x x x NEXT NEXT v Set up program loop. Define v values beginning at el to e2, incremented by e3. Terminate program loop increment value of v until v (>e2). x x x x x x x x Subroutines GOSUB ON-GOSUB RETURN GOSUBn ON el GOSUB RETURN x x x x x x x x x x x x x x x x x X STOP STOP Enter subroutine at line n. Computed GOSUB. Return from subroutine to statement following GOSUB or ON-GOSUB. Transfer control to END statement. x x x x x x x x. Others CHAIN 'CHAIN$ CHAINn$ CHAIN$A$ x. x x x x CHANGE CHANGE v1 , TO V2 DEF DEF FNA(x)=f(x) DEF FNA(x,y)=(x,y) I~,I2'" .In Link to next user program. Link to public library program named in A$. Change character string to array of character codes. Define a function. x x x x x x x x x x Table 1-1 (Cont.). BASIC Statements EduSystems ..... ..... Statement Format Description 5 10 15 20 25 30 40 50 END LET END LETv=f x x RANDOMIZE RANDOMIZE RECORD RECORD REMARK SLEEP REM text SLEEPn End of program. Assign value of formula f to variable v. The word LET is optional. Randomizes random number routine. Define the size and composition of record. Insert a remark or comment. Cause program pause for n seconds. I w 00 V1 ,V 2 , ••• vll x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x Table 1-2. -I Command Format Description BYE CATALOG BYE CAT CAT$ CAT$ COMPILE CO~name Leave BASIC Monitor. List names of user programs. in storage ar~a. List names of public library programs. Compile program in core, save on disk. Stop program execution, return to edit mode. Delete line n. Delete line TI. Delete lines n through m inclusive. Search line n for character c. (See appropriate chapters for instructions on use.) List the data files stored by this user. List the public data files. Return. to keyboard mode after TAPE. f CTRL/C. CTRL/C y.) \0 BASIC Edit and Control Commands DELETE DELn n DELn,m EDIT EDIn (c) FILELOG FIL FILEIDG$ KEY FIL$ KEY EduSystems 5 10 15 20 25 30 40 50 x x x x x x x x x x x x x x x X x x X x x x x x x x' x x x x x x x x x x x x x x x x x x Table 1-2 (Cont.). Command Format Description LIST LIST LISTn List entire program in core. List program starting at line 11. List line n only. List lines n through m inclusive. List entire program, no header. List program starting at line n, no header. List program to line printer. Clear core, request program name. Clear core, bring program to core from storage area. Clear core, request public library program name, bring program to coreo from storage area. Replace old file on disk with version in core. If name not specified, old name retained. LISTn LIST n,m LISTNH LISTNHn '""" I '""" .j:::.. 0 BASIC Edit and Control Commands LLIST NEW LLIST NEW OLD OLD OLD$ OLD$ REPLACE REP REP name EduSystems 5 10 15 20 25 30 40 50 x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x Table 1-2 (Cont.). BASIC Edit and Control Commands EduSystems '""" ...... Command Format RUN RUN SAVE RUNNH SAVE name SCRATCH SCR TAPE TAP UN SAVE UNSAVEname BATCH ~CHO BATCH ECHO LPT LENGTH LPT LENGTH NAME NAME PTP PTP I ~ '""" Description Compile and run program in core. Same as RUN without header. Store program named on storage device. Erase current program from core. Read paper tape; suppress . printing on Teletype. Delete program named from storage area. Commence batch processing. Switch from printout to nonprintout mode or vice versa. Print output on line printer. Request number blocks to store current program. Same as NEW but does not delete existing program. Punch entire program on paper tape. 5 10 15 20 25 30 40 50 x x x x x x x x x x x x x x x x x x X: x x X x x x x x x x x x x x x x x x x x x x x x x x x x x x x x , Table 1·2 (Cont.). Command Format Description PTR PUNCH PTR PUNCH Read paper tape. Punch entire program on paper tape. Punch program starting at line n. Change name of program in core. Renumber program lines. Print output on Teletype. Enable use of privileged commands. Insert password, no echo. PUNCH n RENAME REN .... RESEQUENCE RESEQUENCE tv TIY TTY PRIVILEGE· PRIVILEGE I-" I .j::>.. BASIC Edit and Control Commands (password) Privileged Control Commands BATCHn BATCH HEADER HEADER (header) LOG LOG Same as BATCH, limit program runs to n. Change header; type new header (maximum 12 characters) for next batch run. Print system log. EduSystems 5 10 15 20 25 30 40 50 x x x x x x x X x x x x x x x x x x x x x x x x x x Table 1-2 (Cont.). Command Format Description MAX MAXn Set instruction limit n times 200 per program for next batch run. Change password, no echo. ..... PASSWORD I ..- ..r;:.. w BASIC Edit and Control Commands SAVE STACK PASSWORD '. (new password) SAVE STACK STACKn UN SAVE UN SAVE Save program in storage area. Start unattended batch operation. Same as STACK; limit runsl program. Delete program from storage area. EduSystems 15 20 25 . 30 40 50 5 10 x x x x x x x x x x x x x x x x x x Table 1-3. BASIC Functions and Arithmetic Operations EduSystems 5 ]0 15 20 25 30 40 50 Functions Description SQR(x) SIN(x) COS(x) TAN (x) Square root of x(vx) Sine of x (x in radians) Cosine of x (x in radians) Tangent of x (x in radians) Arctangent of x (x in radians; result in radians) eX (e=2.712818) Natural log of x (lo~x) Absolute value of x (Ixl) Greatest integer of x Sign of x (+ 1 if positive, -1 if negativc, 0 if zero) Random number betwecn 0 and 1 Truncates decimal portion of x Controls printing head position on Teletype Converts character code to character. Used only with PRINT statement. ATN(x) EXP(x) LOG (x) ABS(x) INT(x) SGN(x) RND(x) FIX(x) TAB (x) CHR$(x) 1-144 x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x Table 1-3 (Cont.) Functions BASIC Functions and Arithmetic Operations EduSystems 5 10 15 20 25 30 40 50 Description MID(A$,M,N) Returns N characters, starting at the Mth character of A$. LEN(A$) Returns the number of characters in A$. CAT(A$,B$) Returns a string of A$ concatenated with B$ (maximum of 6 characters returned). Arithmetic Operations SYMBOLS t exponentiation * multiplication I division + addition subtraction ORDER OF EXECUTION 1. Parenthetical expressions 2. Exponentiation 3. Multiplication and Division 4. Addition "and Subtraction 1-145 x x x 1-146 2 edusystems INTRODUCTION EduSystem 5 is a BASIC-speaking supercalculator--calculator because it can be used like a calculator to obtain fast, accurate results, super because it is a computer that ·'uses BASIC and does much more than calculate. EduSystem 5 has the ability to operate in two modes: immediate and programmable. Immediate mode allows the user to perform arithmetic calculations and obtain immediate results without writing programs. The problem and the solution are printed at the Teletype to provide a hard copy for future reference. In programmable mode, one uses BASIC to write programs and type them on the Teletype keyboard. Programs are stored in computer memory and can be printed via the teletype and, if desired, punched on paper tape to be used again in the future. EduSystem 5 BASIC contains all the elements needed to write and execute meaningful programs. In addition, it provides several special features. • Several commands may be typed on a single line. PrograIll;s using this feature require less storage in the computer, thus enabling users to write longer programs. • A colon (:) may be used in place of the PRINT command to save time and storage space. • Typing errors are easily corrected with the use of the ALT MODE (or ESCAPE), ~ back arrow, or RUB OUT key. • INPUT statement responses may be either mathematical expressions or numeric values. All these features, and more, are yours with EduSystem 5. And it expands. If your needs grow beyond EduSystem 5, you can expand it, with a few simple additions, to an intermediate-scale EduSystem 15. 2-1 System Components EduSystem 5 is composed of a table-top computer (PDP-8/F) with 4096 words of core memory and a Teletype with paper tape reader and punch. An optional off-Jine Teletype with paper tape reader and punch allows users to prepare paper .tapes of their programs before coming to the EduSystem 5 and increases the number of persons who may use it each day. Each EduSystem 5 includes the BASIC language processor, a user's guide, and a self-teaching workbook for ·learning the BASIC language. System Expansion . EduSystem 5 is easily expanded to EduSystem 15 by adding a DECtape magnetic tape drive (TD8-E), memory extension control, 256 word read-only memory, and an EduSystem 15 software kit. (See Chapter 4 for a full description of the capabilities of EduSystem 15.) BASIC LANGUAGE CAPABILITIES EduSystem 5 BASIC includes the language elements shown in Table 2-1. These elements are used as explained in Chapter -1. Differences jn usage for EduSystem 5 are discussed below. Line Numbers In EduSystem 5 BASIC there is no upper limit on the size of the line number for any statement. Single-Character PRINT Command EduSystem 5 permits the use of a colon (:) in place of the PRINT command. This abbreviation can be used in place of PRINT in either programmable or immediate mode. The statement format is the same as that of the PRINT command, for example: 1eJ : 5+ 10 :is the same as 10 PR I NT 5+ 10 Multiple Statements per Line EduSystem 5 allows more than one command to single line. Commands after the first begin with character ("), typed as SHIFTIL on the keyboard. often more. understandable when statements, such 2-2 be a A as typed on a back slash program is a series of LET's!, are grouped into a single line. For example, tbe program: 10 A= 1\ 8= 4 \ C= 6 20 : (A+B )*C 99 END is the same as 10 20 32J LET A= 1 LET 8=4 LET C=6 40 PRI NT (A+8)*C 99 END and will produce the same result when the RUN command typed: IS RUN 30 This capability is helpful when the program to be written is too big for EduSystem 5. Commands take less storage in the computer when they are grouped as a single statement. Immediate Mode EduSystem 5 allows certain BASIC statements to be used in immediate mode, that' is, to be issued and ,executed immediately without being included in a formal program. Commands commonly used with immediate mode are PRINT, (or:), LET; FOR, and NEXT. Immediate mode is a quick way to calculate expressions and equations. For example, the statement :SIN(l),COS(l),TAN(l) followed by the RETURN key, causes the sine, cosine, and tangent of 1 radian to be printed immediately, as follows: 0.841471 0.540302 1.55741 Typing multiple commands per line is especially useful in the immediate mode. A table of square roots of the .first 10 integers lRemember that the word LET is optional in the LET statement. 2-3 could, for example, be generated by typing the following single line and pressing the RETURN key: FOR 1:1 TO 10\: SQRCI),\NEXT I 1 2.44946 1.41421 2.64575 1.73205 2.82843 2 3 2.23607 3.16228 Although they are rarely used, other BASIC commands are available in immediate mode. The immediate GOTO command may be used to start a program at a point other than the beginning. This is accomplished by loading the program into the computer memory and typing, for example: GO TO 200 - After the RETURN key is pressed, the program execution will begin automatically at line number 200. In this case, the RUN command need not be typed. INPUT Statement EduSystem 5 allows the student to respond to the INPUT query (?) with either a mathematical expression or :a numeric value. An e~pression entered as input may contain one or more arithmetic operations and may use any available BASIC function. For example, the BASIC statement: 10 INPUT X could be answered in any of the following ways: ? 10 t5+6 1SQR(4f2-2) 1LOG(186) , As explained in Chapter 1, the INPUT statement may have multiple inputs. These inputs may be either mathematical expressions or numeric values. For example, the BASIC statement 10 INPUT A,B,C could be answered as follows: 1512,INT(876.33),7+6t25 2-4 NOTE Remember that you use CTRL/C to stop a program that is running. PROGRAM EDITING There are two times when a program may require editing ·pro:cedures. The first occurs while a line is being typed but before the RETURN key has been pressed. The second occurs when a line has been completely typed and the RETURN key has been pressed. Each situation has its own editing procedures. Procedure 1: Before the RETURN key is pressed. Three keys may be used to correct typing ~rrors: ALT MODE (or ESCAPE), ~ (back arrow), or RUBOUT. \, ALT MODE (or ESCAPE) is used to delete an entire line. When this key is used, BASIC prints $DELETED, erases that line from the program, and returns the carriage so that line may be retyped. ~ (back arrow), SHIFTjO on the keyboard, or RUB OUT is u'sed to delete a character from a line. BASIC prints a back arrow, deleting the last character from that line. More than one back arrow deletes more than one character, in reverse .order. Procedure 2: After the RETURN key is pressed. Once aline of the program has been transmitted to computer memory via the RETURN key, several methods of correction may be. used. Lines may be inserted, deleted, or changed. INSERTION: To add a line to a program, assign, a line number that falls between two existing lines, type the line number and text, and press RETURN. DELETION: To erase a line from computer memory, type the line number only and press the RETURN key. CHANGE: To change an individual line, simply retype it. The old instruction is replaced by the new one. ERROR MESSAGES EduSystem 5 checks all commands before executing them. If it cannot execute a command, it informs the user by printing one' 2-5 ~ of the following messages arid the line number in which the error was found, Message Explanation SYNTAX ERROR Command does not have correct syntax. Common examples of syntax errors are misspelled commands, unmatched parentheses, and other typographical errors. The function used was deleted at system load time and thus is not available. A DEF statement will produce this message if the DEF capability was deleted. Program and variables exceed computer capacity. Reducing one or the other may help. If the program has undergone extensive revision, try punching it out, typing SCR, and reloading. The subscript used is otltside the DIM statement limits. A branch statement (GOTO, GOSUB, or IF) references a nonexistent line. FOR loops are too deeply nested. FOR and NEXT statements are improperly paired. Subroutines are too deeply nested. GOSUB and RETURN statements are improperly paired. No more items are in the data list. A function has been given an illegal argument, e.g., SQR(-l). FUNCTION ERROR TOO-BIG ERROR SUBSCRIPT ERROR LINENO ERROR FOR ERROR NEXT ERROR GOSUBERROR RETURN ERROR DATA ERROR ARGUMENT ERROR To correct the error indicated by the message, the appropriate line in the program must be corrected in the manner described under Program Editing, Procedure 2. OPERATING INSTRUCTIONS Initial Installation When EduSystem 5 is first installed, it must be loaded with a special software program, the BASIC language processor. Once this software is loaded, it need not be reloaded. Perform the following steps to load BASIC. 1. Plug the EduSystem 5 computer into a standard 3-prong 2-6 electrical outlet. Plug the Teletype into a second standard outlet. Turn the key lock on the front of the computer to the power position and turn the Teletype to line. Set all switches on the SWITCH REGISTER (to the left of the ADDR LOAD switch) to the "down" position and press the EXTD ADDR LOAD switch. 2. Perform the following set of switch manipulations. In each step, there are 12 figures which correspond to the 12 switches labeled SWITCH REGISTER (SR) on the front of the computer. The symbol indicates that the corresponding switch should be set to its "up" position. The 9 symboi means that the corresponding switch should be set to its "down" position. The octal instructions which correspond to this diagram OCTAL appear on the right.2 * *9999 9" 9??' 9" ?M .?* 999 ?" 99. 99'9 999 999 *9* 99* Set SR to: . . . . . . Set SR to: Set SR to: Set SR to: Set SR to: _9 -9 *? "9 Set SR t o : ' " Set SR t o : ' " 999 Set SR to: "9999 Set SR to: .9* 9__ Set SR to: . . 9 999 Set SR to: *99 Set SR t o : ' " Set SR to: SetSRto: Set SR to: 999 9" _9 9*. 9*9 *-9" ... ... 6032 99* then lift DEP ... then lift DEP "9 then lift DEP "9 then lift DEP "9 then lift DEP 999 thenliftDEP 6031 5357 6036 7106 7006 7510 then lift DEP 5357 -9 then lift DEP 99* then lift DEP ... 'then lift DEP * 99 then lift DEP 999 then lift DEP **9 then lift DEP 7006 ?" ... _9 *9* 9" *\2* "9 9** then pressADDR LOAD 7756 then lift DEP .9- 9" .9_ ... SetSRto: . . . Set SR to: "? 9*9 6031 5367 6034 7420 3776 thenliftDEP 3376 then lift DEP and again lift DEP 5356 2The octal instructions are provided for those familiar with the octal, or base 8, number system. An explanation of this system is included in Introduction to Programming 1972. 3. Place the tape labeled EDUSYSTEM-5 in the Teletype paper tape reader. Position the tape at the: single row of holes punched at the beginnXl;f the tape. 4. Set the SR to . . . (7756); then press ADDR LOAD. Press the CLEAR switch, then the CONT switch. Push the paper tape reader switch to the START position. The tape should read in. If it stops before the end of tape, an error has occurred. Repeat steps 2, 3, and 4. 5. When the tape has read in properly, BASIC prints the following message: SEL·ECT THE SMALLEST SET OF FUNCTIONS NEEDED FROM THE FOLLOWING CHOICES AT N I IXI I I I I I LOG+EXP I IXIXI I I I I SIN+COS+TAN I tXIXIXI I ! I DEF(FN) I IXIXIXIXI I I SQR I IXIXIXIXIXI I RND I IXIXIXIXIXIXI .9." OPTION ABC 0 E F G TyPE OPTION LETTER? At this time, it is possible to delete any functions which will not be used. In response to the question "TYPE OPTION LETTER1", type the letter of the option that represents the functions needed. Deleting functions increases the size of the BASIC program which may be accommodated. If all functions are deleted (option A), the maximum program size is approximately 60 lines; If all functions are retained (option B), the maximum program size is approximately 30 lines. .. 6. After the functions have been selected, BASIC prints the following question: DO SUBSCRIPTS START AT 0 OR I? Indicate whether subscripts will begin at 0 or 1. Many BASIC programs do not use the zero element of an array. If this is the case, setting subscripts to start at 1 allows larger programs to be run. 7. EduSystem 5 is now ready for use. Turn the key lock to - PANEL LOCK and remove the key to prevent the system from being accidentally disturbed. 2-8 Turning Off the System Perform the following steps to turn off the EduSystem 5: 1. Type CTRL/C to stop any program that is running. 2. Turn the key lock to OFF. Restarting the System Perform the following steps to restart the EduSystem 5: 1. Turn the key locl<: to POWER. 2. Press the CLEAR switch, then the CONT switch. 3. EduSystem 5 is now ready for use. Turn the key lock to PANEL LOCK and remove the key to prevent the system from being accidentally disturbed. Reloading the Functions If a need arises for. functions which were deleted at system load time, the functions can be reloaded without reloading the entire system. Perform the following steps to reload the functions: 1. Type CTRL/C to stop any program that is running. 2. Turn the key lock to the. POWER position; press the HALT switch, then raise it again. 3. Follow the procedure for Initial Installation, starting at step 3. Use the shorter tape labeled EDUSYSTEM-5 FUNCTIONS ONLY instead of the EDUSYSTEM-5 tape. Saving Programs on Paper Tape Once a program has been typed in correctly, it may be saved on paper tape so that it may be reloaded quickly. To save the program, follow this sequence of steps: 1. 2. 3. 4. 5. 6. 7. 8. Turn the Teletype control knob to LINE. Type LIST but do not press the RETURN key. Turn the Teletype pap~r tape punch ON. Turn the Teletype control knob to LOCAL. Press the HERE IS key to produce some leader tape. Turn the Teletype control knob to LINE~ Press RETURN. When punching is complete, turn the control knob to LOCAL. 9., Press the HERE IS key to produce some trailer tape. 2-9 10. Turn the Teletype punch OFF. 11. Turn the Teletype control knob to LINE. Reloading Programs from Paper Tape Programs punched out on paper tape may be reloaded using the Teletype paper tape reader. To reload programs, follow this sequence of steps: I.. Turn the Teletype control knob to LINE. 2. 3. 4. 5. Type SCR, then prcss the RETURN key. Insert the program tape in the reader. Turn the Teletype reader to ST ART. When the tape has read in~ turn the Tcletype reader to FREE. 2-10 Table 2~1. EduSystem 5 BASIC Statement Summary Statement Description LET PRINT (or:) READ DATA GOTO IF GOTO} IF THEN FOR TO STEP NEXT GOSUB RETURN INPUT REM (or ') RESTORE DEF Assign a value to a variable. LET j,s optional. Print out the indicated information. Assign values from data list to variables. Provide data for a program. Change order of program execution: Conditionally change order of program execution. Set up a program loop. End of program loop. Go to a subroutine. Return from a subroutine. Get values of expressions from the Teletype. Insert a program comment. . Restore the data list. Define a function. (Availability must be re~ quested when system is loaded.) Stop program execution. End a program. Define subscripted variables . STOP END . DIM Functions:l ABS(X) ATN(X) COS(X) EXP(X) INT(X) LOG(X) . RND(X) SGN(X) . Absolute value of x Arctangent of x(result in radians) Cosine of x(x in radians) eX (e=2.718282) Greatest integer of x Natural logarithm of x Random number Sign of x( + 1 if positive, -1 if negative, oif zero) SIN (X) Sine of x(x in radians) SQR(X) Square root of x TAN (X) Tangent of x(x in radians) . Editing! Control Commands LIST List all stored program statements. LIST n List program statements beginning at line n. RUN Run the currently stored p,rognim. SCR Delete the currently stored program. CTRL/C Stop execution of a program or printing of a' listing. CTRL/C is typed by pressing C while holding down the CTRL key. < RThe ABS, INT, and SGN functions are always available. Other functions (and the DEF statement) must be selected when the system is loaded. (See Initial Installation, step 5.) 2-11 2-12 3 edusystem 10 INTRODUCTION EduSystem lOis a mini-EduSystem with maxi-potential. It speaks a very fluent BASIC with all the standard features and a few special ones. It provides printed output and paper tape reading and punching. EduSystem 10 even tells you when you make a mistake and provides simple corrective measures. So why, with all EduSystem 10 has to offer, do we call it a starter system? Because EduSystem 10 can expand as your needs expand. It has the built-in potential to grow into larger Edu.Systems-EduSystem 20 or 30 at first, and as big as you want to go thereafter. Even though it isn't as powerful as the larger EduSystems, EduSystem 10 has some features that even some of the big ones can't duplicate. Two operating modes are available: immediate and programmable. Immediate mode lets you perform arithmetic calculations without writing program~. Programmable mode lets you write programs in BASIC, store them in the co~puter., and punch·· them 011 paper tape. Both modes provide the problem and the solution on printed output. Other features include: • Multiple statements per line to save computer storage space and let you write longer programs. • An abbreviated PRINT command, colon (:). • Special keys (ALT MODE, RUB OUT, and ~) fot correcting typing errors. • Mathematical expressions or numeric values as responses to the INPUT statement. System Components EduSystem 10 is composed of a table-top computer (PDP-8/E), 4096 words of cor~ memory, automatic 10Cider (hardware bootstrap), and a Teletype with paper tape reader and punch. Each 3-1 EduSystem 10 includes a BASIC language processor and a library of sample programs, textbooks, and curriculum guides. Optional components for EduSystem 10 include one or more Teletypes for off-line preparation of paper tape and a high-speed paper tape reader and punch which facilitates the use of other system capabilities such as FOCAL, FORTRAN, and assembly language. System Expansion EduSystem 10 may be easily expanded to either EduSystem 20 or EduSystem 30. To expand to EduSystem 20, add 4096 words (or more) of core memory, an EduSystem 2:0 software kit, and as many as 7 additional Teletypes with interfaces. To expand to EduSystem 30, add one DECdisk or DECtape, an optical mark card reader, and an EduSystem 30 software kit. (Chapters 5 and 7 fully describe the capabilities of EduSystem 20 and EduSystern 30, respectively.) BASIC LANGUAGE CAPABILITIES EduSystem 10 BASIC includes the language elements shown in Table 3-1. Normally, these elements are used in programs as explained in Chapter 1. BASIC usage differences with EduSystem 10 are explained below. Line Numbers . EduSystem 10 BASIC does not place an upper limit on the size of the line number for any statement. Single-Character PRINT Command A colon (:) may be used in place of the PRINT command. This abbreviation may be used in either programmable or immediate mode. The statement format is the same as that of the PRINT command, for example: 10 :SQR(A+B) is the same as 10 PRINT SQR(A+B) Multiple Statements per Line EduSystem 10 allows more than one command to be typed on a single line. Comma~ds after the first begin with a back slash character (") typed as SHIFT/L on the keyboard. A program is often more understandable when statements, such as a series of 3-2 LET's!, are grouped into a single line. For example, the program 100 1"0 X=2\Y=8\Z= 12 1l~ :Y IX*Z 999 END • . is the same as 110 120 130 999 LET X=2 LET Y=8 LET Z= 12 PRINT Y/y:*Z END _ and will produce the same result when the RUN command typed: IS RUN 48 The multiple..,statement capability is helpful when the program to be written is too big for EduSystem 10. Commands require less storage in the computer when they are grouped as a single statement. . Immediate Mode EduSystemlO allows certain BASIC statements to be used in immediate mode, that is, to be issued and executed immediately without being included in a formal program. Commands commonly used with immediate mode are PRINT (or:), LET, FOR, and NEXT. Immediate mode is a quick way to calculate expressions and equations. For example, the statement: : INT(76.87 + 2.9) followed by the RETURN key, causes the value of the nearest integer to be printed immediately, as follows: 79 Typing multiple commands per line is especially useful in the immediate mode. A table of random numbers could, for example, be generated by typing the following single line and pressing the RETURN key: lRemember that the word LET is optional in the LET statement. 3-3 rOR I:l TO 20\PRINT RNO(0),\NEXT I 0.217873 0.767746 0.793J94 0.804367 0.696209 0.829399 0.644913 0.992458 0.29751 0.181667 0.927201 0.68785 0.96·3794 0.15:9454 0.894656 0.619773 0.463246 6.52568E-2 r2J.974861 0.731568 Although they are rarely used, other BASIC commands are available in immediate mode. The immediate GOTO command may be used to start a program at a point other than the beginning. This is accomplished by loading the program into the' computer memory and typing, for example: GO TO 35 After the RETURN key is pressed, the program execution will begin automatically at line number 35. In this case, the RUN command need not be typed. INPUT Statement The INPUT statement described in Chapter 1 allows a number to be entered from the Teletype as the value for a variable. EduSystem 10 allows the student to respond to the INPUT query (?) with a value or a mathematical expression. An expression may contain one or more arithmetic operations and may use any available BASIC function. For example. the BASIC statement: 10 INPUT X could be answered in either of the following ways: 1SQR(100) + 20t2 This capability could be used to enable one program to solve more than one problem. As explained in Chapter 1, the INPUT statement may have multiple inputs. These inputs may be either mathematical expressions or numeric values. For example, the BASIC statement: 100 INPUT X,Y,Z 3-4 could be answered as follows: j ?23,INT(284.978),25+86t9 ... NOTE When using the INPUT statement in program~, remember that CTRL/C is used to stop a program that is running. Table 3-1. EduSystem 10 BASIC Statement Summary Statement LET Description DIM Assign a value to a variable. LET is optional. Print out the indicated information. Assign values from data list to variables .. Provide data for a program. Change order of program execution. Conditionally change order of program execution. Set up a program loop. End of program loop. Go to a subroutine. Return from a subroutine. Get values or expressions from the Teletype. Insert a program comment. Restore the data list. Define a function. (Availability must be requested when system is loaded.) Stop program execution. End a program. Define subscripted variables. Fundions2 ABS(X) ATN(X) COS(X) EXP(X) INT(X) Absolute value of x , Arctangent of x (result in radians) Cosine of x (x in radians) eX (e = 2.718282) Greatest integer of x PRINT(or :) READ DATA GOTO IF GOTO} IF THEN FOR TO STEP NEXT GOSUB RETURN . INPUT REM(or ') RESTORE DEF STOP END 2The ABS, INT, and SON functions are always available. Other functions (and the DEF statement) must be selected when the system is loaded. (See Initial Installation, step 5.) 3-5 Table 3·1. (Cont.) EduSystem 10 BASIC Statement Summary D(:scription Statement Functions (Cont.) LOG(X) RND(X) SGN(X) SIN(X) . SQR(X) TAN (X) Editing/ Control Commands LIST LIST n RUN SCR CrRL/C , N aturallogarithm of x Random number Sign of x (+ 1 if positive, - 1 if negative, 0 if zero) Sine of x (x in radians) Square root of x Tangent of x (x in radians) List all stored program statements. List program statements beginning at line n. Run the currently stored program. Delete the currently stored program. Stop execution of a program or printing of a listing. CTRLI C is typed by pressing -C while holding down the CTRL key. PROGRAM EDITING There are two times when a program may require editing procedures. The first occurs while a line is being typed but before the RETURN key has been pressed. The second occurs when a line has been completely typed and the RETURN key has been pressed. Each situation has its own editing procedures. Procedure 1: Before the RETURN key is pressed. Three keys may be used to correct typing errors: ALT MODE (or ESCAPE), ~(back arrow), or RUBOUT. ALT MODE (or ESCAPE) is used to delete an entire line. When this key is used, BASIC prints $DELETED, erases that line from the program, and returns the carriage so that the line may be retyped. ~(back arrow), SHIFT /0 on the keyboard, or RUBOUT is used to delete a character fro in a line. BASIC prints the back arrow, deleting the last character from that line. More than one back arrow deletes more than one character, in reverse order. 3-6 Procedure 2: After the RETURN key is pressed. Once a line of the program has been transmitted to computer memory via the RETURN key; several methods of correction rna)' be used. Lines may be inserted, deleted, or changed. \ INSERTION: To add a line to a program, assign a line number that falls between two existing lines, type the line number and text, and press RETURN. DELETION: To erase a line from computer memory, type the line number only and press th.e RETURN key. CHANGE: To change an individual line, simply retype it. The old instruction is replaced by the new one. ERROR MESSAGES EduSystem 10 checks all commands before executing thetn: if it cannot execute a comm.and, it informs the user by printing one of the following messages and the line number in which the error was found. Message SYNTAX ERROR FUNCTION E~ROR Explanation Command doeS' not have correct syntax. Common examples of syntax errors are misspelled commands, unmatched parentheses, and other typographical errors. The function used was deleted at system load time and thus is not available. A DEF statement wili produce this message if the DEF capability was deleted. . TOO-BIG ERROR Program and variables exceed computer capacity. Reducing one or the other may help. If the program has undergone extensive reVISIOn, try punching it out, typing -SCR, and reloading. SUBSCRIPT ERROR The sUbscript used is outside the DIM statement limits, 3-7 Message Explanation LINENO ERROR A branch statement (GOTO, GOSUB, or IF) references a nonexistent line. FOR ERROR FOR loops are too deeply nested. NEXT ERROR FOR and NEXT statements are improperly paired. GOSUB ERROR Subroutines are too deeply nested. RETURN ERROR GOSUB and RETURN statements are improperly paired. DATA ERROR No more items are in the data list. ARGUMENT ERROR A function has been given an illegal argument. e.g., SQR( - ] ) . To correct the error indicated by the message, the appropriate line in the program must be corrected in the manner described under Program Editing, Procedure 2. OPERATING INSTRUCTIONS Initial Installation When EduSystem lOis first installed, it must be loaded with a special software program, the BASIC language processor. Once this software is loaded, it need not be reloaded. Perform the following steps to load BASIC. 1. Plug the EduSystem 10 computer into a standard 3-prong electrical outlet. Plug the Teletype into a second standard outlet. Turn the key lock on the front of the computer to POWER and the Teletype swith to LINE. Set all switches on the SWITCH REGISTER (to the left of the ADDR LOAD switch) to the "down" position and press the EXTD ADDR LOAD switch. 2. If the computer does not include a hardware bootstrap loader~ perform the following set of switch manipulations;3 otherwise, proceed to step 3. In each step, there are 12 figures which correspond to the 12 switches labeled SWITCH REGISTER (SR)· on the front of the computer. The • symbol indicates that the 3If the EduSystem 10 is equipped with a high-spf:ed paper tape reader and punch, see instructions for the RIM (Read-in-mode) loader in Appendix A. 3-8 ,corresponding switch should' be set to its "up" position. The ? symbol means that the corresponding switch should be set to its "down" position. The octal instructions which correspond to this diagram appear on the right. 4 ' Set SR to: . . . SetSRto: Set SR to: Set SR to: Set SR to: "9 "9 -9"9 SetSRto: . . . Set SR to: . . . SetSRto: . . . Set SR to: -9- Set SR to: . . . "9 Set SR to: _ 9_ Set SR to: "9 Set SR to: Set SR t o : ' " 9" Set SR to: 9" Set SR to: -9- Set SR to: iii _r_ 'i 999 9" 999 9" 9" -9999 9" 99- 999 999 999 -9-999" es;999 999 999 9" 9" '"9 999 9" -99 9-9 ...... 9- ... 9" ~- OCTAL "~ then pressADDR LOAD 7756 9-9 then lift DEP 99- then lift DEP 6032 . . . then lift DEP 5357 "9 then lift DEP "9 then lift DEP "9 then lift DEP 999 then lift DEP 6036 6031 7106 7006 7510 . . . . then lift DEP 5357 "9 then lift DEP 99- then lift DEP 7006 6031 . . . then lift DEP 5367 -99 999 "9 "9 -9 then lift DEP 6034 then "lift DEP 7420 then lift DEP 3,776 then lift DEP 3376 then lift DEP and again lift DEP 5356 3. Place the tape labeled EDUSYSTEM-IO in the Teletype paper tape reader. Position the tape at the single row of holes punched at the beginning of the tape. 4. It the computer does not include a hardware bootstrap loader, perform the operations in step 4b. If it has a bootstrap loader, perform the steps in 4a. a. Set the SR to-9- 9" -9- "s:(5356); then lower and lift the switch labeled SW. Proceed to step 6. -9- .. b. Set the SR to... . . . ~ (7756); then press ADDRLOAD. 5. Press the CLEAR switch, then the CONT switch. Push the paper tape reader switch to the START position. The tape' 40ctal instructions are provided for those familiar with the octal or base 8 number system. An explanation of this system is included in Introduction to Programming 1972. 3-9 should read in. If it stops before the end of tape, an error has occurred. Repeat steps 2, 3, and 4. 6. When the tape has read in properly, BASIC prints the following message: SELECT THE SMALLEST SET OF' F'UNCTIONS NEEDED F'ROM THE F'OLLOWING CHOICES I IX I I I I I I ATN LOG+EXP I IX1XI I I I I SIN+COS+TAN I IXIXIXI I I I DEFCF'N) I lX1XIX1XI I I SQR I IXIXIX1XIXl I RHD I IXIXIXIXIX1XI OPTION ABC D E F' G TyPE OPTION LETTER? At this time, it is possible to delete any functions which will not be used. In response to the question "TYPE OPTION LETTER?", type the letter of the option that represents the functions needed. Deleting functions increases the size of the BASIC program which may be accommodated. If all functions are deleted (option A), the maximum program size is approximately 60 lines. If all functions are retained (option B), the maximum program size is approximately 30 lines. 7. After the functions have been selected, BASIC prints the following question: DO SUBSCRIPTS START AT 0 OR I? Indicate whether subscripts will begin at 0 or 1. Many BASIC programs do not use the zero element of an array. If this is the case, setting subscripts to start at 1 allows larger programs to be run. 8. EduSystem 10 is now ready for use. Turn the key lock to PANEL LOCK and remove the key to prevent the system from being accidentally disturbed. Turning Off the System Perform the following steps to turn off the EduSystem 10: 1. Type CTRL/C to stop any program that is running. 2. Turn the key lock to OFF. 3-10 Restarting the System Perform the following, steps to restart the EduSystem 10: 1. Turn the key lock to POWER. 2. Press the CLEAR switch, then the CONT switch. 3. EduSystem lOis now ready for use. Turn the key lock to PANEL LOCK and remov~ the key to prevent the system from being accidentally disturbed. Reloading the Functions If a need arises for functions which were deleted at system load time, the functions can be reloaded without reloading the entire system. Perform the following steps to reload the functions: 1. Type CTRL/C to stop any program that is running. 2. Turn the key lock to the POWER position; press the HAL T switch, then raise it again. 3. Follow the procedure for Initial Installation, starting at step 3, Use the shorter tape labeled EDUSYSTEM-10 FUNCTIONS ONLY instead of the EDUSYSTEM-I0 tape. Saving Programs on Paper Tape Once a program has been typed in correctly, it may be saved on paper tape so that it may be reloaded quickly. To save the' program, follow this sequence of steps: 1. 2. 3. 4. 5. 6. 7. 8. Turn the Teletype control knob to LINE. Type LIST but do not press the RETURN key. Turn the Teletype paper tape punch ON. Turn the Teletype control knob to LOCAL. Press the HERE IS key to produce some leader tape. TUrn the Teletype control knob to LINE. Press RETURN. When punching is complete, turn the control knob, to LOCAL. 9. Press the HERE IS key to produce some trailer tape. 10. Turn the Teletype punch OFF; 11. Turn the Teletype control knob to LINE. 3-11 Reloading Programs from Paper Tape Programs punched out on paper tape may be reloaded using the Teletype paper tape reader. To reload programs, follow this sequence of steps: 1. 2. 3. 4. 5. Turn the Teletype control knob to LINE. Type SCR, then press the RETURN key. Insert the program tape in the reader. Turn the Teletype reader to START. When the tape has read in, turn the Teletype reader to FREE. 3-12 edusystem15 INTRODUCTION EduSystem 15 combines an extended BASIC language with online DECtape storage to provide a reliable, powerful system. Edu-. System 15 BASIC has all the standard elements of Dartmouth BASIC plus several extended features. BASIC programs run on EduSystem 15 can be virtually limitless in size, up to 10,000 lines; due to a chaining feature that allows programs to be written in sections, then connected. A mini-string feature permits users to input, manip1.J1ate, and output alphanumeric character data, one character at a time. The ability to store programs on the systemDECtape and to retrieve them when needed eliminates the time required to read in paper tapes or type in lengthy programs. And EduSystem 15 offers protection too: a series of privileged commands that control storing programs on DECtape and deleting stored programs from DECtape. These privileged commands can be used only if the user knows the secret password. These features and more make EduSystem 15 an extremely useful classroom tool. System Components EduSystem 15 is composed of a table-top computer (PDP-8jF) , 4096 words of core memory, a 256-word Read-Only Memory (ROM) for automatic loading, TD8-E DECtape, and a Teletype with paper tape reader and punch. Each EduSystem 15 .includes the BASIC language processor and a library of sample programs, textbooks, and curriculum guides. Optional components for the EduSystem 15 include a second off-1ine Teletype for preparation of programs and an optional mark card reader for card processing. The system can also support high-speed paper tap& reader/punch and line printer. 4-1 BASIC LANGUAGE CAPABILITIES EduSystem 15 BASIC includes the language elements shown in Table 4-1 at the end of this chapter. Normally, these elements are used as explained in Chapter 1. EduSystem 15 also includes many advanced BASIC features to allow the user to perform more complicated and lengthy problem solving routines. BASIC usage differences and advanced features are explained in this section. . Entering Programs EduSystem 15 BASIC expects each program to have an assigned name. At the beginning of each programming session, the NEW command should be typed to clear any existing program and define the name of the new program to be entered. 1 To use the NEW command, the user types: NEW and the computer asks for: NEW FILE NAr1E-- The user then types any name of 1 to 6 characters, followed by the RETURN key.· BASIC assigns that name to the program to be entered. The user may change the name of the program being entered at any time by typing the NAME command. BASIC again asks for NEW FILE NAME and assigns a new name to the program being entered. The NAME command does not delete the existing program. Using Random Numbers The RND function allows the use of random numbers within a program. Each time it is used, the RND function returns as its value a random value between 0 and 1. Unlike the other functions, the value returned by RND is not a function of its argument. However, all functions in BASIC must be followed by an argument. Therefore, RND should always be followed by a dummy argument, such as zero, which is enclosed in parentheses. IIf the user does not wish to assign a program name, he can delete any existing program by typing the SCRATCH command. 4-2 NOTE Notc that it is possible to generate random numbers over any range. For example, the cxpression: (B- A) *R ND (0 )+A has a random value in the range A < n < B. Repeated uses of RND in a program return different values between 0 and 1. The sequence of numbers is, however, the same each time the program is run. Thus, the sequence is reproducible for later checking of the program. The RANDOMIZE statement allows the user to make the random number sequence returned by the RND function different each time a program is run. That is, when executed, the RANDOMIZE statement causes the RND function to select randomly a new sequence of random numbers. If RANDOMIZE is used, it normally appears as one of the first lines in a program. J-Jisting the Program . The LIST command may be used to list out all or a part of the current program. LIST prints the program statements in their proper order, regardless of the order in which they were entered. EduSystem 15's LIST command has four different forms, as shown below. Command· Meaning LIST List the entire program. Precede it by a header line 2 giving the name of the program. LIST n List the program starting at the given line number (n).. Precede it by a header line. The line number must be separated from LIST by two spaces. LISTNH List the entire program but do not print a header line. 2A header line consists of the program name followed, on the same line, by the system name (EDU BASIC). If no program name was assigned, the . system prints "*NONE* EDU BASIC". 4-3 Command Meaning LISTNHn List the program starting at the given line number (n) but do not print a header line. NOTE The programmer may stop a listing at any time by t.yping CTRL/C on the keyboard. Executing the Program The programmer may execute a program at any time by typing the RUN command. The existing program is inspected for errors; if none exist, it is executed. If an error is detected, an error message (see Error Messages) is printed. In either case, at the end of the run, BASIC prints READY, indicating: that the program may now be changed or rerun. There are two types of RUN commands: RUN and RUN NH. RUN executes the current program, preceding it by 'a header line" RUN NH executes the current program but does not print a header line (RUN and NH must be separated by a single space). Privileged Control Commands . Several optional commands are available which modify and control a program run. All of them are considered to be privileged instructions in the sense that the use of them is restricted. The privileged commands are available only if the privileged command capability was selected when EduSystem 15 was loaded. During normal system operation these commands are locked out; if a user attempts to use a privileged command, it is ignored and the system prints WHAT? A speci~ll command, the PRIVILEGE command, is used to unlock and make these privileged instructions available. To use it, the user types PRIVILEGE and then the RETURN key. The system then waits for the user to type a one to six character password code. (The typed characters are not printed.) At the time the system was loaded, a password was typed by the user or assigned by the system. The characters typed in after the PRIVILEGE command are compared to this password. If they match, the PRIV1LEGE command is successful and all privileged commands may then be used. If they do not match, the message INVALID P ASSWORD is printed and all privileged commands continue to be unavailable. 4-4 In short, a user must know the password in order to use any privileged command. It is important that the password be kept secret. For this reason, the password is never printed when the user types it. It is also possible to change the code at any time. The instruction to change the code, PASSWORD, is, of course, a priv- . ileged instruction. The other privileged commands, SAVE and UNSAVE, are discussed below. DECtape System Storage Capability . EduSystem 15 allows the system DECtape to be used for permanent on-line storage of programs. Programs stored in this way may be loaded instantly, without the need to load a paper tape or type in a program. . Two commands, SAVE and UNSAVE, may be used to change the contents of the DECtape storage area. Because the amount of storage space i~ .limited, and to prevent accidental erasure of stored programs, both SAVE and UNSAVE are privileged. commands. During normal system operation they are disabled. They may only be used after a successful PRIVILEGE command has been executed. The SAVE command stores the current program in the DECtape system storage area and gives it the name specified by the last NEW, OLD, or NAME command. Any existing program stored under this name is deleted. Thus, all stored programs have names which may be used to recall them in the f\lture. If a SAVE is at. tempted when the privileged commands are locked out, the system types WHAT? and ignores the command. If a successful PRIV1LEGE command has been executed, but the storage area is full, the message NO SPACE is typed and the program is not stored. , The UNSAVE command is used to delete a program already stored. UNSAVE must be preceded by a NEW, OLD, or NAME command which specifies the name of the file to be deleted. The user must be certain to use exactly the same program name as he used when he first identified the program. Like SAVE, UNSAVE will .be ignored unless preceded by ·a .successful PRIVILEGED command. If the program to be deleted does not exist in the system storage area, the message NO SUCH FILE will be printed. No program will be deleted. The CATALOG command may be used to obtain a list of the names of all programs available in the system storage area. The 4 .. 5 CATALOG list also inc1udes the number of storage blocks used by the program. EduSystem 15 includes 1348 blocks of storage space. The CATALoG command may be used to determine how many of these blocks have been used and hence how many are free. If the storage space is almost full and another program is to be saved, the LENGTH command may be used to determine if there is enough room to store the current program. If enough room is not available, an existing program must be deleted first. In all cases, the maximum number of stored programs, regardless of size, is 62. The user may load programs stored in the system storage area at any time by typing the OLD command. After the OLD command is entered, the system prints OLD PROGRAM NAME. The user then types the name of the program to be loaded. The user must be certain to use exactly the same program name as he used when he first identified the program. ADVANCI:D SYSTEM CAPABILITIES Some users will want to write programs which are too large or too complicated to be handled in the normal way. For these users, the system inc1udes several capabilities for advanced program. Running Very Long Programs EduSystem 15 will run programs of up to 6000 characters or approximately 250 lines. In some instances, programs which are at or near the 6000-character limit and which contain many complex FOR, IF, and GOSUB sections will be too big to be run. In this . case, the NOLINE command may be used to gain more space. If NOLINE is. used, the program logic errors which are detected while the program is executing will cause an error message to be typed but the line number where they occur will not be typed. NOLINE allows substantially longer program8' to be run. If the program to be run is substantially longer than the 6000character limit, it may still be run by means of the technique known as chaining. The program is broken down into pieces, each of which is less than 6000 charaCters. A chained program may have many of these pieces and, bence, may be indefinitely long. Each piece of the program is then stored in the DECtape system storage area with the SAVE command. The final command to be executed in all but the last section is a CHAIN statement which 4-6 contains the name of the next section of the program. For example, the statement: 950 CHAIN "PART10" would cause the system to load and execute the stored program whose name is PARTIO. The name of the next section of the program must be encoded in quotation marks and must be exactly six characters long. If the actual name of the next section is less than six characters, one or more spaces must be inserted before the second quotation mark to make a total of six characters. For example, if the next section of the program is named LINK2, the following CHAIN statement would be used: 955 CHAIN "LINK2 " Execution of the CHAIN statemc:nt loads and executes the named program. The previous section of the program is deleted. Thus, the user only needs to load the first section and run it. All. succeeding sections of the chained program are loaded and executed automatically. Using a Data File Just as some very advanced programs may be too large to be executed in the normal way, other sophisticated programs may need to store and use more data than may be accommodated under normal system operation. If this is the case, data may be temporarily stored in the system ·storage area. Data 'stored in this way is referred 10 as a data file. The data file is actually a part of the program data which is defined by a program's DATA statement. All of a program's data is gathered from the DATA statements into a DATA list which is read by READ statements. As items are read from the list, they are marked as already having been used. A READ statement always fetches the next item from the list. In fact, the data list may be thought of having a movable marker which remembers which item of the list is next. It s.tarts out marking the first" data item. As READ statements are executed, this marker ni.oves down the list. A RESTORE statement moves it back to the top of the list. 4-7 The data file capability allows a program, by means of a WRITE statement, to change and add to this data list as well as to read it. The WRITE statement format is the same as the DATA statement format. Writing a variable puts the value of that. variable in the next place in the data ·list. The data item that was there previously is replaced by the new value. If a WRITE statement follows a RESTORE. it will change the first item or items in the data list. If it follows one or more READs (or WRITEs), the WRITE statement will change data items further down in the data list. The total number of items which may be put in the data list depends on the size of the program. Maximum sized BASIC programs may have up to 1000 items; small programs have room for 2000 items. Programs which write data out to the data list must keep track of how much data has been written and the order in which it was output. If data which has been written is to be subsequently read, a RESTORE command must be executed to move the marker back to the top of the data list. If data has been written off the end of the data list, the program must remember how many items the data list contains, and be careful not to try to READ more data items than are there. The normal BASIC check for end of data does not exist for a written data list. The program must also be sure that it does not write more data than the data list can contain (l000-2000 items). Writing too much data c'auses part of the user's BASIC program to be destroyed. Th~ data file is frequently used in conjunction with chaining since data written onto the data list by one program section may be read by the next section. The program section which writes the data must execute a RESTORE just before the CHAIN statement. The next section, which will read thiS", must not have any DATA statement of its own since this data would destroy the data items written by the previous section. Character Variables and String Capability An of the standard BASIC statements deal o~ly with numbers. All variables are assumed to be decimal values. In fact, BASIC is capable' of doing many interesting operations on characters or words instead of numbers. The character handling capability of BASIC depends on the concept of representing individual characters as numbers. Each character has its own numeric code or character code, as indicated in Appendix B. When a character is 4-8 input, it is converted to a numeric code. All internal processing of that character uses this code. Since the code is a number, it may be used and manipulated with the standard BASIC statements. When the program outputs a character, it uses the character code and converts it back into a character. In short, characters stored in a BASIC program are indistinguishable from numeric values. The only difference is in the way they arc used, i.e., that certain numeric values actually stand for characters. The standard INPUT statement is used to input characters. A dollar sign ($) is placed in front of the variable name to indicate that a character code is to be input rather than a decimal number. When the character is typed, its character code is stored in the indicated variable. It is important not to confuse the inputting of characters with the inputting of numbers. The potential confusion lies in the fact that the numeric values are themselves characters. The value 192 is in fact made up of the three characters 1, 9 and 2. If these three characters were input to a BASIC program as character variables, they would be entered as three separate numeric (character code) values rather than as the single value 192. But the physical characters typed at the interactive terminal would be identical. Again, the difference is entirely in the way that the input is interpreted. Unlike the numeric' INPUT statement, character INPUT statements do not cause a question mark to be printed. Therefore, a series of characters may be typed without intervening question . marks. Programs doing character input must therefore indicate, by PRINT statements, when input is expected. In the following examples, each program executes an INPUT statem,ent. In the program on the left, three characters are entered and three variables are set up. In the example on the rig~t, a single numeric value is input. 10 PRINT "ENTER VALUE" ; 10 PRINT ,"ENTER VALUE "; 20 INPUT X 20 INPUT $X 1 ,$X2, $X3 30 PRINT Xl;X2;X3 30 PRINT X 40 END 40 END RUN NH RUN NH ENTER VALUE 234 50 51 52 READY ENTER VALUE?234 234 READY 4-9 Note that INPUT $A accepts the input character immediately without a carriage return. Note that the dollar sign is not a part of the variable name. It is used only in INPUT statements to indicate that typed characters are to be converted to their numeric character codes before being stored in the variable. Character codes may be converted back to their respective characters by means of the special PRINT command function CHR$. CHR$ is the opposite of the dollar sign INPUT convention. It is a function which takes as its argument a single constant or variable and prints the single character whose characte:r code corresponds to that value. For example, PRINT CHR$ (65.) prints the character A. CHR$ may only be used in PRINT st.atements. One of the most frequent uses of the character capability is to allow words .or characters to be entered into BASIC programs in response to questions. For example, a program might ask the user if he wants to run the program again with a different set of input data. The user responds by typing Y if he wants to run again or by typing N if not. The program then checks the character code of the character entered to see if it equals the character code for Y. If so, it branches back to the beginning of the program. Otherwise, the program stops. The following program illustrates the use of character variables in making a run-time decision. 10 PRI NT 20 PRINT "WOULD YOU LIKE TO DO THIS AGAIN IN THEN 90 60 PRI NT 10 PRINT "O.K. IT'S YOUR CHOICE." 80 STOP 90 PR INT 100 PRINT "y OR N7"; 110 GOTO 30 120 END RUN NH \~OULD YOU LIKE TO DO THIS AGAIN , <=, >=). Relational operators may only be used in IF statements'. S1 S2 Statement as a whole is not properly written and, as a result, does not conform to proper BASIC syntax. For example, a semicolon is allowed in a PRINT statement but not in a READ or INPUT statement. 4-14 Message Explanation ST Statement's command word is not one of the BASIC statement types. TB The program is too large to be run. Cause is usually an extremely large number of PRINT -statements. TO Program is either too large or too complex to be run. The total number of variables, constants, functions, and line numbers should be reduc~d, if possible. UL A OOSUB, OOTO, or IF statement contains a line number which does not exist. UQ A quotation mark indicating the beginning of a string of text does not have a corresponding quotation mark at the end of the text string. Program Logic Errors 4 Some errors do not show up until the program is actually executed. An example of this type of error is an expression which uses a square root of a variable. If, when this square root is actually calculated, the variable has a negative value, a program logic error has occurred. EduSystem 15 prints the following messages if _program logic errors occur. Message Explanation CH A CHAIN statement tried to chain to a program which was not available in the DECtape storage area. CO Program ran too long and was automatically stopped by the system. DA The program ran out of data. It attempted to do a READ after all data had been read. 4Some program logic errors may be corrected by the method described under Program Editing, Procedure 2. Most, however, necessitate the rewriting of the program. 4-15 Messag~ Explanation DO The program attempted to divide by zero. Instead of dividing by zero, BASIC divides by the smallest possible number, giving a result of about 10500 • This error does not cause the program to stop. FN An expression contains a function which was not defined in a DEF statement. GS The program is too complex to be executed. The problem is generally that too many subroutines have the!Dselves executed GOSUB instructions. LG Programl.ttempted to take the logarithm of a negative number zero. RE A RETURN statement was used outside of a subroutine or a subroutine was entered by at GOTO instead of a GOSUB. SP See GS. SQ Program attempted to take the square root of a negative number. BASIC automatically takes the square root of the absolute value of the number instead. This error does not cause the program to stop . SS Program used a subscript which was too large for the variable. The maximum size of a subscript is specified in a DIM statement. WR There is no more room on the DECtape to write data. The program attempted to do a WRITE statement when the data list was full. (Note that if this error occurs, the program text will no longer be intact. A NEW, OLD, or ~CR command must be used to clear the program area.) df OPERATING INSTRUCTIONS Loading the System When EduSystem 15 is first installed, it must be loaded with a special software program, the BASIC language processor. Once this 4-16 software has been loaded, it need not be reloaded. Perform the following steps to load BASIC. INITIALIZE THE DECTAPE UNIT Perform the following steps to prepare the TD8E DECtape unit for software loading. ' 1. Set the REMOTE/OFF/LOCAL switch to OFF. 2. Place a DECtape on the left spindle with the DECtape label out. 3. Wind four turns of tape onto the right spindle. 4. Set the REMOTE/OFF/LOCAL switch to LOCAL. S. Wind a few turns of tape onto the right spindle with the ~ switch to ensure that the tape is properly mounted. 6. Dial 0 on the unit selector dial. 7. Set the REMOTE/OFF/LOCAL switch to REMOTE. 8. Set the WRITE ENABLE/WRITE LOCK switch to WRITE ENABLE. INITIALIZE COMPUTER MEMORY To initialize the PDP-8/F memory, perform the following steps. 1. Turn the key lock on the front of the computer to POWER. 2. Perform the following set of switch manipulations on the SWITCH REGISTER (to the left of the ADDR LOAD switch). In each step, there are 12 figures which correspond to the 12 switches labeled SWITCH REGISTER (SR) on the front of the computer. The • symbol indicates that the corresponding switch should be set to its "up" position. The symbol means that the corresponding switch should be set to its "down" position. The octal instructions which corresp'ond to this diagram appear on the right. 5 50ctal instructions are provided for those familiar with the octal, or base 8, number system. An explanation of this system is included in Introduction to Programming 1972. 4-17 OCTAL 999 999 999 999 then pmss EXTD ADDR LOAD 0000 eM SetSRto: . . . "9 then pressADDR LOAD 7756 ~ 6032 Set SR to: "9 999 9" 9-9 then lift DEP 6031 Set SR to: "9 999 9" 99_ then lift DEP Set SR to: _9_ eM then lift DEP 5357 .~ Set SR to: _9 999 9 6036 _9 then lift DEP Set SR to: . . . 7106 ?9- 99S? "9 then lift DEP SetSRto: . . . YS?9 999 "Y then lift DEP 7006 SetSRto: . . . -Y- 99- 999 then lift DEP 7510 5357 . . . then lift DEP Set SRto: -9- 97006 SetSRto: . . . ):99 999 .. 9 then lift DEP SetSRto: "9 999 9M 99i then lift DEP 6031 Set SR to: _~,_ 9" -y. My iii 9" "Y Set SR to: _ (?_ Y9 9-- -99 Set SR to: . . . -9(;( 9-9 999 My Set SR to: 9" SetSRto: 9..... _ 9 Set SR to: S?- -9- -9 SetSRto: ...... y" -9- then lift DEP 5367 then lift DEP 6034 then lift DEP 7420 then lift DEP 3776 then lift DEP 3376 then lift DEP and again lift DEP 5356 3. Place the tape labeled EDUSYSTEM 15 in the Teletype paper tape reader. Position the tape at the single row of holes punched at the beginning of the tape. Turn the Teletype control knob to LINE. 4. Set the SR to . . . . . . '~~i' ADDRLOAD. .. ~ (7756); then press 5. Press the CLEAR switch, then thj~ CONT switch. Push the paper tape reader switch to START. The tape should begin to move: If it does not, repeat steps 2, 3, and 4. 4-18 System Building Dialog When the EDUSYSTEM 15 paper tape has read in pf(;)perly, BASIC prints a series of questions (see Figure 4-1). The user responds by typing Y for yes and N for no on the Teletype. STANDARD SYSTEM? Since EduSystem 15 has optional operating modes and may be used with optional components, if present, this question is always answered no (N). ' The next four questions: IS SYSTEM DEVICE A DF32 DISK? TC01 DECTAPE? RJ4"08 DISK? LINCTAPE? are always answered no (N) since none of these devices are available with the EduSystem 15. A response of yes (Y) to any of the above will result in the following message, and EduSystem 15 will begin the dialog again. SYSTEM DEVICE 1/0 ERROR The system's next question is: TOg E DECTAPE? and the user responds Y. 4-19 Figure 4-1. System Building Dialog 4-20 D )-------.../ BEGINS READING TAPE AND BUILDS SYSTEM READS IN ADDITIONAL INPUT WHEN TAPE IS READ, TYPES "READY" Figure 4-1. (Cont.) System Building Dialog 4-21 I EduSystcm 15 then asks: DO YOU HAVE A TD8 E 'HOM? Answer this Y if the EduSystem 15 has a TD8E Read Only Memory. If the user answers N, the system asks: CORE? 8 Y. OF' Since the system will have either the Read Only Memory or the 8K of core memory, answer this question Y. (The question will not be asked if the user answered Y to the previous question.) EduSystem 15 then asks: DO YOU WA~T BATCH CAPABILITIES? If the EduSystem 15 has an optional card reader, answer Y and refer to Chapter 7 (EduSystem 30) for additional instructions. If not processing card programs, answer N. N ext the system asks: DO you WANT PRIVILEGED COMMAND CAPABILITY? The privileged command capability prevents unauthorized users from executing critical system commands. To establish this protection, the user types Y. The system then prints: TYPE I~ITIAL PASSWORD The password is a special code which must be known to use privileged commands. Type a 1 to 6 character password, the first character of which is alphabetic. If no privileged capability is desired, respond to the original question with N; the system will not ask for a password. The system asks if a high-speed paper tape punch and/or line printer are part of the system. DO THE FOLLOWING EXIST: HIGH-SPEED PUNCH? LPfi18 PRINTER? 4-22 The response to each question must be Y if the device exists; N if it does not. Normally, an EduSystem 15 will have neither device. The system's next question is: PROGRAM LIBRARY INITIALLY EMPTY? The user's response should be Y unless there are programs previously stored within the system which are to be kept. If this is the case, N must be typed as the answer and the questions in boxes 1 through 8 of the flowchart must be answered in the same way as when the system was bui~t when the program library was empty., When all questions have been answered, the system types: IS THE ABOVE CORRECT? If all questions have been answered properly, type Y. The system will load the rest of the EduSystem 15 paper tape. If any of the responses were erroneous, type N; the set of questions is repeated. When the entire tape has been read, EduSystem 15 gives the user a chance to load additional DEC-supplied system update tapes by asking: MORE INPUT? If no DEC-supplied update tapes exist, respond Nand EduSystem 15 is loaded. If update tapes do exist, load the first one into the tape reader and type Y to hegin loading. Finally, when all input has been read in, EduSystem 15 indicates that it is ready to process BASIC programs by printing: READY At this time, turn the key lock to PANEL LOCK and remove the key to prevent the system from being accidentally disturbed. DIAGNOSTIC MESSAGES DURING SYSTEM BUILDING The following error messages are printed when errors are detected during the building of EduSystem 15. TAPE READY? 4-23 This message is typed whenever the system is waiting for the paper tape reader to be loaded. It may appear by itself, usually due to a tape tear or reader jam, or it may appear as the last line of another diagnostic message. ACTION: 1. The portion of the paper tape which is read after the system building dialog has distinct blocks of information about two and one-half tape fanfolds long. The start of such a block is indicated by nine blank tape frames followed by a frame with all positions punched. . Back up the tape several fanfolds to the beginning of a previously read block. Position the tape such that the blanks at the beginning of the block are over the read station. 2. Type Yon the interactive terminal. BAD PLACE TO START TAPE TAPE READY? This message means that after a previous message the user did not correctly position the tape to the beginning of a data block. (See discussion under TAPE READY? message.) ACTION: 1. Correctly position the tape. 2. Type Y on the interactive terminal. CHECKSUM ERROR TAPE READY? A checksum error occurred while the most recent data block was being read. ACTION: 1. Back up the tape to the beginning of the block. 2. Type Y to reread the data. SYSTEM DEVICE I/O ERROR 4-24 If this message occurs before the dialog has been completed, the dialog will automatically begin again. If an I/O error occurs after the dialog is completed the TAPE READY message will appear. ACTION: 1. Make sure that the system device is on line and writeenabled and the unit number is set correctly. 2. Respond appropriately to the question which follows the message. Turning Off the System The system may be powered down when it will not be used for extended periods of time, such as overnight. The procedure is as follows: 1. Type CTRL/C to stop any program that is running. 2. Turn the key lock to OFF; turn the DECtape unit and Teletype to OFF. Restarting the System The system may be restarted at any time without reloading by the following procedure: 1. Initialize the DECtape unit. 2. Turn the key lock to POWER and the Teletype to LINE. 3. Set the SR to ••• •• C? 999 9~9 (7600); then press ADDRLOAD. 4. Press CLEAR switch, then the CONT switch. 5. EduSystem 15 is now ready for use. Turn the key lock to PANEL LOCK and remove the key to prevent the system from being accidentally disturbed. Saving Programs on Paper Tape Once a program has been typed in correctly, it may be saved on paper tape so that it may be reloaded quickly. To save the program, perform the following steps: 1. Turn the Teletype (TTY) control knob to LINE. 2. Type LISTNH but do not press the RETURN key. 3. Turn the TTY paper tape punch ON. 4. Press SHIFT /CTRL, type "PPPPPP" to produce some , leader tape. 5. Press the RETURN key. 4-25 6. When punching is complete, press SHIFT /CTRL, type "PPPPPP" to produce some trailer tape. 7. Turn the TTY punch OFF. Reloading Programs from Paper Tape Programs punched out on paper tape may be reloaded using the Teletype (TTY) paper tape reader. The TAPE command is used to load programs from paper tape. To reload programs, perform the following steps: 1. Insert the paper tape in the TTY reader. 2. Turn the TTY control knob to LINE. 3. Type NEW, then press the RETURN key. 4. Type the program name. S. Type TAPE, press the RETURN key. 6. Tum the TTY paper tape reader to ST ART. 7. When the tape has read in, turn the TTY reader to FREE. A special control command, ECHO, may be used with TAPE to , prevent the program from being listed while it is being read. The first time it is used, ECHO inhibits all printout. A second ECHO command restores normal printout. Table 4-1. Statement LET PRINT .READ DATA RESTORE WRITE GOTO IF GOTO} IF THEN FOR TO STEP NEXT DIM GOSUB RETURN INPUT REMARK (REM) RANDOMIZE DEF EduSystem 15 BASIC Statement Summary Description Assign a value to a variable. LET is optional. Print out the indicated information. Assign values from data list to variables . Provide data for a program. Restore the data list. Record data on DECtape storage file .. Change order of program Fxecution. Conditionally change order of program execution. Set up a program loop. End a program loop. Define subscripted variables. Go to a subroutine. Return from a subroutine. Get values from the Teletype. Insert a program comment. Cause RND function to randomly select new sequence of random numbers between 0 and 1. Define a function. 4-26 Table 4-1. (Cont.) EduSystem 15 BASIC Statement Summary Statement De~cription CHAIN Link to next_section of .a program which is stored within the system. Do not print out the line number in which program logic errors are found. (Allow larger-thannormal programs to be run without chaining.) Stop program execution. End a program. NOLINE STOP END Editing and Control Commands LIST List all stored program statements. LIST n List program starting at line n. LISTNH List all program statements but do not print a header line. LISTNHn List program starting at line n but do not print a header line. RUN Execute the current program. RUN NH Same as RUN without header line. SCRATCH(SCR) Delete the currently stored (in memory) program. CTRL/C Stop execution of a program or printing of a listing. CTRLI C is typed by pressing C while holding. down the CTRL key. TAPE Read a program from paper tape. Ignore any line which does not begin with a line number. ECHO Switch from 'printout to non-printout mode or vice versa. RESEQUENCE Renumber program lines. NEW Clear memory, request program name. Clear memory, bring program to memory from OLD storage area. NAME Same as NEW but does not clear memory. CATALOG Print out the names of programs in storage area. (or CAT) LENGTH Print out the number of blocks needed to store the current program. PRIVILEGE Enable use of privileged commands. To be suc(or PRI) cessful, this command must be followed by the correct password. This command is recognized only if the privileged command capability was selected at system load time. 4-27 · Table Statement 4.~. (Cont.) EduSystem 15 BASIC Statement Summary Description Privileged CQmmands 6 PASSWORD Change the password code. SAVE Save the current program in the system storage area. UNSAVE Delete the named program from the system storage area. Functions ABS(X) ATN(X) COS (X) EXP(X) INT(X) LOG (X) RND(X) SGN(X) SIN(X) SQR(X) TAN (X) TAB (X) CHR$(X) Absolute value of x. Arctangent of x (result in radians). Cosine of x (x in radians). eX (e=2.718282). Greatest integer of x. N aturallogarithm of x. Random number. Sign of x (+ 1 if positive, -1 if negative, 0 if zero). Sine of x (x in radians). Square root of x. Tangent of x (x in radians). Controls printing head position on Teletype. Converts character code to character. Used only with the PRINT command. 6The privileged commands may only be used after a successful PRIVILEGE command has been executed. 4-28 5 edusystem 20 INTRODUCTION EduSystem 20. is a multi-user BASIC system. The system is composed of from one to eight terminals connected on-line to a PDP-8/E computer. This means that, depending on the number of on-line terminalS, EduSystem 20 allows up to eight different BASIC programs to be run at the same time. EduSystem 20 terminals need not be in the same room, or even in the same building as the computer. They may be placed in remote locations and connected to the computer by regular telephone lines. In addition to letting several persons use BASIC aCthe same time, EduSystem 20 allows users to operate BASIC in two different modes: immediate and programmable. Immediate mode allows the user to perform arithmetic calculations without writing programs. Programmable mode enables programs to be written in BASIC, stored in computer memory, and, if desired, saved on paper tape. Both modes provide a printed copy of the problem and the solution. EduSystem 20 BASIC also includes advanced features that enable a user to perform more complex programming tasks. These features include the ability to enter a subroutine if certain conditions are met, to write multiple statements per line, and to use a search character to edit a program line. System Components EduSystem 20 is composed of a PDP-8/E computer with 8192 words of core memory, power fail protection, auto~atic loader (hardware bootstrap), and up to 4 terminals and their associated interfacing. Each EduSystem 20 includes the BASIC language processor and a library of sample programs, textbooks, and curriculum guides. An additional 4096 words of core memory enable EduSystem 20 to handle up to 4 more terminals (for a total C?f 8). One or more off-line terminals may also be added for paper tape 5-1 preparation. The system can also support a high-speed paper tape reader/punch. System Expansion EduSystem 20 may be easily expanded to intermediate-sized EduSystems 25 or 40, or to the total school computer system, EduSystem 50. To expand to EduSystem 25, add 4096 words of core memory, DECtape, and an EduSystem 25 software kit. Expansion to EduSystem 40 requires a DECdisk or DECtape, an optional mark card reader, and an EduSystem 30 softwan~ kit. (Chapters 6 and 8 fully describe the capabilities of EduSystem 25 and EduSystem 40, respectfully.) EDUSYSTEM 20 BASIC EduSystein 20 BASIC has all the standard elements of .Dartmouth BASIC plus several extended features. Tables 5-1 and 5-2 summarize the system's BASIC language capabilities. The extended features are discussed below. Abbreviated Commands All commands and statement keywords can be abbreviated to the first three letters, as shown in Table 5-1. i Table 5-1. EduSystem 20 BASIC Statement Summary . Command (Abbreviation) LET READ(REA) DATA(DAT) PRINT(PRI) REStORE(RES) GOTO(GOT) IF THEN (IF THE) FOR TO STEP. (FOR TO STE) N EXT(N EX) GOSUB(GOS) , RETURN(RET) ON GOTO(ON GOT) Explanation Assign a value to a variable. LET is optional. Assign values from data list to variables. Provide data for a program. Print out the indicated information on the Teletype. Restore the data list. Change order of program execution. Conditionally perform specified operation or conditionally change order of program execution. Set up a program loop. End of program loop. Go to a subroutine. Return from a subroutine. Conditionally change order of program execution according to evaluation of formula con4tained in statement. 5-2 Table 5-1 (Cont.). Command (Abbreviation) EduSystem 20 BASIC Statement Summary Explanation ON GOSUB (ON GOS) INPUT(INP) REMARK(REM or ') RANDOMIZE (RAN or RANDOM) DEFFN STOP (STO) END Conditionally go to a subroutine according to . evaluation of formula contained in statement. Get values or expressions from the Teletype. Insert a program comment. Cause RND function to randomly select new sequence of random numbers between 0 and 1. Define a function. Stop program execution. End a program. Editing/ Control Commands LIST(LIS) List entire program in memory. LIST n(LIS n ) L i s t line n.LIST n, ni(LIS n, m) List lines n through m inclusive. DELETE n(DEL n) Delete line n. DELETE n, m Delete lines n through m inclusive. (DELn, m) EDIT n(EDI n) Search line n for the character typed. KEY Return to KEY (normal) mode. RUN Execute the current program. SCRATCH(SCR) Erase the current program from memory. TAPE(TAP) Read a program from the Teletype paper tape reader or punch a program on the Teletype paper tape punch. PTR Read a program from the high-speed paper tape reader. PTP Punch a program out on the high-speed paper tape punch. Stop a running program, print STOP, and CTRL/C then READY. CTRL/C is typed by pressing C while holding down the CTRL key. BYE Same as SCRATCH. Same as SCRATCH. NEW Table 5-2. EduSystem 20 BASIC Function Summary Function Description ABS(X) ATN(X) COS(X) EXP(X) INT(X) Absolute value of x Arctangent of x (result in radians) Cosine of x (x in radians) eX (e=2.712818) Greatest integer of x 5-3 Table 5-2 (Cont.). EduSystem 20 BASIC Fundion Summary Function Description LOG (X) RND(X) SGN(X) SIN (X) SQR(X) TAN (X) TAB (X) TAB (X) CHR$(X) Natural logarithm of x Random number Sign of x (+ 1 if positive,-l if negative, 0 if zero) Sine of x (x in radians) Square root of x Tangent of x (x in radians) Controls printing head position on Teletype. Truncates decimal portion of x. Converts character code to character. Used only with PRINT statement. Multiple Statements per Line EduSystem 20 allows more than one statement to be typed on a single line. Statements after the first begin with a back slash character ("-.) whibh is SHIFT /L on the keyboard. A program is often more understa:ndable when statements, such as a series of LET's, are grouped into a single line. For example, the program: 10 X=82\Y=75\Z=98 20 PRINT (X+Y+Z)/3 is the same as 10 LET X=82' 20 LET Y=75 : 30 LET Z=98 , 40 PRINT (X+Y+Z)/3 and will produce the same result when the RUN command is typed:! RUN 85 READY Since Ed1JSystem 20's memory is being shared by several users, this multiple-statement capability is helpful when writing long programs. Statements require less storage in the computer when they are grouped as a single statement. ! Notice that EduSystem 20 BASIC does -not require the use of an END statement. 5-4 Immediate Mode EduSystem 20 allows· certain BASIC statements to be used in immediate mode, that is, to be issued and executed immediately without being included in a formal program. Statements commonly used with immediate mode are PRINT, LET, FOR, and NEXT. Immediate mode is a quick way to calculate expressions and equations. For example, the statement: PR I NT SQR (144) followed by the RETURN'key, causes the square root of 144 to be printed immediately, as follows: 12 READY BASIC then prints READY to indicate that another immediate mode statement or a program may be entered. Immediate mode statements are not stored in computer memory. Typing multiple statements per line is especially useful in the im- . mediate mode. A table of random numbers could, for example, be generated by typing the following single line and pressing RETURN: F'OR D= 1 TO 20\PRINT RND(0),\NEXT D .2431684 .04493979 .2373254 .9882844 .2988412 .4834217 .3046887 .2587987 .7295008 .4961024 .1923863 .03323189 .3125257 .5010026 .9121199 .8701425 .3095865 .04103271 .241212 .9218898 READY· Nearly all the BASIC statements and commands may be executed in immediate mode. This is an excellent way to introduce students to the BASIC language, as the statements and commands can be exercised and understood before the student begins programmmg: Immediate. mode statements can also be used with programs. For example, an immedJate GOTO statement may be used to start a program at a point other than the beginning. This is accom-:..., plis~ed by lo.,,:?ing the,jJE9,~ram into computer mem~ f'pr}~~Jl~l GOTO 50 After the RETURN key is pressed, the program execution will begin automatically at line number 50. In this case, the RUN command need not be typed. INPUT Statement The INPUT statement described in Chapter 1 allows a number, or numbers, to be entered from the TTY as values for variables. EduSystem 20 allows the user to respond to the INPUT query (?) with a value or mathematical expression. An expression may contain one or more arithmetic operations and may use any BASIC function. For example, the statement: . ~([(( c" 'I~) is i (\' r.i.Jn#" (Jl~J-D.I' VU1"V'\N oVW~ .~~dYv ~nlAfte 100 INPUT A . could be answered in any of the following Ja;~~ 748 710*{146+128)/3 75 5t2 +SQR<:') I¢ I'" iN pJ-( v' . iNP, (ex. S v - - .VALVe i 01~. A 'A's ~L ',x "y'S \JAf fAO(sVS); y co~u~ This capability enable one program to solve more than one problem. As explained in Chapter 1, the INPUT statement may have multiple inputs. These inputs may be either mathematical expressions or numeric va!ues. For example, the statement: 10 INPUT A,B,e could be answered as follows: 133,LOG(33),33t5 Comments Previously~ the use of the REMARK (or REM) command to introduce a comment on a single line was discussed. Comments may also be appended to any line by starting the comment with a single apostrophe ('). All characters typed afier the apostrophe on 5-6 a single line are ignored when the program is executed. For example: 10 LET X=4 'SET X TO ITS INITIAL VALUE 20 GOTO 10"LOOP BACK TO START When included' within a PRINT statement message, the apostrophe is not considered as the start of a comment. For example: 12 PRINT "X'S VALUE IS";X prints X'S VALUE IS 4 When responding to an INPUT statement, the user may add a comment which will print on the Teletype but have no effect on the running program. For example: 10 I NPUT A 20 PRINT A RUN " Subscripted Variables In chapter 1, the DIM statement is used to permit subscripts of more than 10. EduSystem 20 BASIC defines all variables as they occur, so the DIM statement is not neeessary~ The system imposes the following limits on subscript size: • Single subscripts: 0 to 2047 • Double subscripts: 0 to 63 for each subscript Consider the following .example. Notice that a variable has a value of 0 until it is assigned a value. 5-7 REM· MATRIX CHECK PROGRAM FOR 1=0 TO 6 LET A( I , 0 ): I FOR J:0 TO 10 LET A( 0, J ) : J PRINT A(I,J); 35 NEXT J 40 PRINT 45 NEXT I RUN 10 20 22 25 28 30 '" 1 2 1 2 3 0 0 '" '" 0 0 5 6 0 0 0 0 4 0 0 (~~~y t: (ffJ /vv.,- 3 ttJ , 4 5 6 7 8 9 10 0000000 0 o 0 0 0 0 0 0 0 00000 000 o 0 0 0 0 0 0 0 0000000 0 00000 0 0 0 ~ ~ tWv/uMrJ tikut ~I; 1- /L4>:: / ~- ~ lr;t~ T vb (s \ evllow&b) cry 0.. G~ X b] ~c..~ ~ ptQAfifJ'"\ ~ I4t JUvl., ulitllJ<.. IILtft b)I SireJ IF THEN Statement The IF THEN statement described in Chapter 1 is used to transfer conditionally from the normal order of program execution. For example: 50 l~ X>Y THEN 200 transfers control to ]ine 200 if X is greater than Y. If X is not greater than Y, control transfers to the line following line 50. EduSystem 20 BASIC uses the IF THEN statement in this way to change the order of program execution. It also allows the IF THEN statement to, conditionally perform an operation without changing the order of program execution. For example: 50 I~ X>Y THEN PRINT "X>Y" If X is greater than Y, BASIC prints X> Y. Whether or not X is greater than Y, the next statement executed is the one following line 50. IF THEN used in this manner does not change the order of program execution. 5-8 The IF THEN statement can also be used to transfer control to a subroutine. For example: 25 I If' A+B=C THEN. GOSUB 100 If A 100. +B equals C, control is transferred to the subroutine at line Truncation Function (FIX) EduSystem 20 BASIC includes all the functions discussed in Chapter 1 (see Table 5-2). In addition, it includes the truncation function (FIX) which returns the integer part of x. For example: PRI FIXC-842.756) -842 Notice that FIX is like INT for positive arguments. In fact, FIX could be defined as: f/J /} lIu FIX(X)==SGN(X)*INT (ABS(X» _ l .-+.:-:- _// ac~~. ~ dtfoitd~ <1~ f!ht UJai::~} ~:V·Lf~ fJr CHR$ Function !,..''-IT 4Ak'~fv.1;D VA ~ I X . JD Wlt tit. . Occasionally, it is desir-~l~ to type a character other than the printing ASCII set (see Appendix B) or to convert ASCII character codes t? their respective characters. A special PRINT statement function, CHR$, is used for this purpose: This function takes as its argument a single constant or variable and prints the single character whose character code corresponds to that value. For example: 10 FOR 1=0 TO 9 20 PRINT CHRS(I+48)J 30 NEXT I RUN 0123456789 READY /It ~S() "IN,) ur Clf'R.- 'Ii'(J l{)<, J' ~ MA l(\f?~ .. ~~ ~ -tiM w etvui tfO ~J ~~-rA1? . LA/' This program prints "0123456789" because 48 to 57 are the ASCII values for the characters 0 through 9. The following special characters can also be printed using the CHR$ function: rtD PR iAJ7 ('NUL L (/ 5-9fke GH1(~· C2-5 ~) ............ ' Bell Line feed Carriage return Quote (") Back arrow (~) Form feed CHR$(7) CHR$(10) CHR$(13) CHR$(34) CHR$(95) CHR$(12) For each ASCII character there is a second acceptable form of CHR$ function. The second code is obtained by adding 128 to the ASCII code given in Appendix B. For example, both CHR$(65) and CHR$(193) cause the character A to be output. ON·GOTO Statemenl The ON-OOTO statement permits the program to transfer control to one of a set of lines depending on the value of a formula. The statement is of the form: line number ON formula OOTO line number, line number . .. The formula is evaluated and then truncated to an integer. This integer is used as an index to tell which of the line numbers receives control. If the integer is 1, the first line number is used; if it is 2, then the second is used; etc. Obviously, the formula after truncation cannot be zero or negative or greater than the number of line numbers in the list. For example: 10 ON A+2 GOTO 100,200,300,400 If A is 2, then control is passed to line 400. The range A can have in this example is -1 to 2. ON GOSUB Statement The OOSUB and RETURN statements are used to allow the user to transfer control to a subroutine and return from that subroutine to the normal course of program execution (see Chapter 1). The ON GOSUB statement is used in the same manner as the ON OOTO statement described previously. The statement is of the form: ' line number ON formula OOSUB line number, line number . .. 5-10 ' The formula is evaluated and then truncated to an integer. Depending on the value of the integer, control is transferred to the subroutine which begins at one of the line numbers listed. When the RETURN statement is encountered, control transfers to the line following the ON GOSUB line. For example: 50 ON X GOSUB 200,300,400 If X is 1, 2, or 3) control will transfer to line 200, 300, or 400 re:;pectively. If X is not equal to 1, 2, or 3, line 50 is ignored .9 7 fLAA i ? 1 HAVE A HIGH SPEED PUNCH {Y OR N)?Y HAVE A HIGH SPEED READeR (Y OR 1'J)7Y' ABOVE CORRECT (Y OR N)?Y If the number of users is more than 1, BASIC continues the dialog by asking: PDP-8/L COMPUTER ? When all responses have been entered, BASIC asks: IS THE ABOVE CORRECT V\A)"\L \ i~~ \ v{ ",-v..{\-t~l _~A QGAt ~~' ,J ',J As explained in Chapter 1, the INPUT statement may have multiple inputs. These inputs may be either mathematical expressions or numeric values. For example, the statement: 10 INPUT AlBIC could be answered as follows: 148148'SISQR(48) Comments Previously, the use of the REMARK (or REM) statement to introduce a comment on a single line was discussed. Comments may also be appended to any line by starting the comment with a single apostrophe ('). All characters typed after the apostrophe are ignored when the program is executed. For example: 10 LET X=4 'SET X TO ITS INITIAL VALUE 20 GOTO 1~ 'LOOP BACK TO START 6-4 When responding to an INPUT statement, the user may add a comment which prints on the terminal but has no effect on the running program. For example: UJ INPUT X 20 PRINT X RUN . ? 2 'LET X BE 2 2 READY .'~ . IF THEN Statement The IF THEN statem~nt described in Chapter 1 is used to transfer conditionally from the normal ?rder of program execution. For example: 25 IF A<-B THEN 100 transfers control to line 100 if A is less than or equal to B. If A is greater than B, control transfers to the line following line 25 .. BASIC-E uses the IF THEN statement in this way to change the order of program execution. It also allows THEN to be followed by an executable BASIC statement. This statement is executed onl if the IF relation is true; otherwise control passes to the next separate statement. or example: 50 IF 2+2=4 THEN LET A=7'PRINT A Since the statement (2+2=4) is true, BASIC prints 7. The next . statement executed is the one following line 50. IF THEN used in this manner does not change the order of program execution. The IF THEN statement can also be used to transfer control to a subroutine. For example: 25 IFA+B=C THEN GOSUB 100 If A+B equals C, control is transferred to the subroutine at line 100. Otherwise, the next statement executed is the one following line 25. ' 6-5 ON-GOTO Statement The ON-GOTO statement permits the program to transfer control to one of a set of lines depending on the value of a formula. The statement is of the form: line number ON formula GOTO line number,line number . .. The formula is evaluated and then truncated to an integer. This integer is used as an index to tell which of the line numbers receives control. If the integer value of the formula, is 1, the first line number is used; if the value is 2, then the second is used; etc. Obviously, the formula after truncation cannot be zero or negative or greater than the number of line numbers in the list. For example: If X is 2, then control passes to line 400. The allowable range of X in this example is -1 to 2, so that the range of the formula value is 1 to 4. ON GOSUB Statement The GOSUB and RETURN statements are used to allow the user to transfer control to a subroutine and return from that subroutine to the normal course of program execution (see Chapter 1). The ON GOSUB statement is used in' the same manner as the ON GOTO statement described previously. TlJ.e stateme~!_ i~of", the form: - line number ON formula GOSUB line number, line number . .. The formula is evaluated and then truncated to an integer. Depending on the value of the integer, control is transferred to the subroutine which begins at one of the line numbers listed. When the RETURN statement is encountered, control transfers to the line following the"ON GOSUB statement. For example: If X is 1, 2, or 3, control transfers to line 200, 300, or 400, respectively. If X is not equal to 1,2, or 3, line 50 is ignored. 6-6 RANDOMIZE Statement The random number (RND) function produces a random number between 0 and 1, as described in Chapter 1. A given program using the RND function produces the same random numbers each time it is run. If the user wants the random number generator to calculate different random numbers every time the program is run, EduSystem 25 BASIC provides the RANDOMIZE statement. RANDOMIZE is normally· placed at the beginning of a program which uses the RND fmiction. When the program is executed, RANDOMIZE causes the RND function to choose a random starting value so that the same program gives different results each time it is run. For example: 10 RANDOMIZE 20 PRINT RND(0) prints a different number each time it is run. For this reason, it is good practice to debug (detect, locate, and correct mistakes) a program completely before inserting the RANDOMIZE sta~ement. To demonstrate the effect of the RANDOMIZE statement on two runs of the same program, the RANDOMIZE statement was inserted as line 15 below: 15 RANDOM 20 FOR 1=1 TO 5 25 PRINT "VALUE" I "IS" RND(0 ) 30 NEXT I RUN VALUE 1 IS .3808637 VALUE 2 IS .7119271 VALUE 3 IS .9687586 VALUE 4 IS .03029916 VALUE 5 IS .4629068 READY RUN VALUE VALUE VALUE VALUE VALUE I 2 3 4 5 IS IS IS IS IS .8916059 .2441537 .3154383 .07033823 .583024 READY 6-7 Truncation Function (FIX) EduSystem 25 BASIC includes all the functions discussed in Chapter I (sce Table 6-2). In addition, EduSystem 25 includes the truncation function (FIX) which returns the integer part of the function argument. For example: PRI FIX(82+100.677S, 182 PRJ FIX(SQR(85.54621» 9 Notice that FIX is like INT for positive arguments. In fact, FIX could be defined as: FIX(X)=SGN(X) *INT(ABS(X)) EXTENDED SYSTEM CAPABILITIES In addition to the BASIC language features previously discussed, EduSystem 25 has several extended features that allow the user to write longer, more complex programs. These features include the ability to store programs on DECtape, create and manipulate data files on DECtape, and link program segments together to al10w longer user programs. Another extended capability allows character strings to be input, manipulated, compared, and output. These extended features are discussed below. String Variables EduSystem 25 BASIC has the ability to manipulate alphanumeric information (commonly called strings). A string is a sequence of six or fewer printing ASCII characters (see Appendix B). If a string contains more than six characters, only the first six are retained. A string variable is signified by one letter followed by the dol1ar sign ($) character and, optionally, by one or two subscripts. The following are all acceptable string variables: A$ B$(l) C$(2,5) READING STRING DATA Strings of characters may be read into string variables from DATA statements. Each string data element is composed of one to six characters enclosed in quotation marks. The quotation marks are not part of the actual strings. For example: "'~.~~. ~ p~ \JZ.o.t ~ \o.P~ ~ '~Lt 6-~ E:~t- d. OJ'..fA, f; ~ , }..fA }/'f. s-tr.) i U Rtp,.{)kf 10 READ AS,SS,CS 20 DATA "JONES","SMITH","TAYLOR" The string JONES is read into A$, SMITH into B$, and TAYLOR into C$. If the string contains more than six characters, excess characters are ignored. PRINTING STRINGS The normal PRINT statement may be used to print string information. If a semicolon is used to separate string variables in a PRINT command, the strings are printed with no intervening spaces. For example, the program: 10 READ AS,SS,CS 20 PRINT CSJSS'AS 30 DATA ttlNG" ,·"SHAR", ttT IME-" .-/ RUN . '~Z:""" '- causes the following to print : I 10 READ AS,BS,CS 20 PRINT CSJBSAS DELETED // h- 10 READ AS, Bslcs 20 PRINT CSJBSICS DELETED --~ READY INPUTTING STRINGS String information may be .entered into a BASIC program by means of the INPUT command. Strings typed at the keyboard may contain any of the standard BASIC characters except back arrow (~) and quotation mark. Back arrow, as always, is used to delete the last character typed. Commas ar~ used to separate string variables, as with numeric data. If a string contains a. comma, the entire string must be enclosed in quotation marks. The following . program demonstrates string input: 10 INPUT AS,BS,CS 20 PRINT AS,BS,CS RUN 1 JONES,SMITH,TAYLOR JONES SMITH TAYLOR READY 6-9 Strings and numeric information may be combined in the same INPUT statement as in the following example. Note that if an input string contains more than six characters, only the first six are retained. 10 INPUT AIASIB$ 20 PRINT ASIBS1A RUN ? 01754IMAYNARDIMASS. MAYNAR MASS. 1754 READY co,) I lie: , The numeric variable A is set to 1754 (leading zeroes are not printed). The string MAYNAR is put in the string variable A$, and the string MASS. is put into the string variable B$. LINE INPUT Strings of more than six characters may be entered by means of the LINPUT (line input) statement. A LINPUT statement is followed by one non-subscripted variable, e.g., A$. The following program illustrates the use of the LINPUT statement: 10 LINPUT AS 20 Z=-AS(0) 30 FOR I-I TO INTCZ/6+.9) 40 PRINT ASCI); 50 NEXT 1 60 PRINT RUN ? MAYNARDI MASS. 01754 MAYNARDI MASS. 01754 READY This program inputs the entire line of type from the terminal and stores the characters so that the values of the string variables are, effectively: A$(1) = MAYNAR A$(2) D, MAS = A$(3)=S. 01 A$(4) = 754 A$ (0) = total number of characters stored Commas and quotation marks are treated as ordinary characters and, hence, are stored in the string variables. LINPUT accepts a line of characters up to a carriage return. 6-10 WORKING WITH STRINGS Strings may be used in both LET and IF THEN statements. For example: 10 LET YS="YES" 20 IF B$ , >=, <=, <> are used with string variables to represent alphabetic order; they could be used to alphabetize a list of strings .. The arithmetic operations (+, -, *, /, t) are not defined for strings. Thus, statements such as LET A$ = 3 *5 and LET C$ = A$+ B$ have no meaning and should never be used in a BASIC program. Such statements do not cause an error message to be printed; however, the results of such operations are undefined. ' STRING FUNCTIONS EduSystem 25 'BASIC contains several functions for use with character strings. These functions allow the program to access part of a string (MID), generate a numeric string or value (CRR$), determine the number of characters in a string (LEN), and link two strings together ( CAT) . ) CHR$ Function Occasionally, it is desirable' to type a character other than the printing ASCII set (see Appendix B) or to convert ASCII character 'codes to their respective characters. A special PRINT statement function, CRR$, is used for this purpose. This function takes as its argument a single constant or variable and prints the single character whose character code corresponds to that value. 6-11 1" FOR 1=" TO 9 2" PRINT CHRS(I+46); 30 NEXT I RUN 0123456769 READY This program, prints "0123456789" because 48 to 57 are the ASCII values for the characters 0 through 9. The following special characters can also be printed using the CHR$ function: CHR$(7) CHR$(10) CHR$(13) CHR$(34) CHR$(95) CHR$(12) Bell Line feed Carriage return Quote (") Back arrow (~) Form feed For each ASCII character there is a second acceptable form of CHR$ function. The second code is obtained by adding 128 to the ASCII code given in Appendix B. For example, both CHR$« 65) and CHR$ (193) cause the character A to be output. MID Function The MID function is used to obtain a portion of a character string. The format of this function is: MID(A$,M,N) BASIC accesses the characters in the string variable A$ and returns N characters, beginning with position M. Characters in a string are numbered 1 through 6. Consider the following example: 10 LET AS·"UVWXYZ" 20 PRINT MID(AS,3,3) RUN WXY READY 6-12 LEN Function The LEN function returns the number of characters in the string argument. Characters in a string are numbered 0 thro'ugh 6. For example: 10 RS.tfRANDOM" 20 PRINT LEN(RS) RUN 6 READY CAT Function The CAT function returns a string of characters which are the result of the concatenation (1i~king) of two other character strings. A maximum of six characters can be returned by the CAT function; if the first string to be linked contains six characters, only those six characters are returned. For example: 10 AS."01234S"\BS="678910" 20 PRINT CAT(ASIBS) RUN 01234S READY. "- If the first string contains less than six characters, they are linked as shown in the following program. 10 A$="EDU"\B$="-2S" 20 PRINT CAT(A$IBS) \ RUN EDU-2S READY Program. Storage / Retrieval EduSystem 25 allows the system DECtape to be used for permanent on-line program storage. Programs stored in this way may be loaded instantly without handling a paper tape or typing a lengthy program. STORING USER PROGRAMS User written programs may be stored on DECtape. Each program to be saved must have an assigned name, entered at the beginning of the programming session. The NEW command is given to clear any existing program and define the name of the new program to be entered. To use the NEW command, the user types: 6-13 NEW and presses RETURN. The system then asks for: NAME-- The user then types any name of 1 to 6 characters (the first ·of which must be alphabetic) and presses RETURN. BASIC assigns that name to the program to be entered. The user may change the name of the program at any time by typing the RENAME command. BASIC again asks for NAME- and assigns the new name to the program being entered. RENAME does not delete the existing program as does NEW. Once a program has been named and typed correctly, it may be stored on DECtape with the SAVE command. Any existing program stored under the same name is deleted when a SAVE command is issued. Thus all stored programs have unique names which may be used to recall them in the future. To store a program, the user, having named and entered a program, types: SAVE and presses RETURN. BASIC stores the program on DECtape under the name specified with an extension identifying the user terminal from which the program was saved. For example, a program named ALPHA that is saved from ter'minal .E2 (see Starting EduSystem 25) is stored as ALPHA .E2. Extensions protect the programs from access by other terminals, i.e., terminal .E1 cannot access a program stored by terminal .E2. When the program has been stored, BASIC prints READY. At this time, the program still resides in computer memory; storing· does not erase computer memory. A NEW or SCR command must be typed to erase the program from memory after it has been stored on DECtape. RETRIEVING USER PROGRAMS User programs stored on DECtape are brought into memory with the OLD command. Only programs stored from the same user terminal can be retrieved at that terminal. When recalling a program with the OLD command, the user must give exactly the 6-14 same name as was used 'when the program was stored. To use the OLD command, the user types: OLD and presses the RETURN key. The system then asks for NAME-. The user can also use the OLD command and the program name (e.g., ALPHA) on the same line as follows: OLD ALPHA BASIC brings the stored program into memory but does not erase the program from DECtape. If the user wishes to modify the program, he can make the necessary modifications, then issue another SAVE command. This procedure replaces the original stored program on DEC tape with the modified version of the same name. The user can obtain a listing of all programs stored from his terminal by using the CATALOG command. CATALOG, like all other program storage/retrieval commands, is an immediate command. It is used by typing CATALOG and pressing RETURN. BASIC immediately prints a listing, without extensions, of all programs stored by the terminal from which the CATALOG command was issued. RUNNING VERY LONG PROGRAMS EduSystem 25 accommodates BASIC programs up to 250 lines long. If a program is any longer, it may be necessary to break it into several segments. A program that has been broken into more than one piece is called a chained program. Each part of a chained program is saved on DECtape as a separate program, complete with name and system-assigned extension. The last statement of each part to be executed is- a CHAIN statement specifying the name of the next 'section of the program. For example, a program named ALPHA is segmented into three parts: ALPHA, BETA, and GAMMA. ALPHA is loaded with the OLD command. 250 CHAIN "BETA" 6-15 The last statement in ALPHA is a CHAIN statement. or 250 CHAIN as The string variable (B$) may be used if the segment name was previously assigned to it, for example: 248 BS="BETA" When this CHAIN statement is reached, the BET A segment of the program is loaded and executed. The BET A segment then chains to the next (GAMMA) segment of the program with a statement such as: 399 CHAIN "GAMMA" Each separate part of the program links automatically to the next part of the program. The CHAIN command may also be used to branch to a stored program -from a working program. For example: 10 INPUT "WHAT LESSON DO YOU WANT" A$ 20 CHAIN A$ RUN WHAT LESSON DO YOU WANT? DELTA would cause BASIC to retrieve, load, and execute the program named DELTA. DELETING STORED PROGRAMS The UNSAVE command is used to delete a program already stored. UNSAVE must either be preceded by a NEW, OLD, or RENAME command which specifies the name of the program to be deleted or the command must be typed as: UNSAVE ALPHA specifying the name (e.g., ALPHA) of the program, on DECtape, to be deleted. The user must use exactly the same name used when 6-16 the program was stored. Only programs which were saved from the terminal being used may' be deleted by a user at that terminal, e.g., a user at terminal .Bl may delete only those programs stored with an extension of .El. (These are programs listed in response to the CATALOG command.) USING PUBLIC LIBRARY PROGRAMS Programs stored by' the System Manager with the extension .EB may be accessed by all users. These programs are collectively called the public library. To obtain a listing of the available public library programs, the user types: CATS and presses the RETURN key. A listing of the public library programs is printed. A sample listing is shown below: ROCKET LUNAR POLUTE ELECT SNOOPY GAMBLE READY The user can access any program in the public library by typing OLD$ and the desired program name. For example, the user types: OLOS SNOOPY The library program SNOOPY is loaded into memory and the system prints READY. The user can then execute SNOOPY by typing RUN or, if desired, can obtain a listing of SNOOPY by typing LIST. User may access the public library but cannot SAVE or UNSAVE the library programs. These programs are protected by the .EB extension. The user can also access public library programs by chaining to them from a program. For example, the _user can access the public 6-17 Iibraryprogram ELECT by including the following statement in his program: 55 CHAINS f9ELECT" , or by including the following statements: 50 ES."ELECT" 55 CHAINS ES Data File Storage1Retrievai Just as some programs may be too large to be executed as a single p.rogram, other programs may need to store and use more data than may be contained in DATA statements within the program. If this is the case, data may be stored on DECtape. Data stored in this way is called a data file. EduSystem 25 allows users to read and write OECtape data files. These data files may contain numeric or string data. Data files are the perfect way to test student programs. The instructor may create a data file which all student programs must use and then answers may be stored in another file which may be checked automatically. Data files are stored automatically by EduSystem 25 on the DEC tape mounted on DECtape drive 1. Data files are stored with an extension similar in principle to that previously discussed for programs. Terminal .El data files have the extension .Dl, .E2 data files use .D2, etc. The system manager's extension (.ES) uses .DS data files. Normally, .DS files can only be read; users are limited to reading only by placing DECtape drive 1 on WRITE LOCK. CREATING DATA FILES When the user desires to store data on DECtape, he must create a data file, or use an existing data file. Data files are created with the OPEN FOR OUTPUT command. For example, the user wishes to create a data file named DATAI0 (date file names, like program file names, can be 1 to 6 characters long, the first character of which must be alphabetic). The data file name can be used in the OPEN statement or a string variable can represent it. A data 6-1S file would be created when the following statement was executed In a program: 10 OPEN "DATA10" FOR OUTPUTI12 The data file name must be enclosed in quotation marks. This statement could also be coded as: 10 OPEN AS FOR OUTPUTI12 if A$ has been set equal to DAT Al O. The 12 at the end of the statement indicates that 12 blocks are to be reserved for this file. Any number of blocks up to 64 may be reserved in this manner. If no blocks are res~fved in the OPEN FOR OUTPUT statement, the system assumes that the file is to be 10 blocks long. When the data file has been created, or reopened, the user may write data into the file with the PRINT # statement. This statement may contain either numeric or string data separated by commas or semicolons. For example, a single data item can be entered by typing the following: 20 PRINT II 248 This statement writes 248 and a carriage return/line feed onto a data file that has been opened for output. Several data items may be included in a PRINT # statement, with commas printed as separators between data items on each line of the output file. The commas must be enclosed in quotation marks to have them print on the output file. For example: writes each of the above items on the data file as separate data items as follows: 1, 2, 3, 4, 5 and a carriage return/line feed exactly as the items would be input from the terminal. 6-19 Character strings are used in the PRINT # statement in the same manner, for example: 25 A$="JONES"\8$="SMITH"\C$="TAYLOR" 30 PRINT#IA$IB$IC$ would write three separate character strings onto the DECtape as follows: JONES, SMITH, TAYLOR and a carriage return/line feed. Writing PRINT # statements with multiple operands (data jtems) saves space on the DECtape data file because fewer carriage return/line feeds need to be stored. When al1 data has been entered with PRINT # statements, the output file should be closed with the CLOSE statement. Since EduSystem 25 allows only one output file to be opened at a time, the CLOSE statement is used to close the output file. For example: 3~ CLOSE READING DATA FILES When the user wishes to usc data stored on DECtape data files, he opens a previously created file with the OPEN FOR INPUT statement. If, for example, the user wishes to read data stored in a file named DATAlO, he can reference this name in the OPEN statement or use a string variable t<;> represent. it. The data file would be opened when the following statement was executed in a program: 40 OPEN "DATf\l~" FOR INPUT The data file name must be enclosed in quotation marks. The above statement could also be coded as: 35 BS="DATA10" 40 OPEN BS FOR INPUT When the data file has been opened for input, the user may read data from the file with the INPUT # statement. The INPUT # statement searches the file for a carriage return/line feed character and inputs the next data item, or items. This statement may contain either alphabetic or string variables separated by commas or semicolons. For example, the statement: 6-20 searches for a carriage return/line feed character and inputs the next five separate data items· (separated by either a comma, a semicolon, or a carriage return/line feed ) from a data file. The following program uses the examples in this section to demonstrate data file usage: 10 X$="DATA10" 15 OPEN X$ FOR OUTPUT~12 -20 PRINT*~1~2~3~4~5 , 25 A$="JONES"'B$="SMITH"'C$="TAYLOR" 30 PRINT#~A$~H$IC$ 35 CLOSE 40 OPEN X$ FOR INPUT 50 55 INPUT#~A~H~C~D~E INPUT#~A$~B$~C$ PRINT 65 PRINT 70 PRINT 75 PRINT 60 A~H~C~D~E A$~B$~C$ RUN 1 2 3 JONES SMITH TAYLOR LISTING· DAT A FILES The user can obtain a listing of the data files for his terminal by typing the FILELOG command. This immediate mode command is typed as: FILELOG or FIL and produces a listing of the data file names without extensions. For example: FILELOG DATAl'" NUMBER CIRCLE TIMER READY 6-21 ERASING DATA FILES Data files can be deleted from DECtape with the KILL command. If, for example, the user wishes to erase a file named DATAIO, he types: KILL DATA lei when the RETURN key is pressed, BASIC deletes DATAIO from the data file and prints READY. The KILL command and the file name must be separated by a space. This command deletes only those data files entered from the same terminal, i.e., with the same extension. USING PUBLIC DATA FILES Data files stored by the System Manager with the extension .08 may be accessed by all users. To obtain a listing of the available public data files, the user types: FILELOGS FILS and presses the RETURN key. A listing of the public data files· is printed. A sample listing is shown below: FILS TESTell TESTI1J2 DATASI1J DATASS DATA611J The user can use the data in any public data file by opening the file for input. For example, to use the data in a public file named DATA55, the user types: 911J OPENS "DATASS" FOR INPUT Included in a program, the above statement would make the data in DATA55 available to the user program. The user can manipulate this data in his program but cannot change the data file in any way. Public data files are protected by the .08 extension. 6-22 Table 6-1. EduSystem 25 BASIC Statement Summary Command (Abbreviation) Explanation Input/Output Statements . LET Assign a value to a variable. The word LET is optional. READ(REA) 'j Assign values from data list to variables. .PRINT(PRI) Print out the indicated information on the Teletype. DATA(DAT) Provide data for a program. RESTORE(RES) Restore the data list. INPUT(INP) Get values or expressions from the Teletype. LINPUT(LIN) Get long character string from the Teletype. 'GOTO(GOT) Change order or program execution. 'IF THEN(IF THE) Conditionally perform speci,,: fied operation or conditionally change order of program execution. Set up a program loop . . FOR TO STEP(FOR TO STE) 'NEXT(NEX) End of program loop. GOSUB(GOS) Go to a subroutine. RETURN(RET) Return from a subroutine. , Conditionally change order of ON GOTO(ON GOT) program execution according to evaluation of formula contained in statement. ON GOSUB(ON GOS) Conditional1y go to a subroutine according to evaluation of formula contained in statement. Insert a program comment. 'REMARK(REM or ') Cause RND function to ranRANDOMIZE(RAN or RANDOM) domly select new sequence of random numbers between 0 and 1. Define a function. DEF FN Stop program execution. STOP (STO) End a program (not required END with EduSystem 25). Editing/Control Commands. LIST(LIS) LIST n(LIS n) List entire program in memory. List line n. 6-23 Table 6-1 (Cont.). EduSystem 2S BASIC Statement Summary Command (Abbreviation) Explanation '. LIST n,m(LIS n,m) List lines n through m inclusive. Delete line n. Delete lines n through m inclusive. Search line n for the character typed. Return to KEY (normal) mode. Execute the current program. Erase the current program from memory. Same as SCRATCH. Read a program from the Teletype paper tape reader or punch a program on the Teletype paper tape punch. Stop a running program, print STOP, and then READY. DELETE n(DEL n) DELETE n,m(DEL n,m) EDIT n(EDI n) KEY RUN 'SCRATCH(SCR) BYE TAPE(TAP) ,CTRL/C Program Storage/Retrieval Commands 'NEW Clear memory, request program name. 'RENAME(REN) Chan&e the name of the program currently in core memory. Store program in memory on 'SAVE DECtape, using the name specified by NEW, RENAME, or OLD and an extension determined by the user's terminal. Erase memory, retrieve, load CHAIN A$ and begin execution of the stored program named in A$. Used to segment a large program into workable sections~ Chain to public library proCHAIN$ A$ grams. Clear memory, request pro'OLD gram name, bring named program to memory from DECtape. Delete from DECtape the proVNSAVE gram named in most recent 6-24 Table 6-1 (Cont.). EduSystem 25 BASIC Statement Summary Command (Abbreviation) Explanation NEW, RENAME, or OLD command. List names of stored programs for this user (extensions are not printed). List public library programs. Request public library program name, bring named program to memory from DECtape. 'CATALOG(CAT) 'CAT$ 'OLD$ Data File Commands OPEN A$ FOR OUTPUT,X OPEN B$ FOR INPUT .-;() OPENS B$ FOR INPUT INPUT # :! PRINT # CLOSE FILELOG(FIL) FILELOG$(FIL$) KILL A$ 6-25 Create a DECtape file named by A$, If the file already exists on DECtape, this command reopens it. X determines the number of blocks reserved for this file. It may be any integer up to 64. If no X is entered, lOis assumed. Open the existing file named by B$. If no such file exists, ' an error ~ssage is printed. Open a· .EOJfile named by A$. Read variables (numeric and/ or string) from the input file previously opened. Write data (numeric and/ or string) onto the output file previously opened. Close open output file. Catalog the data files stored by this user (used only in immediate mode). Catalog the data files stored by the System Manager with the extension ,DO. Delete a DECtape data file named by A$. Table 6-2. EduSystem 25 BASIC Function Summary Function Description "ABS(X) ATN(X) COS(X) EXP(X) INT(X) LOG (X) RND(X) 'SGN(X) SIN(X) 'SQR(X) TAN (X) TAB (X) FIX (X) CHR$(X) MID(A$,M,N) LEN(A$) CAT(A$,B$) Absolute value of x. Arctangent of x(result in radians). Cosine of x(x in radians). eX (e=2.718282). Greatest integer of x. Natural logarithm of x. Random number. Sign of x (+ 1 if positive, -1 if negative, 0 if zero). Sine of x (x in radians) . Square root of x. Tangent of x (x in radians) . Controls printing head position on Teletype. Truncates decimal portion of x. Converts character code to character. Used only with the PRINT command. Returns N characters, starting at the Mth character of A$. Returns the number of characters in A$. Returns a string of A$ concatenated with B$ (maximum of 6 characters returned). ERROR MESSAGES EduSystem 25 checks all statements and commands before executing them. If a statement or command cannot be executed, the system informs the user by printing an error message and the line number (if available) in which the error was found (see Table 6-3 ). Procedures used to correct errors are described under Program Editing. Table 6-3. EduSystem 25 Error Messages Message WHAT? ERROR ERROR ERROR ERROR ERROR ERROR ERROR 1 2 3 4 5 6 7 Explanation Immediate mode statement or command not understood. It does not begin with a line number and is not a valid system command. Log of negative or zero number was requested. Square root of negative number was requested. Division by zero was requested. Overflow, exponent greater than approximately +38. Underflow, exponent less than approximately-38. Line too long or program too big. Characters are being typed too fast; use TAPE command for reading paper tapes. 6-26 Table 6·3 (Cont.). EduSystem 25 Error Messages Message ERROR 8 ERROR ~ ERROR ERROR ERROR ERROR ERROR ERROR 10 11 12 13 14 15 ERROR ERROR ERROR ERROR 16 17 18 19 ERROR 20 ERROR 21 ERROR 22 ERROR 23 ERROR ERROR ERROR ERROR ERROR ERROR ERROR ERROR ERROR ERROR ERROR ERROR ERROR ERROR ERROR 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 ERROR ERROR ERROR ERROR 39 40 41 42 Explanation System overload caused character to be lost. Program too complex or too many variables. (GOSUB, FOR, or user defined function calls are too deeply nested.) Missing or illegal operand or double operators. Missing operator before a left parenthesis. Missing or illegal number. Too many digits in number. No DEF for function call. Missing or mismatched parentheses or illegal dummy variable in DEF. Wrong number of arguments in DEF call. Illegal character in DEF expression. Missing or illegal variable. Single and double subscripted variables with the same name. Subscript out of range. No left parenthesis in. function. Illegal user defined function, not FN followed by a letter and a left parenthesis. Mismatched parentheses or missing operator after right parenthesis. Syntax error in GOTO. Syntax error in RESTORE. Syntax error in GOSUB. Syntax error in ON. Index error out of range in ON. Syntax error in RETURN. RETURN without GOSUB. Missing left parenthesis in TAB function. Syntax error in PRINT. Writing past end-of-file. Missing or illegal line number. Attempt to GOTO or GOSUB to a nonexistent line. Missing or illegal relation in IF. Syntax error in IF. Missing equal sign or improper variable left of the equal sign in LET or FOR. Subscripted index in FOR. Syntax error in FOR. FOR without NEXT. Syntax error in LET. 6-27 Table 6-3 (Cont.). EduSystem 25 Error Messages Message ERROR 43 ERROR 44 ERROR 45 ERROR ERROR ERROR ERROR ERROR ERROR 46 47 48 49 50 51 ERROR ERROR ERROR ERROR ERROR 52 53 54 55 56 Explanation Syntax error in NEXT. NEXT without FOR. Too much data typed or illegal character in DATA or the data typed in. Illegal character or function in INPUT or READ. Out of data. Unrecognized command: RUN mode. Bad file name or file not found. Syntax error in LINPUT. String error, argument is incorrect type or out of bounds. String function error, missing or illegal argument. File not open or bad syntax after #. Reading past end of file. Bad syntax in OPEN. No room for file on DECtape. PROGRAM EDITING There are two times when a program may require editing procedures. The first occurs while a line is being typed but before the RETURN key is pressed. The second occurs when a line has been completely typed and the RETURN key has been pressed. Each situation has its own editing procedures. Situation 1: Before the RETURN key is pressed. Three keys may be used to correct typing errors: RUBOUT, or ALT MODE (or ESC). ~ ~ (SHIFT /0), (back arrow), SHIFT/O on the keyboard, or RUBOUT is used to delete a character from a line. BASIC prints the back arrow, deleting the last character from that line. More than one back arrow deletes more than one character, in reverse order. ALT MODE (ESC on some Teletypes) is used to delete an entire line. When this key is used, BASIC prints $DELETED, erases that line from the program, and returns the carriage so that the line may be retyped. 6-28 Situation 2: After the RETURN key is pressed. Once a line of the program has beer.t transmitted to computer memory via the RETURN key, several methods of correction may be used. Lines may be inserted, deleted, or changed. INSERTION To add a line to a program, assign a line number that falls between two existing lines, type the-line number and text, and press . RETURN. DELETION To erase a line from computer memory, type the line number only and press the RETURN key. The DELETE command may also be used to erase lines' from memory. To erase a single line, type DELETE and the line number and press RETURN. DELETE followed by the two line numbers separated by a comma erases all lines between and including the two given. For example: DELETE 10,,20 erase~ lines 10 through 20. CHANGE Old instructions may be replaced by new ones by retyping the line. This procedure is adequate for changing simple lines. When, however, the line contains a complex formula or a long message to be printed, it may be changed with the EDIT command. The EDIT command allows the user to access a single line and search for the character or characters to be changed. To use this command, type EDIT line number and press the RETURN key. BASIC waits for a search character to be typed (BASIC docs not print this search character when it is typed). This search character is one that already exists on the line to be changed. After the ,search character is typed, BASIC prints the contents of that line until the search character is printed. At this point, printing stops and the user has the following options: • Type new characters; BASIC inserts them following the ones already printed. • Type a form feed (CTRL/L) to cause the search to proceed to the next occurrence, if any, of the search character. 6-29 • Type a BELL (CTRL/G) to signal a ~hange of search character, then type a new search character. • Use the RUBOUT or ~ key to delete one character to the left each time the key is pressed. • Type the RETURN key to terminate editing of the line at that point, deleting any existing text to the right. • Type the ALT MODE key to delete all existing characters to the left except the line number. • Type the LINE FEED key to terminate editing of the line, saving all the remaining characters on that line. When the EDIT operation is complete, BASIC prints READY. Note that line numbers cannot be changed with the EDIT command. The following example demonstrates the EDIT command. An incorrect line was typed and entered to the system as follows: 60 PRINT "PI=3.14146 ABOU~'" The line was edited as follows: EDIT 60 PRINT .. PI=3.14146 .... S9 ABOUI"T'" First 6 was entered as the search character. BASIC printed the line to the 6, and the RUBOUT key was typed twice to remove the two incorrect digits (46) and 59 was inserted in the line. CTRL/G was typed and another search character (%) was entered. BASIC printed characters to the % which was removed with a RUB OUT and replaced with aT. The LINE FEED key was typed to terminate the edit and save the remaining characters. If the line is listed, the following'is printed on the Teletype. LIST 60 60 PRINT "PI=3.141S9 ABOUT'" READY 6-30 OPERATING INSTRUCTIONS Loading EduSystem 25 EduSystem 25· software is supplied on a DECtape. This tape, called the system DECtape t must be used to create the system when the system is installed. Perform the following procedures to activate EduSystem 25. ' INITIALIZE THE DECT APE UNIT Perform the following steps to prepare the DECtape unit for loading software: 1. Set the WRITE ENABLE/WRITE LOCK switch to .WRITE LOCK. 2. Set the REMOTE/OFF/LOCAL switch to OFF. 3. Place the system DECtape on the left spindle with the DECtape label out. 4. Wind four turns of tape onto the right spindle. 5. Set the REMOTE/OFF/LOCAL switch to LOCAL. 6. Wind a few turns of tape onto the right spindle with the ~ switch to ensure that the tape is properly mounted. 7. Dial 0 on the unit selector dial. 8. Set the REMOTE/OFF/LOCAL switch to REMOTE. INITIALIZE COMPUTER MEMORY The system may be activated in one of two ways: with an automatic loader (hardware bootstrap) or with an OS/8 bootstrap loader. The following instructions are for an EduSystem- 25 that includes a hardware bootstrap. If the EduSystem does not have a hardware bootstrap, see Introduction to Programming'1972, Chapter 9, for OS;8 bootstrap loading instructions. 1. Turn the key lock on the computer console to POWER. 2. Turn all Teletypes to LINE. 3. Mount the EduSystem 25 system DECtape on drive 0 as described above. 4. Set the SWITCH REGISTER (SR) to 0600 (octal).4 5. Press and raise the HALT switch. 6. Press and raise the SW switch. The EduSystem-25 DECtape spins and the system indicates that it is active by printing a period (.) on the console Teletype. If the 4 An explanation of the octal, or base 8, number system is included in Introduction to Programming 1972. 6-31 system is not CJctivated, ensure that the correct DEC tape is being used and repeat the above procedures. Immediately following the period printed by the system, the user enters the characters shown below: .R EDU25 The period is printed by the OS/8 Keyboard Monitor. The user types R to request the running of a program, in this case, EduSystem 25.r. When the RETURN key is pressed, the system prints: TO BOOTSTRAP HACK OS/8 MONITOR: LOAD ADDRESS 07600 AND START This message means that EduSystem 25 (or other OS/8 programs) can be started by setting the SR to 7600 and pressing ADDR LOAD, CLEAR, and CONT. The OS/8 Monitor prints another period, to allow the user to request a program. If, for example, the user types an incorrect response to the ensuing system dialog, . he can restart the dialog by reloading (bootstrapping back) the OS/8 Monitor from location 7600 and again requesting that EduSystem 25 be run.· ANSWER SYSTEM DIALOG When the system has been activated correctly, it prints the identification message: EUUSYSTEM 25 HASIC and begins to ask certain questions which the user must answer to establish the system configtlration. The first question is: NUMBER OF USERS (l TO 5)7 The user responds with a single digit from 1 to 5, depending on the number of terminals to be used. If one user is specified, this ques- [) Refer to Introduction to Programming 1972, Chapter 9, for a complete explanation of the OS/8 Operating System. 6-32 tion ends the initial BASIC dialog. If more than one user is indicated, BASIC continues the dialog by asking: PDP-B/L COMPUTER (Y OR N>? The user responds Y if the EduSystem 25 computer is a PDP-8/L, N if not. An N response to this question prompts the next question: STANDARD REMOTE TELETYPE CODES (Y OR N)? BASIC is asking for a PT08 or KL8E device code for each Teletype to be used (excluding the console Teletype). Standard PT08 ·or KL8E device codes arc 40, 42, 44, 46, 50, 52, and 54. When a system using PT08 or KL8E interface units i~ first installed, the user determines the specific device code for each Teletype and labels each Teletype with its specific device code. If device codes are standard, the user responds Y to this question and BASIC assumes the standard device codes and continues the dialog. If device codes are not standard, the user enters N; BASIC then asks: TELETYPE 11 DEVICE CODE? BASIC asks this question for each Teletype to be used, up to seven times for a~ 8-user system. The user responds with the specific 2-digit device code for each Teletype. When the device codes have been determined, or if the computer is a PDP-8/L, BASIC asks the following question: SAME AMOUNT OF STORAGE FtiR ALL USERS? The '!bove question requires the user to decide whether to partition the available core equally among the users on the EduSystem 25. (Since EduSystem 25 software 'uses 4K of core, the available core is always 4K less than the total core on the system.) If the user responds Y to this question, BASIC determines the size of the core memory available and divides it equally among the users, then ends the dialog. If Nis the response, BASIC determines the amount of available core storage and prints the highest core field according to the following: 6-33 Field 7-32K core memory Field 6-28K; core memory Field 5-24K core memory Field 4-20K core memory Field 3-16K core memory Field 2-12K core memory Field 1- 8K core memory . For explanation purposes, the following dialog is written for a 16K, 5-user EduSystem 25. The available core is to be allocated as follows: User 1-10 blocks (user 1 is the console terminal) . User 2-- 6 blocks User 3-- 8 blocks User 4-- 4 blocks User 5-- 4 blocks Each core field contains 16 blocks; a core field may be divided among several users, but no user may be allotted blocks in more than one core field. To determine the number of blocks, BASIC prints the following dialog and the user answers as shown: FIELD THERE YOUR THERE YOUR FIELD THERE YOUR THERE YOUR THERE YOUR 3 ARE 16 BLOCKS LEFT IN THIS FIELD. ALLOCAT IUN FOR USER !If I WILL 91=: nU!,.' l'IAI\IY HLUCKS? 19.1 ARE 06 BLOCKS LEFT IN THIS FIELD. ALLOCAT 10111 FOR USER *2 1" ILL BE HOW MANY BLOCKS? 6 2 ARE 16 BLOCKS LEFT IN THIS FIELD. ALLOCATION FOR USER '3 WILL BE HOW MANY BLOCKS?8 ARE 08 BLUCKS LEFT IN THIS FIELD. ALLOCATION FOR USER #4 WILL BE HUW .MANY' BLOCKS?4 ARE ~4 BLOCKS LEFT IN THIS FIELD. ALLOCATION FOR USER *5 WILL BE HUW MANY BLOCKS?4 When an invalid response is made to any of BASIC's questions, an error message is printed and the question is repeated. For example: STANDARD REMOTE TELETYPE CODES B. Repeated uses of RND in a program return different values between zero and one. The sequence of numbers is, however, the same each time the program is run. Thus, the sequence is reproducible for later checking of the program. The RANDOMIZE statement allows the user to make the random number sequence returned by the RND function different each time a program is run. That is, when executed, the RANDOMIZE statement causes the RND function to select randomly a new sequence of random numbers. If RANDOMIZE is used, it normally appears as one of the first lines in a program. Running Long Programs EduSystem 30 runs programs of up to 6000 characters in interactive mode and up to 5000 characters in batch mode. These limits correspond to roughly 2.00' and 250 lines per program, respectively. In some cases, interactive programs which are at or near the 6000 character limit and which contain many complex FOR, IF, and GOSUB sections are too large to be run. If this is the case, the NOLINE command may be used to gain more space. If NOLINE is used, program logic errors· which are detected while the program is executing cause an error message to be printed, but the line number of the error is not printed. NO LINE allows substantially longer programs to be run. If the program to be run is substantially longer than the 6000character limit,. it may still be run by means of a technique known as chaining. The program is written in sections, each of which is 7-5 less than 6000 characters. A chained program may have many of these program sections and, hence, may be indefinitely long. Each section of the total program is then stored in the system storage area with the SAVE command under a separate name. The final command to be executed in all but the last section is a CHAIN statement containing the name of the next section of the program. For example, the statement 950 CHAIN "PART10" would cause the system to load and execute the stored program whose name is PARTIO. In the CHAIN statement, the name of the next section of the program must be encoded in quotation marks and must be exactly six characters long. If the actual naml~ of the next section is less than six characters, one or more spaces must be inserted before the second quotation mark to make a total of six characters. For example, if the next section of the program is named LINK2, the following CHAIN statement would be used: 955 CHAIN "LINK2" ~. Execution of the CHAIN statement loads and executes the named program. The previous section of the program is deleted. Thus, the uSer only needs to load the first section and run it. All succeeding .sections of the chained program load and execute automatically. Using a Data File Just as some programs may be too large to be executed in one piece, other programs may need to store and use more data than may be accommodated under normal system operation. If this is the case, data may be temporarily stored in the system storage area. Data stored in this way is referred to as a data file. 7-6 The data file is actually a part of the program data which is de- . fined by a DATA statement. All data within a program is gathered from the DATA statements into a data list which is then read by READ statements. As items are read from the list, they are marked as already having been used. A READ statement always fetches the next item from the list. In fact, the data list may be considered to have a movable marker which remembers the next item of the list. The marker initially marks the first data item. As READ statements are executed, the marker moves down the list. A RESTORE statement moves the marker back to the top of the list. The data file capability allows a' program, by means of a WRITE statement, to change and add to this data list as well as to read it. The WRITE statement format is the same as the DATA statement format. Writing a variable puts the value of that variable in the next place in the data list. The data item that was there previously is replaced by the new value. If a WRITE statement follows a RESTORE, it changes the first item or items in the data list. If it follows one or more READs (or WRITEs), the WRITE statement changes data items further down in the data list. The total number of items' which may be put in the data list depends on the size of the program. Maximum sized BASIC programs may have up to 1000 items; small programs have room for 2000 items. Programs which write data on the data list must keep track of how much data has been' written and the order in which it was output. If data which has been written is to be subsequently read, a RESTORE statement must be executed to return the marker to the top of the data list. If data has been written off the end of the data list, the program must remember how many items the data list c~i1tains, and be careful not to try to READ more data items than are there. The normal BASIC check for end of data does not exist for a written data list. The program must also be sure that it does not write more data. than the data list can contain (10002000 items). Writing too much data causes part of the user's BASIC program to be destroyed. Data files are frequently used in conjunction with chaining since data written onto the data list by one program section may be read by the next section. The program section which writes the 7-7 data must execute a RESTORE just before the CHAIN statement. The next section, which reads the data list, must not have any DATA statements since this data would destroy the data items written by the previous section. Character Variables and String Capability Standard BASIC statements deal only with numbers, assuming all variables to be decimal values. However, BASIC is also capable of performing many useful operations on characters or words (strings of characters) instead of numbers. The character handling capabilities of BASIC depend on the representation of individual characters as numbers. Each character has its own numeric code (or character code), as indicated in Appendix B. When a character is input, by an INPUT statement, it is converted to a numeric code. All internal processing of that character uses this code. Since the code is a number. it can be used and manipulated' with any BASIC statement. When a user program is to output a character, BASIC converts the numeric code back into a character and prints the character. In short, characters stored in a BASIC program are indistinguishable from numeric values: The only difference is in the way they are used, i.e., that certain numeric values actually represent characters. The INPUT statement is used to input characters. A dollar sign ($) is placed before a variable name to indicate that a character code is to be input rather than a decimal number, e.g., INPUT $A. When the character is typed, its character code is stored in the indicated variable. It is important not to confuse character input with numeric input. A potential confusion lies in the fact that the numeric values are themselves characters. For example, the value 234 is composed of the three characters 2, 3, and 4. If these three characters were input to a BASIC program as character variables, they would be' entered as three separate numeric (character code) values rather than as the single value 234. Whether the input is character code or numeric, the physical characters typed at the terminal are identical; the difference is entirely in the way that the program interprets the input. In the following examples, each program executes an INPUT statement. In the program on the left, three characters are entered and three variables are set up. In the example on the right, a single numeric value is input. 7-8 10 PRINT "ENTER VALUE"; 20 INPUT X 30 PRINT X 40 END RUN NH 10 PRINT "ENTER VALUE "; 20 INPUT $Xll$X21$X3 30 PRINT.Xl;X2JX3 40 END RUN NH ENTER VALUE 234 50 51 52 ENTER VALUE?234 234 READY READY Note that character INPUT statements do not cause a question mark to be printed. Therefore, a series of characters may be typed without intervening question marks. Programs doing character input must therefore indicate, by PRINT statements, when input is expected. Also note that the $ is not part of the variable name. It is used only in INPUT statements to indicate that typed characters are to be converted to their numeric character codes before being stored in the variable. Character codes may be converted to their respective characters by means of the special PRINT statement function CHR$. CHR$ is the inverse of the dollar sign INPUT convention. The CRR$ function takes, as its argument, a single constant or variable and prints the single character whose code corresponds to that value. For example: 50 PRINT ChR$(65) prints the character A. CHR$. may only be used in PRINT statements. One of· the most frequent uses of the character capability is to enter words or characters into BASIC programs in response to questions. For example, a program might ask the user if he wants to run the program again with a different set of input data. The user responds by typing Y if he wants to run again or by typing N if not. The program then compares the code of the character' entered with the character code of Y to determine if they are equal. If so, it branches back to the beginning of the program. If not, the program executes the remaining statements. The following program illustrates the use of character variables in making a run-time decision. 7-9 10 PRINT PRINT "WOULD YOU LIKE TO DO THIS AGAIN (Y OR N)1"; INPUT SA 40 IF A=#Y THEN l~ 5~ IF A<>#N THEN 9~ 60 PRINT 70 PRINT "O.K. IT'S YOUR CHOICE." 8~ STOP 90 PRINT 1~0 PRINT "Y OR N1"'; 110 GOTO 3~ 120 END· RUN NH 2~ 3~ WOULD YOU LIKE TO DO THIS AGAIN *5\END is the same as 10 LET A=3 20 LET B=8 30 LET C=13 40 PRINT (A+B+C>*5 50 END and will produce the same result when the RUN command typed:." IS RUN NH 120 READY This multiple-statement capability is helpful when writing long programs since statements require less storage in the computer when they are grouped as a single statement. Listing the Program The LIST command may be used to list all or part of the current program. LIST print'S the program statements in their proper order, regardless of the order in which they were entered. The 'EduSystem 30 LIST command has four different forms, as shown below. 7-12 Command LIST LIST n LISTNH LISTNHn Meaning List the entire program. Precede it by a header line 3 giving the name of the progran:t. List the program starting at the given line number (n). Precede it by a header line. The line number must be separated from LIST by two spaces. List the entire program, but do not print a header line. List the program starting at the given line number (n), but do not print a header line. NOTE The programmer may stop a listing at any time by typing CTRLjC on the keyboard. Executing the Program The programmer may execute a program at any time by typing the ,RUN command. The existing program is inspected for errors; if none exist, it is executed. If an error is detected, an error message (see the section on Error Messages) is printed. In either case, at the end of the run, BASIC prints READY, indicating that the program may now be changed or rerun. There are two types of RUN. commands: RUN and RUN NH. RUN executes the current program, preceding it by a header line. RUN NH (NH means no header) executes the current program but does not print a header line. RUN and NH must be separated by a single space. The user may terminate program execution at any time by typing CTRLjC. Loading a Card Program for Interactive Use Programs previously written on cards may be loaded for use in interactive mode. The progr~p1 'Cleck is pr;e~eded by a NEW card and followed by a KEY c,artl. The ,U:~er mounts this deck in the Executing Card Programs for card reader in the normal'way instructions) and types the BA H command. Cards are processed in normal batch fashion u the KEY card is read. The KEY card switches the system, interactive mode. The program is then available for execution J;. editing from the interactive terminal. j/O (# 3 A header line consists of the program name followed, on the same line, by the system name (EDU BASIC). If no prograin name was assigned, the system prints "*NONE* EDU BASIC". 7-13 After two RUN commands (or after some number of RUNs if the privileged BATCH command is used), the system automatically returns to processing any additional card program in the reader. Storing Programs on Paper Tape Once a program has been entered or read correctly, it may be saved on paper tape for quick reloading, as follows: 1. Turn the Teletype control knob to LINE. 2. Type LISTNH but do not press the RETURN key. 3. Turn the Teletype paper tape punch ON. 4. Press SHIFT /CTRL, type "PPPPPP" to produce some leader tape. 5. Press the RETURN key. 6. When punching is complete, press SHIFT /CTRL, type "PPPPPP" to produce some trailer tape. 7. Turn the Teletype punch OFF. 8. Carefully rip tape off punch. Notice that an arrow head is at the beginning of the program and an arrow tail a't the end. Reloading Programs From Paper Tape Programs punched on paper tape may be reloaded using the Teletype (TTY) paper tape reader. The TAPE command is used to load programs from paper tape as follows: 1. Insert the paper tape in the TTY reader, with the arrow head facing out of the reader. 2. Turn the TTY control knob to LINE. 3. Type NEW, then press the RETURN key. 4. Type the program name. 5. Type TAPE, press the RETURN key. 6. Turn the TTY paper tape reader to ST ART. 7. When the tape has read in, turn the TTY reader to FREE. Remove the paper tape. A special control command, ECHO, may be used with TAPE to prevent the program from being listed while it is being read. The first time it is used, ECHO inhibits all printout. A second ECHO command restores normal printout. Privileged C.ontrol Commands Several optional commands are available which modify and control a program run. All· of these commands are considered to be 7-14 privileged in the sense that their use is restricted. The privileged commands are available only if the privileged command capability was selected when EduSystem 30 was loaded. During normal system operation these commands are disabled. If' a user attempts to use a privileged command, it is ignored and the system prints WHAT? A special command, the PRIVILEGE command, is used to make these privileged commands available. To use PRIVILEGE, the user types PRIVILEGE and the RETURN key. The system then waits for the user to type a one to six character password code. (The typed characters are not printed.) At the time the system was loaded, a password was typed into the system. The characters typed after the PRIVILEGE command are compared to this password. If they match, the PRIVILEGE command is successful and all privileged commands may then be used. If they do not match, the message INVALID PASSWORD is printed and all privileged commands continue to be unavailable. In short, the user must know the password in order to use any privileged command. It is' important that the password be kept secret. For this reason, the password is never printed when the user types it. It is possible to change the password code at any time. The command, PASSWORD, which. changes the code is, of course, a privileged instruction. Certain privileged commands are used only when processing card programs; these commands are discussed under Executing Card Programs. The other privileged commands, SAVE and UNSAVE, are discussed below. All privileged commands must be typed at the terminal; they cannot be entered on' cards. Using the System Storage Capability EduSystem 30 allows the system device (DECdisk or DECtape) to be used for permanent on-line storage of programs. Programs stored in this way may be loaded instantly, without the need to load a paper tape or card deck or type a program. SAVE AND UNSAVE COMMANDS' Two commands, SAVE and UNSAVE, may be used to change the contents of the system storage area. Because the amount of storage space is limited, and to prevent accidental erasure of stored 7-15 programs, both SAVE and UN SAVE are privileged commands. During normal system operation they are disabled. SAVE and UNSAVE may only be used after a successful PRIVILEGE command has been executed. The SAVE command stores the programs currently in memory on the system storage area (DECtape or DECdisk) and gives it the name specified by the last NEW, OLD, or NAME command. Any existing program stored under this name is deleted. Thus, all stored programs have names which may be used to recall th,em in the future. If a SAVE is attempted when the privileged commands are disabled, the system prints WHAT? and ignores the command. If a S'Uccessful PRIVILEGE command has been executed, but the storage area is full, the message NO SPACE is printed and the program is not stored. The UNSAVE command is used to delete a program already stored. UNSAVE must be preceded by a NEW, OLD, or NAME command which specifies the name of the file to be deleted. The user must be certain to use exactly the same program name as he used when be first identified the program. Like SAVE, UNSAVE is ignored unless preceded by a successful PRIV ILEGE command. If the program to be deleted does not exist in the system storage area, the message FILE NOT SAVED is printed and no program is deleted. CATALOG COMMAND The CATALOG command may be used to obtain a list of the names of all programs available in the system storage area. The CATALOG list includes the number of storage blocks used by the program. A standard EduSystem 30 includes 116 blocks of storage space (for nonstandard systems, see Calculating Available Storage). The CATALOG command may be used to determine how many of these blocks have been used and, hence, how many are free. LENGTH COMMAND If the system storage space is almost full and another program is to be saved, the LENGTH command may be used to determine if there is room to store the current program. If space is not available, an existing· program must be deleted. In all cases, the maximum number of stored programs, regardless of size or storage device, is 62. 7-16 OLD COMMAND The user may load programs stored in the system storage area at any time by typing the OLD command. After the OLD command is entered, the system prints OLD PROGRAM NAME. The user then types the name of the program to be loaded. The user must be certain to use exactly the same program name as he used when he first identified the program. Returning to Batch Mode At the end of an inte.ractive session, the system is ready for further batch processing. When the system prints READY, the BATCH or STACK command may be used to begin a batch run. Program Editing There are two times when a program may require editing procedures. The first occurs while a lirie is being typed but before the _ RETURN key is pressed. The second occurs when a line has been completely typed and the RETURN key has been pressed. Each situation has its own editing procedures. Procedure 1 : Before the RETURN key is pressed. Three keys may be used to correct typing errors: ALT MODE (or ESCAPE), -E- (back arrow), or RUBOUT~ ALT MODE (or ESCAPE) is used to delete an entire line. When this key is used,BASIC prints DELETED, erases that line from the program, and returns the carriage so that the line may be retyped. -E- (back arrow), SHIFT /0 on the lceyboard, or RUBOUT is used to delete a character from a line. BASIC prints the back arrow, deleting the last character from that line. More than one back arrow deletes more than one character, in reverse order. Procedure 2: After .the RETURN key is pressed. Once a line of the program has been transmitted to computer memory via the RETURN key, several methods of correction may be used. Lines may be i~serted, deleted, changed, or renumbered. INSERTION: To add a line to a program, assign a line number that falls between two existing lines" type the line number and text, and press RETURN. 7-17 DELETION: To erase a line from computer memory, type the line number only and press the RETURN key. CHANGE: To change an individual line, simply retype it. The old instruction is replaced by the new one. RENUMBER: Occasionally, repeated editing and insertions result in there being no more room in an area of a program to insert new lines. It is then necessary to spread out the line numbers so there is room for new ins~rtions. The RESEQUENCE command is used for this purpose. To renumber a program, type the RESEQUENCE command. This command changes the first line's number to 100 and renumbers each succeeding line wjth an increment of 10. RESEQUENCE also automatically changes all GOTO, GOSUB, and IF statements to correspond to the new line numbers. WRITING AND RUNNING CARD PROGRAMS ·W:riting a ]~r()gram on Cards Programs to be submitted to Edu~ stem 30 are first transcribed onto specially formatted BASIC carl s. These cards are preprinted with a series of small rectangular b xes. Each card has 39 columns of boxes, with the column num r printed along the lower edge. Figure 7-1 illustrate,s a BASIC cfd. ""II"""""""""'1""T Irnrnrnrnrnrnrnillillillrnillrnrnrnrnrnrnrnrnrnrnillrnrnrnrnrnrnillillmill~ Irnrnrnrnrnillrnillrnrnillrnrnrnrnrnmrnrnrnillrnillillrnillrnrnrnillillillill~ ~~~D~D~"-'~ ... h'~~~~~ffiffi~ffiffiffiffi~ffiffiffiffiffi~ffi~ffiffi~ffiffi~~~ffiffiffiffi~ fiJ [iJ [i] "J ~ 'I ~ (j] ~m. IJ leu oo..fiiJ 91ft;] m[ilJ [ij] (j] ~ [1] ill [1] ~ ~ :lJ Wru 'J ·f,.'1 ['fj [jJ l] , ilbD:lllj I)] I to OJ tdlUlJ ~l Ell L'l [] [jJ Ell OJ ~l ~ ~ I] m 3 ..., ,f· llj ~ rll ~ ~ ~ [j] ~J ~ 00 Ell ~J [1J ~ Ell t~ ~ rn ~ !1l E!l 00 E!l ~ ru crJ ~ [ij] [ij] Ell EiJ [!!J t!l f1] 8 . 00 ")"',,,f, 'n EiJ BJ I1l EiJ Im~~ fl] E!J tlj ffi ~ EiJ EiJ EiJ EiJ EiJ t:!] Ell ~ ill@] @J "" F 'IJ f1] f1J Ell ~ I!lftifiJtn1I~ ~l MOftU ffi Ell ~ [t l'lJ ~ Ell Ell Ell ~ ~ 8 ernrnu ern 4. D B.oltn ~OOOO- ~~ffi~BJBJBJmm~ffi~~ffi~~BJEiJBJ~~~~~~~ffi~BJ~~~~~~~ 7 r~~1~~E!lE!l~mmE!lm[ij]OOrnE!lffirn(j][ij][ij]rllE!l~ffirnffi~~[ij][ij](j]~E!lE!l[ij]S 00 l!lOO 8 "'''.&, ffi~~~[;Jffiffi~OO~~~~~~ffi~~~l1]fj]l1]~~OO~~~~l1]~~~ ~ @]~ 9 .' ....... I 2 3 4 'ffi~~~ffiffi~]ffiOO~~[;][;]OO~~OO~~[j]ffi~[;j~OO[;J~~ffi~~~~ • 1 IU II II 12 1l!J4!J5IJIII1!J1I 1m! 211221231241251211211211211301311321331341 351311311311311 Figure 7-1. * EduSystem 30 BASIC Card Program statements are written onto e BASIC cards by marking these boxes with ordinary lead penc . Each box is marked with a single heavy line, drawn either verti ally or diagonally. It is not necessary to fill in the entire box. Av, id making any stray marks, 7-18 f f as the- computer reads all marks on the card, whether or not they occur inside a box. Any stray marks cause the computer to misread the card. A program to be submitted to EduSystem 30 is marked on a series of these cards; each program statement is placed on a separate card. LINE NUMBERS The first item of each program statement to be marked on the card is the line number. All program statements must have line . numbers from 1 to 999. The line number is marked in the leftmost three columns of the card. In each of these columns are 10 boxes containing the digits 0 through 9. (Above these numbered boxes are six other bo:xes which are never marked as part of a program statement. They are used as control cards and are explained later.) The user marks an appropriate digit in each of three columns. If the line number is only one or two digits, it can be marked in any of the three columns. Blank line number columns are ignored. Figure 7-2 shows a card marked with the line number 120~ Figure 7-2. Line Number Example Line numbers should be marked on cards in "the order in which program statements are to be executed: the lowest line number on the first cay;d, the highest line number (the END statement) on the last card. If the cards are not physically qrdered by line number within the card deck, EduSystem 30 still executes the program in line-number order. The only time when- the order of the cards is important is when two cards have the same line number. In that 7-19 case, only the last card in the deck which has that line number is used in the program. BASIC STATEMENTS BASIC statement types are marked after the line number, in column 4 or 5, within the outliI1ed area. Each box in this area represents a single BASIC statement; thus, one mark in the appropriate box indicates the corresponding statement type. It is not necessary to spell out the statement. Since each statement is marked on a separate card, each program card should have only one mark in column 4 or 5. In Figure 7-3, the LET box has been marked. Line 120 is, therefore, a LET statement. (The implied LET cannot be used with card programs.) Figure 7-3. Statement Example STATEMENT OPERAND The line number and statement type are marked in specific sections of the card. The remaindec of a statement, the statement operand, is marked in a different manner in columns 6 through 39. The first step in this process is to write the remaining characters of the line in the boxes across the top of the card, one character to a box, starting in column 6. The boxes below each of these cqaracters are then marked with the aid of the BASIC template, a~ shown in Figure 7-4. 7-20 + - II I t $&OEFIA()<> o? ! G H 110 B - I t ; 0 IG : J K L 1J H F paR 1 M K I [ STU 1 P N L $ V w· x 1 s a o 7 y z 1v T R : . 1Y W U It ." 1. z X ; , \ I . M N 0 2 3 4 5 E C'II + Il - ( 7 ... ) 8 I < 9 t > . -. , 1 \ 2 3 I 4 & 5 ! 6 •• 7 8 9 EDUSYSTEM-30 BASIC TEMPLATE momODma Maynard, Massachusetts Figure 7-4. EduSystem 30 BASIC Template The template has a column of holes down the center with the characters used in writing an operand printed on either side. All characters are printed twice on the template, once on the left and once on the right. The top hole in the template corresponds to the blank boxes at the top edge of the card where the characters of the operand were written. The bottom pair of holes correspond to the row of heavy black marks along the lower edge of each card. The twelve holes in between correspond to the twelve boxes in eachcard column. The following procedure is used to mark the statement operand characters: 11, Place the template on the card so that the character to be marked appears in the top box of the template and the two black marks appear in the bottom pair of holes. 2 .. If the character is a digit (0 to 9), find that digit on either side of the template and mark the one box which is beside that digit. 7-21 3. If the character is not a digit, find the two occurrences of that character on the template, one on the left and one on the right. Mark the two boxes which are beside these characters. 4. If the character is a space, make no marks. An example of the marking procedure is shown in Figure 7-5. EDUSYSTEM-30 BASIC TEMPLATE ( mamDDma Maynard. Massachusetts Figure 7-5. Marking the Statement Operand ,I' SUMMARY OF CARD MARKING PROCEDURE A completed card is :tnarked in three places: 1. Columns 1 through 3 to mark the lin.e number. 2. Column 4 or 5 to indicate the BASIC statement type. 3. Columns 6 through 39 to indicate the statement operand, as w!itten across the top of the card. Figure 7-6 shows two examples of completed cards. 7-22 Figure 7-6. Completed BASIC Cards Submitting a Program to be Run When all statements of a program have been marked on cards, the cards are collected into a single deck for submission to the computer. However, in addition to the deck of program cards, the computer must be given the program name and explicitly instructed to execute the program. Special cards, called control ~ards, are added to program deck for this purpose. Control cards are not part of the actual program. They do not have line numbers and are placed ~t the beginning and end of the program deck. 7-23 THE NEW CARD The first card of any deck submitted to the computer must be a NEW card or an OLD card 4 (see Using a Stored Program), which contains the name of the program. Any cards in a deck which come before a NEW, or OLD, card are ignored. If no NEW, or OLD, card is included in the deck, the entire program is ignored. A NEW card has a single mark in the NEW box in the upper left-hand corner of the card. It has no other marks in columns 1 through 5. The name of the program, which can be 1 to 6 characters long, is marked using the template and starting in column 6. The remaining columns of the NEW card, starting in column 12, should be used to mark identifying information such as the name of the programmer. THE LIST CARD When the computer reads a program, it reads the marks in the columns rather than the characters printed across the top of the card. If the columns below each character are accurately marked, the computer reads the card as intended. Erroneous marks, however, cause, the computer to read the statements incorrectly. It is useful to obtain a printed listing of the program exactly as it was read by the computer. The LIST command instructs the computer to print such a listing. A LIST card contains a single mark in the LIST box, the topmost box in column 3. The LIST card should be placed after the program deck,· immediately before the RUN card. THE RUN CARD Each program deck submitted to the computer must have a RUN card following the last program card. A RUN card has a single mark in the RUN box, the topmost box in column 2. The RUN card is the signal for the computer to execute the program. If a program deck has no RUN card, the program is loaded into the computer but never executed. The RUN card is normally the last card in the deck. Since the NEW (or OLD) card is the first card in the deck, it is often marked on a colored card to make it easy to spot the beginning of separate programs in a stack of many programs. Control cards can be easily identified if the system manager runs a felt-tip marker over the tops of a box of cards and makes these cards available to students for use as control cards. 4 7-24 SUMMARY A complete program deck, ready to be run by the computer, consists of the complete set of program cards preceded by a NEW· card and followed by a LIST and/or a RUN card. If other control cards are being used, they may be iriserted as necessary. Control cards should be placed before or after the program deck, not inserted within it. This complete deck is then submitted to the computer operator to be run. (If there is no system operator, each student must run his own program through the computer as described under Executing Card Programs.) Figure 7-7 shows a . BASIC program deck. ~ 0 '"2 UJ t- V> >- III :::> CI UJ .,: '"0 .,: '"0 U ,..: 11. 0 '"<-' u, ,..: 11. 0 '"<-' !:: £! Q t3 i5 Figure 7-7. BASIC Program Deck Getting the Results of a Computer Run Whenever EduSystem 30 processes a card program, it prints the results of that run on the Teletype. The ,format of this output is as follows: \ 1. Beginning of Output-A row of dashes (- - - -'- -) is printed to indicate the beginning of program output and thus separate each program from the output of the previous program. 2. Identification Line-The information on the NEW card is printed at the top of the first page of output. This information usually includes the name of the program and the name of the programmer. 7-25 3. Program Listing-If a LIST card is included directly after the program deck, a listing of all statements in the program is printed. It is preceded by a header line which includes the name of the program and a short message selected by the system operator. 4. Program Output-If a RUN card is included at the end of the deck, the program is executed. The results of all PRINT statements are printed as program output. The printed program output is preceded by the same header as the program listing. Using a Stored Program In all previous examples the program to be executed is submitted on a card deck. The NEW card at the front of the deck indicates that the program to be run is a new one (i.e., a program the computer does not already have stored away) and that it is contained in the cards which follow the NEW card. The computer is also capable of storing programs for future use. Stored programs are considered -to be old programs. They do not have to be submitted on cards each time they are run. An OLD card is used to call a program which has been stored in the system previously. The OLD card has a single mark in the OLD box in column 1 of the card. All programs stored within the system have names. The name of the old program to be used must be marked starting in column 6. The user must be certain to use exactly the same program name as he used when he first identified the program. For example, blanks which preceded the program name or appear in the name itself must be included. The OLD card is used instead of a NEW card; it is, therefore, the first card in the deck. Like the NEW card, it should have identifying information coded in the columns after the program name. (Like the NEW card, OLD is often marked on a colored card.) Since the program is already stored in the system, the OLD card need not be followed by a program deck. The next card can be the RUN card. Two cards, an OLD card followed by a RUN card, are all that is needed to run a stored program. If the user wishes to supply some of his own input data to an OLD program, this data is marked as regular DATA statement cards. These DATA cards are placed between the OLD card and the 7-26 RuN card. They 'are merged into the stored program before it is executed. 5 Interacting With the Operator If card programs are being run under the supervision of a system operator, he may be requested to perform certain functions, such as entering data or making minor modifications to the program. An OPR card is used to communicate with the operator. An OPR card has a single mark in the OPR box in column 4 of the card. Any message can be marked in columns 6 through 39. When an OPR card is encountered in a program deck, the· message in columns 6 through 39 is printed and a bell rings to alert the operator. Normally, the OPR card is used to request the operator to perform some function which a card user cannot perform directly. Operations such as saving programs in the system storage area can only be done by typing commands at the Teletype. A KEY card is used to have the computer pause so that the operator can type one or more commands. The KEY card contains a 'single mark in the KEY box in column 2 of the card; it should be the last card in the deck. KEY should, of course, be preceded by one or more OPR cards, telling the operator what to do when the computer pauses. For example, BASIC programs can request data from the operator. An INPUT statement is used to request data from the Teletype, such as the current date. Editing and Rerunning a Program After a program has been executed by means of a RUN card, it is still available in core memory and may be modified and/or run a second time. New lines, or new data, may be added to the program, or, may replace existing program statements. Any program lines to be added should follow the first RUN card. After these new cards, a second RUN card should be included. The The DATA statements submitted on cards must have line numbers which differ from the line numbers of the stored program. Otherwise, these DATA statements will replace program statements. Also a stored program which is to be used with card data should have no DATA statements of its own. 5 7-27 number of RUN cards allowed per deck operator and is normally two. IS set by the system Inserting Messages in the Program Printout One line messages can be inserted into program output by using an MSG card. An MSG card has a single mark in the MSG. box in column 3 of the card. Columns 6 through 39 can contain any message. This message is printed as part of the program output. Sample Program The following sample program demonstrates the use of EduSystem 30 as a computational tool by students who have no knowledge of computer programming. The program is already stored in the computer. PROBLEM Students in a physics class are performing a lab experiment whose results require very lengthy data reduction. Rather than have each student perform these· calculations manually, the instructor wrote a program to do it and stored the program under the name LAB3 7. This program has no line numbers between 900 and 950. Each student is to prepare a deck containing his data, in some predefined order with line numbers between 900 and 950, and submit it to the computer. PROCEDURES Each student prepares a deck containing his data and submits it to the computer. The decks are prepared in the following manner: 1. Each student writes his lab data values across the top of one or more cards, starting in column 6. Values on any one card are separated by a comma. 2. When all data values have been obtained, the student completes the marking of the data cards. The DATA box in column 5 of each card is marked. The first card is marked with line number 900 in columns 1 to 3. Succeeding cards are given line numbers 901, 902, etc. Finally, using a template, the student fills in the boxes in columns 6 through 39. 3. An OLD card is marked with a single mark in the OLD box, the program name LAB37 in col.umns 6-10, and the student's name after column 11. The OLD card is placed 7-28 before the data deck. Next a RUN card, with a single mark in RUN box is placed behind the deck. These cards are then submitted to the computer. PRINTED RESULTS The following is a sample printout of the results of one student's input to the LAB37 _program: OLD LAB37 A. EINSTEIN PHYSICS 1 RUN LAB37 EDUBASIC DATA SET I 1 = SAMPLE SIZE 12 SUM = 444 MEAN 37 STD. DEVIATION = 7.51665 = DATA SET /I ~~,~ , "if -_/I 2 SAt1PLE SIZE = 8 SUM = 32.7 MEAN = 4.0875 STD. DEVIATION / EXECUT -.-.' - Once" EduSystem 3 as een oaded"and started, it is available for processing program decks (if the batch capability was retained at system load time). It is not necessary to reload or restart the system each time it is used. -~--,.,. "'> -- \ ~-------- Perform the following operations to process batch (multiple' programs) of marked cards. Collect all programs to be run into a i single deck. Any number of programs may be included so long as I the deck fits into the card reader (maximum of 400 cards). ,i i 1. Arrange all cards so that they face in the same direction. f 2. Place the deck in the reader, face down with the row of ! black marks on the bottom of each card placed inward ,r toward the back of the reader. 7-29 3. Ensure that the reader power switch is ON, then press the START button. At this time, all red lights on the card reader conttol panel should be off; the single green light should be on. 4. Type BATCH. The BATCH command is used to commence processing of the entire batch of programs loaded into the reader. Once a batch run is initiated, it continues until all cards have been processed. EduSystem 30 then asks: MORE CARDS? 5. Type N if no more programs are to be executed during this run. EduSystem 30 concludes the batch run by typing READY. If more programs are to be executed, continue at steR 6. 6. Place the. additional program cards in the reader, then press S!ART. Respond to the MORE CARDS? question by typing Y. The batch operation restarts. All output from a batch is printed at the Teletype (or possibly on a line printer, see Using Optional Hardware). The output of individual programs is separated by rows of dashes (- - - - - - ) .. Executing Card Programs Individually EduSystem 30. may be used as a system in which each user loads and executes his own card program. The system is started exactly as it is for a batch run; the BATCH command is typed, even though no cards are in the reader. The system, finding no cards, asks: MORE CARDS? At this time the system is ready to accommodate a single user with a card deck. The single user can proceed with the op-erating procedures· described under Normal Batch Operation. When all " cards have been processed, the system again asks: MORE CARDS? 7-30 The user may then tear off his program output and leave the system ready for the next user. Controlling a Batch Run A batch operator may control the execution of card programs. CTRL/C may be typed at any time to terminate a program run and automatically continue with the next program. CTRL/C does not interrupt the loading of a program, only its execution or listing. When CTRL/C is used to terminate program execution, the message STOPPED BY OPERATOR is printed. The ALT MODE key (labeled ESC on some terminals) may be used to interrupt the system while it is reading cards (i.e., halt the batch operation) and allow the operator to type commands at the Teletype. The operator can then type BATCH to begin processing of the next program in the deck. Several optional commands (BATCH, MAX, 'HEADER, ST ACK, and LOG) are available to modify and control a batch run. All of these commands are privileged commands (see Privileged Control Commands). They can be used only if privileged command capability was retained at system load time and if the user knows the correct password. BATCH COMMAND In the privileged mode, the BATCH command may be followed by a single space and an integer which is less than 4000. For example: BATCH 20 This number is the maximum number of RUN commands which may be executed by any single program deck. If privileged commands are not enabled or if no number is specified, the BATCH command is executed and 2 is the number of RUN commands ( cards) allowed per program. \, MAX COMMAND Occasionally, a program is submitted which does not terminate. It will run indefinitely (in a loop) and delay the execution. of other programs until the operator stops it The MAX command can be used to automatically terminate programs which run too long. MAX defines the maximum number of BASIC program • 7-31 statements which may be executed in a program. The system counts instructions in units of 200. Thus, the limit set by the MAX command is the number of 200 instruction units which are allowed per program. If very small programs are being run, a MAX of 10, allowing execution of 2000 statements, is reasonable. This command is typed as follows: MAX 10 More complex programs need to execute more than 2000 statements. In this case, a correspondingly higher limit should be set. If no MAX is set, or if the operand of MAX is 0, programs may be run indefinitely. A MAX limit is only in effect for the succeeding batch run. If the program being run executes a CHAIN instruction, the instruction count is restarted. HEADER COMMAND Before running or listing a program, the system prints a header line consisting of the name of the program followed by the message EDU BASIC. The HEADER command may be used to change this message to any new header composed of 1 to 12 characters. The new header is then used for all programs in the next batch run. Thus, this command can be used to identify the programs in that batch. For example, if a batch consists of all the programs \ from a given class, the name of the class or of the instructor might be used for the header. To use the HEADER command, type HEADER and press RETURN; then type the new header message and press RETURN again. For example: HEADER PHYSICS 101 STACK COMMAND The KEY command and the INPUT statement may be used by a card program to interact with the operator, as described previously. When a batch is being processed unattended, these commands stop program execution. Therefore, the STACK command is available to start up an unattended batch run. The STACK command makes all INPUT and KEY instructions illegal and causes processing of card programs to begin. Like the BATCH command in privileged mode, the STACK command may be followed by a space and an integer which specifies the number of • 7-32 RUN commands allowed per program. For example, if the STACK command is typed as: .. STACK 4 it allows any program to be executed four times. This number is 2 by default if not explicitly specified or if the system is not in privileged mode. Execution of BATCH, STACK, NEW, or OLD commancis automatically locks out the privileged instructions. Subsequent privileged instructions must be preceded by a successful PRIVILEGE command. LOG COMMAND As programs are run, a system log is created which contains a record of all the programs which have been run. More specifically, the log retains all information included on the NEW or OLD card which precedes each program deck. NEVv' or OLD cards generally contain such information as the name and cl.ass of the student who submitted the program. The privileged command LOG may be used to obtain a printed listing of this log. If a very large number of programs are run before the log is printed, or if the amount of space reserved for the log when the 1\ system was loaded is small, the log may become full; if this hap- (\) i pens, the log is automatically printed at that time without a LOG:\ command being given. .._, _. __ .. __~.. (. \\ ~- --'---.',-----..',. ' ·'-~---l'··~ Hands-On Interaction Versus Batch If the user wishes to get maximum throughput of student programs, he should use the ST ACK command. However, if the user wishes' to allow hands-on student int(~raction with a hign throughput, he uses the BATCH command and implements the plan outlined below. Most student interaction in programming occurs during debugging. The EduSystem 30 BATCH command allows the user to mix hand-on use with high throughput. Typing BATCH with no following number allows each program to be run a maximum of two' tiines. A programming class use of EduSystem 30 is optimized by ,entering cards in the following order: NEW program name caId deck student, class 7-33 , I f I I I I LIST card RUN card KEY card EduSystem 30 reads 'the deck, lists the program, and attempts execution. The student's error messages print at this time, if errors occur, and the KEY card allows the student to sit down at the terminal and correct the errors on-line. When errors have been corrected, the student types his second RUN,. getting his second attempt at execution. Upon completion of the second RUN, EduSystem 30 automatically reads the next student's cards. This use of BATCH with the KEY cards allows each student two successive attempts at a successful RUN and brings much of the excitement of interaction into the EduSystem 30 batch operation. ERROR MESSAGES Some programs execute' correctly the first time they are tried. Most others, especially if they are at all complex, have errors in them. EduSystem 30 checks all statements and commands when they are entered (on cards or from the interactive terminal) and before executing them. If it cannot execute a statement or command, the system informs the user by printing one of the following types of messages. . Batch Mode Program Loading Errors The following messages are printed if errors occur while BASIC is loading a card program. Message .Explanation BAD CHARACTER One or more characters on a card were· not understood. The character % replaces any unreadable character. The information on the card is processed if possible. This error does not cause any subsequent RUN commands to be ignored. BAD CHARACTER- Same as BAD CHARACTER message except LINE NOT USED that the information on the card is ignored. This error does cause subsequent RUN commands to be ignored. . WHAT? Line does not make sense to the system. It does not begin with a line number and is not a valid system command or statement; I 7-34 Message NO ROOM FILE NOT SAVED FILE TOO BIG FOR BATCH MODE Explanation The program is too large to be loaded, i.e., it is greater than 5000 characters. Larger programs should be run in interactive mode or CHAINed. The progra~ named on an OLD control card is not available in the system storage area. The program named on an OLD card is too large to be run in batch mode. It mus(be run interactively. Interactive Mode Program Loading ErrorsH As each line is typed, EduSystem 30 checks it for program loading errors. If it finds an eqor, it prints one of the following error messages immediately after the erroneous line. Explanation Message WHAT? LINE NO. TOO BIG LINE TOO LONG NO ROOM FILE NOT SAVED NO SPACE Bell I/O ERROR INVALID PASSWORD Line does not make sense' to the system. It does not begin with a line number and is not a valid system command. The line number of a line or the' argument of a system command is greater than 4095. Line just entered is longer than 80 characters. There is no room to store the line just entered. The program named as the operand of an OLD command was not previously saved on the system device. There is not enough space on the DECtape to SAVE the current program. If an invalid character is entered, the Teletype bell rings and the character is ignored. An input or output error occurred on the DECtape unit. Be sure that the unit is on-line, write-enabled, and the unit number is set correctly. Retry whatever was interrupted by the error. If the problem persists, there is a hardware problem. Contact the system administrator or DEC field service. The password typed after a PRIVILEGE command is not the system password. Privileged mode is not entered. To correct program loading and coding errors indicated by these messages, the appropriate line in the program must be corrected in the manner described in the Program Editing section, Procedure 2. 6 7-35 Coding Errors 7 After the RUN (or RUNNH) command is entered, EduSystem 30 checks each statement before executing it for mistakes in the BASIC program coding. If the system cannot execute a statement, it informs the user by printing one of the following messages and the line number in which the error was found. Message Explanation CH 'EN There is an illegal character in the line. Program does not have an END statement as the last line in the program. Not enough NEXT statements in the program. There must be a NEXT statement for each FOR statemellt in the program. FOR and NEXT statements do not match. There is a NEXT statement: in the program whose variable is not the same as the variable in the corresponding FOR statement. Line contains an improperly written decimal number or constant.. It may, for example, have two decimal points or have an alphabetic character in it. The program as a whole is too big to be run by the sys- . tern. Making the program smaller, reducing the size of . subscripted variables, or using the NOLINE command may help. Program has too many (more than 8) FOR-NEXT loops one within another. Line contains an improperly used parenthesis. Generally, the problem is an expression which does not have an equal number of left and right parentheses. Statement contains an invalid relational operator _«, =, >, <=, >=). Relational operators may only be used in IF statements. Statement as a whole is not properly written and, as a result, does not conform to proper BASIC syntax. For example, a semicolon is aHowed in a PRINT statement but not in a READ or INPUT statement. Statement word is not one of' the legal BASIC statement types. The program is too big to be run. Cause is usually an extremely large number of PRINT statements. FN Fa LI M1 M2 NE PC RO S1 S2 ST TB 7 To correct the program loading and coding errors indicated by the messages, the appropriate' line in the program must be corrected in the manner described in the Program Editing section, Procedure 2. 7-36 Message Explanation TO Program :is either too large or too complex to be run. The total number of variables, constants, functions, and line numbers should be reduced, if possible. A GOSUB, GOTO, or IF statement contains a line number which does not exist. A quotation mark indicating the beginning of a 'String of text does not have a corresponding quotation mark at the end of the text string. UL UQ Program Logic Errors 8 Some errors do not show up until the program is actually executed. An example of this type of error is an expression which uses a square root of a variable. If, when this square root is actually calculated, the variable has a negative value, a program logic error has occurred. EduSystem 30 prints the following messages if program logic errors occur. Message Explanation CH A CHAIN statement tried to chain to a program which was not available in the DECtape storage area. Program ran too long and was automatically stopped by the system. The program ran out of data. It attempted to do a READ after all data had been read. The program attempted to divide by zero. Instead of dividing by zero, BASIC divides by the smallest possible number, giving a result of about 10 500 • This error does not cause the program to stop. An expression coptains a function which was not defined in a DEF statement. The program is too complex to be executed. The problem is generally that too many subroutines have themselves executed GOSUB instructions. Program attempted to take the logarithm of a negative number or zero. A RETURN statement was used outside of ;a subroutine or a subroutine was entered by a GOTO instead of a GOSUB. See GS. CO DA DO FN GS LG RE SP 8 Some program logic errors may be corrected by the method described in the Program Editing section, Procedure 2. Most, however, necessitate the rewriting of the program. 7-37 Message Explanation SQ Program attempted to take the square root of a negative number. BASIC automatically takes the square root of the absolute value of the number instead. This error does not cause the program to stop. Program used a sUbscript which was too big for the variable. The maximum size of a subscript is specified in a DIM'statement. There is no r,oom to write data. The program attempted to do a WRITE statement when the data list was full. (Note that if this error occurs, the program text will no longer be intact. A NEW, OLD, or SCRATCH command must be used to clear the program area.) SS WR OPERATING INSTRUCTIONS Loading EduSystem 30' The EduSystem 30 software is supplied on a paper tape. This tape must be loaded into computer memory when the system is first installed. Once loaded, the software need not be reloaded. Perform the following procedures to load the EduSystem 30 software. INITIALIZE THE DECDISK If the system device is DECdisk, perform the following steps to prepare the disk for software loading: 1. Ensure that the disk unit is on (red light illuminated inside the back of the computer cabinet) . 2. Ensure that all disk protect switches (located inside the front of the computer cabinet) are III the off (down) position. INITIALIZE THE DECTAPE UNIT If the system device is a DECtape unit, perform the following steps to prepare the unit for software loading. 1. Set the REMOTE/OFF/LOCAL switch to OFF. 2. Place a DECtape on the left spindle with the DECtape label out. 3. Wind four turns of tape onto the empty reel on the right spindle. 4. Set the REMOTE/OFF/LOCAL switch to LOCAL. S. Wind a few turns of tape onto the right spindle reel with the ~ switch to ensure that the tape is properly mounted. 7-38 6. Dial 0 on the unit selector dial. 7. Set the REMOTE/OFF/LOCAL switch to REMOTE. 8. Set the WRITE ENABLE/WRITE LOCK switch to WRITE ENABLE. INITIALIZE COl\1PUTER MEMORY The EduSystem 30 software tape may be loaded into memory in one of two ways: with an automatic loader (hardware bootstraps) or with the Read-In Mode (RIM) loader program. The following loading instructions are for an EduSystem 30 that includes a hardware bootstrap. If the EduSystem does not have a hardware bootstrap, see Appendix A for instructions on using the RIM loader. 1. Turn the key lock on the computer console to POWER. 2. Turn the Teletype to LINE. 3. Place the EduSystem 30 tape in the appropriate reader (high-speed or Teletype) with the leader code (ASCII . 200) over the read head. 4. Set the SWITCH REGISTER (SR) to 5356 (octal).9 5. Press and raise the HALT switch. 6. Turn on the appropriate paper tape reader. 7. Press and raise the SW switch. The tape should begin to move. If it does not, ensure that the correct tape is being used and that tape is positioned. over the read head. Repeat the above procedures. System Building Dialog When a portion of the EDUSYSTEM-30 paper tape has been read, BASIC prints a series of questions (see Figure 7-8) concerning the system configuration. The user responds by typing Y for yes and N for no, followed by the RETURN key. The first question is: STANDARD SYSTEM? EduSystem 30 has several optional operating modes and may be used with a variety of hardware components. A response of Y to the above question causes EduSystem 30 to build a system as it An explanation of the octal. or base 8, number system is included in Introduction to Programming 1972. 9 7-39 would if the following answers were given to the other system building questions: IS SYSTEM DEVICE A DF32 IHSK?Y HOW MANY DISKS?1 DO YOU WANT BATCH CAPABILITIES?Y HOW MANY BLOCKS FOR LOG?6 BATCH INPUT ON PUNCHED CARDS?N DO YOU WANT PRIVILEGED COMMAND CAPA8ILITY?Y TYPE INITIAL PASSWORD (EDU-BASIC) DO THE FOLLOWING EXIST: HIGH-SPEED PUNCH?N LP08 PRINTER?N Basic then asks: PROGRAM LIBRARY INITIALLY EMPTY? The user respondsY if there are no programs to be saved on the system device. If programs are to be saved, the response must be N and the questions in boxes 1 through 8 of Figure 7-8 must be answered in the same way as \Yhen the system was built. If the user types N in response to the question STANDARD SYSTEM?, EduSystem 30 recognizes that a nonstandard system is being loaded and asks the following questions: IS SYSTEM DEVICE A DF32. DISK? f TC01 DECTAPE? RF(ilJ8 DISK? LINCTAPE? TO BE DECTAPE? This series of questions is asked only until a response of Y is typed. If the device being described is not the one being used in the system, the user responds ,by typing N. If the system device is a disk, either DF32 or RF08, the system asks: HOW MANY DISKS? The user responds by typing the number of disk surfaces available in the system (1, 2, 3, or 4) and then typing the RETURN key. If the system device is TD8E DECtape, the system asks: 7-40 DO YOU HAVE A TDBE ROM? Respond Y if the system has a TD8E Read-Only Memory. If the response is N, the system asks: 8K OF CORE? If the system device is DECtape, the system must include either a TD8E ROM (TD8E DECtape only) or 8K of core memory. If the response to the previous question was Y, this question is not asked. EduSystem 30 then asks: DO YOU WANT BATCH CAPABILITIES? If. the system is to process card programs, respond Y. If it is only to be used as an interactive system, respond N. If batch capability is selected, the system then asks: HOW MANY BLOCKS FOR LOG? The log is a stored record of system usage which records the name of all programs submitted for execution. The larger it is:. the more program runs may be recorded before the log becomes full and must be printed. The log may be from 0 (no log at all) to 22 blocks of disk storage. Each block will hold the record of approximately 10 to 20 programs. Respond by typing the number of blocks to be reserved for the batch log, then typing the RETURN key. The system then asks: BATCH INPUT ON PUNCHED CARDS? Respond N if the batch input is to be coded with the EduSystem 30 template on the standard 39-column EduSystem 30 mark-sense cards. Respond Y if input will be on cards punche4 using a keypunch. The system then asks: MAXIMUM DATA COLUMNS PER CARD? 7-41 The maximum allowable response to this question depends upon the type of reader used: the punched-card reader has a maximum of 80 columns per card; the mark-sense reader maximum is 40 columns per card. See Using Optional Hardware for more information on preparing cards using a keypunch. Next, the system asks: DO YOU WANT PRIVILEGED COMMAND CAPABILITY? The privileged command capability prevents unauthorized users from executing certain critical system commands. To establish this protection, type Y. The system then prints: . TYPE INITIAL PASSWORD The password is a special code which must be known in order to use privileged commands. It is up to six characters long. Respond by typing the desired system password. If it is less than six characters, type the RETURN key after the last letter of the password. To protect their secrecy, the characters typed are not printed. If no privileged capability is desired, the response to the original question is N. (A standard sys~em keeps the privileged capability and sets the initial password to BASIC.) Finally, the system asks if a high-speed paper tape punch and/or line printer are part of the system by printing: DO THE FOLLOWING EXIST: HIGH-SPEED PUNCH? LPc;,8 PRINTER? The response to each question must be Y if the device exists, N if it does not. A standard system assumes that neither device exists. (See Using Optional Hardware for a discussion of how these devices are used.) When all questions have been answered, the system asks: IS THE ABOVE CORRECT? If all questions were answered properly, type Y. The system then loads the rest of the EduSystem 30 papet tape. If any of the re- 7-42 sponses were incorrect, type N; the complete set of questions is repeated. When the entire tape has been read, EduSystem 30 gives the user a chance to load additional DEC-supplied system update tapes by asking: MORE INPUT? If no DEC-supplied ,update tapes exist, respond Nand EduSystem 30 is completely loaded. If update tapes do exist, load the first one into the tape reader and type Y to obtain loading. Finally, when all input has been read, EduSystem 30 indicates that it is ready to process BASIC programs by printing: READY At this time, turn the key lock to PANEL LOCK and remove the key to prevent the system from being accidentally disturbed. DIAGNOSTIC MESSAGES DURING SYSTEM BUILD The following error messages are printed when errors are detected during the building of EduSystem 30. TAPE READY? This message is printed whenever the system is waiting for the paper tape reader to be loaded. It may appear by itself, usually due to a tape tear or reader jam, or it may appear as. the last line of another diagnostic message. ACTION: 1. The portion of the paper tape which is read after the system building dialog has distinct blocks of information about two and one-half tape fanfolds long. The start of such a block is indicated by nine blank tape frames followed by a frame with all positions punched. Back up the tape several fanfolds to the beginning of a previously read block. Position the tape such that the blanks at the beginning of the block are over the read . station. 2. Type Y on the interactive terminal. 7-43 N 1-4 Figure 7-8. System Building Dialog 7-44 o l-------' Figure 7-8 (Cont.). System Building Dialog 7-45 BEGINS READING TAPE AND BUILDS SYSTEM YES READS IN ·ADDITIONAL INPUT WHEN TAPE IS READ, u TYPES " READY Figure 7-8 (Cont.). System Building Dialog 7-46 BAD PLACE TO START TAPE TAPE READY? This message means that after a previous message the user did not correctly position the tape to the beginning of a data block. (See discussion under TAPE READY? message.) ACTION: 1. Correctly position the tape. 2. Type Y on the interactive terminal. CHECKSUM ERROR TAPE READY? A checksum error occurred while the most recent data block was being used. ACTION: 1. Back up the tape to the beginning of the block. 2. Type Y to reread the data. SYSTEM DEVICE liD ERROR If this message occurs before the dialog has been completed, the dialog automatically restarts. If an I/O error occurs after the dialog is completed,. the TAPE READY message is printed. ACTION: 1. Make sure that the system device is on-line and writt!enabled and that the unit number is set correctly. 2. Respond appropriately to the question which follows the message. Turning Off the System If power failure detection is available on the EduSystem 30, simply turn the console key lock to OFF. Otherwise, to shut the system down, overnight or for any reason, ensure that the system is inactive by: 7-47 1. Typing CTRL/C to stop any program that is running. 2. Turning the key lock to POWER, and pressing and raising the HALT switch. 3. Turning the key lock to OFF. NOTE Turning off the computer does not turn off the disk unit. Disk power should never be turned off. Turning On the System If power failure detection is available on the EduSystem 30, simply turn the key lock to PANEL LOCK. Otherwise, perform the following procedures. 1. 2. 3. 4. 5. 6. Ensure~ that the hardware is properly initialized as explained previously. Turn the key lock to POWER. Set the.5R to 0000 and press EXTD ADDR LOAD. Set the SR to 7600 and press ADDR LOAD. Turn the Teletype to LINE. Turn the key lock to PANEL LOCK. EduSystem 30 is now ready to process BASIC programs. Restarting EduSystem 30 If EduSystem 30 has been loaded onto the system device but the computer memory has been used to run other programs (which do not write on the system device), then the following device-dependent programs may be used to start up the system. Instructions for these programs are given in octal numbers. If unfamiliar with the octal, or base 8, number system, refer to Introduction to Programming 1972. DF32 OR RF08 DISK With hardware bootstrap: 1. Press and raise the HALT switch. 2. Set the SR to 5350. 3. Press and raise the SW switch. Without hardware bootstrap: 1. Press and raise the HALT switch. 7-48 2. 3. 4. 5. 6. 7. 8. 9. Set the SR to 7750 and press ADDR LOAD. Set the SR to 7600 and lift DEP. Set the SR to 6603 and lift DEP. Set the SR to 6622 and lift DEP. Set the SR to 5352 and lift DEP. Set the SR to 5752 and lift DEP. Set the SR to 7750 and press ADDR LOAD. Press the CLEAR switch, then the CONT switch. TCOIDECTAPE With hardware bootstrap: 1. Press and raise the HALT switch. 2. Set the SR to 0600. 3. Press and raise the SW switch. Without hardware bootstrap: 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. Press and raise the HALT switch. Set the SR to 7742 and press ADDR LOAD. Set the SR to 1353 and lift DEP. Set the SR to 6766 and lift DEP. Set the SR to 6771 and lift DEP. Set the SR to 5344 and lift DEP. Set the SR to 1352 and lift DEP. Set the SR to 5343 and lift DEP. Set the SR to 7752 and press ADDR LOAD. Set the SR to 0220 and lift DEP. Set the SR to 0600 and lift DEP. Set the SR to 7577 and lift DEP, then lift DEP again. Set the SR to 7742 and press ADDR LOAD.: Press the CLEAR switch, then the CaNT switch. L TD8E DECTAPE With TD8E ROM: 1. Press and raise the HALT switch. 2. Set the SR to 7470. 3. Press, in order, the ADDR LOAD, EXTD ADDR LOAD, CLEAR, and CONT switches. Without TD8E ROM: 1. Press and raise the HALT switch. 7-49 2. 3. 4. S. Set the SR to 0011. Press the EXTD ADDR LOAD switch. Set the SR to 7470 and press ADDR LOAD. Press the CLEAR switch, then the CONT switch. Using Optional Hardware LP08 LINE PRINTER If the EduSystem 30 includes an LP08 line printer, perform the following procedures to produce output on the -line printer rather than at the Teletype. 1. Turn the LP08 power switch to ON. 2. Turn the ON-LINE/OFF-LINE switch to ON-LINE. 3 .. Type LPT and press RETURN. 4. When printing is complete, type TTY and press RETURN. 5. Turn the LP08 power switch to OFF. An LPT command causes all subsequent output associated with LIST, LOG, RUN, CATALOG, BATCH, or STACK commands to be printed on the LP08 printer. A TTY command returns control to the Teletype from the line printer. The user may temporarily interrupt printing by turning the ON-LINE/OFF-LINE switch to OFF-LINE; he may continue printing by turning it to ON-LINE. When batch processing terminates, the output device is automatically reset back to the Teletype. HIGH-SPEED PAPER TAPE READER/PUNCH If a high-speed punch is available, the PUNCH command may be used to punch the current program on paper tape .. PUNCH may be used with or without an argument. It is similar to LIST in that the entire program is punched if no argument is used and, if an argument is used, only those lines numbered greater than or equal to that argument are punched. Perform the following procedures to use the high-speed punch: 1. 2. 3. 4. 5. Turn the TTY control knob to LINE. Turn the high-speed punch ON. Press FEED to produce some leader tape. Type PUNCH and press RETURN. When punching is complete, press FEED to produce some trailer tape. 6. Turn the high-speed punch OFF. 7-50 Punching tp.ay be stopped at any time by typing CTRL/C. If a high-speed reader is available, the TAPE command may be used to load BASIC programs previously punched on tape. Perform the following procedures to use the high-speed reader: 1. 2. 3. 4. 5. Turn the high-speed reader ON. Turn the TTY control knob to LINE. Insert tape in the reader. Type TAPE and press RETURN. When the tape has read in, turn the high-speed reader OFF. 6. Type KEY; press RETURN. A KEY command returns control to the Teletype. PUNCHED CARD INPUT Programs loaded and run via the card reader may be prepared using a standard DEC 029 keypunch or be marked with a lead pencil arid the EduSystem 30 template. If punched cards are used, the system building dialog questions must be answered appropriately. Punch program statements on cards just as if they were being typed at the interactive terminal. The seven control commands (NEW, RUN, LIST, OLD, KEY, MSG, and aPR)· available in batch mode are used by punching the command name starting in column 1. Information normally marked starting in column 6 must begin in column 5. The number of data columns on each card which is read by , EduSystem 30 is specified in the system building dialog. Thus the system can be made to ignore the latter portion of a batch input card. These ignored columns then may be used to hold sequence numbers or other information which will not be processed by EduSystem 30. Programs .punched with a keypunch may be read by either the regular DEC punched card reader (CR8 series) or the DEC mark-sense reader (CM8 series). With the punched card reader, standard 80-column cards may contain up to 80 columns of data. Cards to be read by the mark-sense reader must be· punched on cards which have the special marks along the bottom edge of the card and which conform to other rigid specifications. The mark-sense cards may be made to contain up to forty . 7-51 columns of data per card. The simplest, and recommended, method for using 'punched mark-sense cards involves using the standard EduSystem 30, cards. Ignore the information printed on the card. Prepare a keypunch' drum card· which will cause the punches to occur only in keypunch columns 1, 3, 7, 11, 13, ... , that is in all the odd numbered columns except column 9. All other columns should be automatically skipped. The user may now punch EduSystem 30 cards as if they were normal cards. The drum card will correctly position the punches. Note that the BASlC commands must be punched in their entirety. CALCULATING AVAILABLE STORAGE The number of storage blocks initially available on the syst€m device is calculated according to the following rules: Availabie Blocks 1. System' Device DF32 Disk DECtape RF08 Disk LINCtape 131 1348 1922 1348 2. If batch capabilities are included in the system, subtract 10 blocks from the basic number of blocks. If the number of blocks specified for use by the batch log is greater than one, subtract one less than that number from the current total. 3. If the system device is a disk and the hardware configuration includes more than a single disk surface, add the appropriate number of blocks for each additional disk surface. System Device Available Blocks DS32, RS08 255 2046 7-52 < 8 edusysten.... 40 INTRODUCTION EduSystem 40 offers a combination of the language capabilities of EduSystem 20 and EduSystem 30 by allowing the user to nm either system, but not both simultaneously. The purchaser of an EduSystem 40 is obtaining an extremely versatile system-one which can accommodate not only a large and varied number of users, but a tremendous number of program runs per day. Working with EduSystem 20, the beginning student, who is unfamiliar with a computer system and who may be learning a computer language for the first time, can develop his skills while as many as seven other students may also be using the system at equal or more advanced levels of learning. If the problem is complex or the student desires the use of commands not present in EduSystem 20, then EduSystem 30 is available as a stand-alone system. In addition, using the batch capabilities of EduSystem 30 permits extremely large numbers of user programs on cards to be executed every day. With the varied services provided by EduSystem 30 and, alter,.. nately, the time-sharing capabilities of EduSystem 20, the user obtains a complete system which can be put to use continuously for maximum produetivity. System Components EduSystem 40 is composed of a PDP-8/E computer with 8192 words of core memory (12,288 words of core memory are recommended if the syste:m includes 5 or more terminals); automatic loader (MI8-EF or MI8-EO hardware bootstrap, MI8-EC for TD8-E DECtape with ROM'; 32,768 word DECdisk (DF32 or RF08) or DECtape; optical mark sense card reader; and as many as eight Teletype termipals with low-speed paper tape reader and punch units. Each EduSystem 40 contains two BASIC Language processors (EduSystem 40-20 and EduSystem 40-30) and a library of "sample programs, textbooks and curriculum guides. 8-1 Optional components include a high-speed line printer, high-speed paper tape reader and punch, and additional core memory to increase program SIZe. System Expansion By adding 4096 words of core memory; a high-speed paper tape reader; 262,000 word DECdisk and control; additional computer terminals and their associated interfacing; and an EduSystem 50 software set, EduSystem 40 may be expanded to EduSystem 50. (Chapter 9 provides information concerning the EduSystem 50 TSS-8 time-sharing system.) If the system includes DECtape, the PDP-8 Operating System (OS/8) m!ly be run. This system contains a keyboard monitor, machine language. assemblers, debugging tools, and FORTRAN, and is described in Chapter 9 of Introduction To Programming 1972. . BASIC LANGUAGE CAPABILITIES Advantages and Applications EduSystem 40 provides the user with two BASIC systemsEduSystem 40-20 and EduSystem 40-30. Both systems are fairly compatible in language capabilities-they share a large number of common statements and commands. However, there are certain features peculiar to each EduSystem which may make it advantageous for the user to choose one over the other. A short summary' of these features is included here. (The user is directed to Chapters 5 and 7 for complete details concerning the use of the language capabilities of EduSystems 20 and 30). EDUSYSTEM 20 EduSystem 20 provides an immediate mode for fast and accurate calculations of expressions and equations. Statements used in this mode are not stored in memory. There are certain commands available in EduSystem 20 which are either not pres~nt in EduSystem 30 or are used in a different way. The more important of these are EDIT, INPUT. DIM. IF THEN, ON GOTO, and ON GOSUB. , The EDIT command speeds the editing procedure by eliminating the need to retype complete lines. The user simply searches for the character(s) he wishes to change and, using the options available, makes the necessary corrections. 8-2 The INPUT statement allows a number or numbers to be entered from the Teletype as values for variables. Using EduSystem 20, the user response may be a value, or a mathematical expression which may contain arithmetic operations and a ~ASIC function (see Tables 8-4 and 8-5). The DIM statement is not necessary in EduSystem 20 as the system sets limits on subscript size (single subscript: 0-2047; double subscript: 0-63 for each subscript), and defines all variables as they occur. . The IF THEN statement, in addition to conditionally altering the order of execution by effecting transfer of control, may include another BASIC statement, thus causing an operation to be performed without changing the order of execution. The ON GOTO and ON GOSUB statements allow conditional transfer to another statement or subroutine depending upon the integer value of the formula following ON. After execution of a subroutine, control returns to the statement following the ON GOSUB statement. It has already been mentioned that EduSystem 20 is a multiuser BASIC, and as far as the school system is concerned, this is probably its greatest asset. As many as eight users may be working simultaneously on one computer. Terminals may be situated in different rooms, even different buildings, to serve a greater number of users and applications. EDUSYSTEM 30 EduSystem 30 is a true batch system allowing either interactive or "hands-off" batch operation. Specially formatted mark cards provide a means by which students can easBy code programs and submit a deck for later execution. An operator can gather all individual program decks into one large deck, to be run consecutively and automatically by the system. Commands are available which allow operator intervention during runs. EduSystem 30 makes available to the user a single mass storage device-DECdisk (or DECtape). The user can store data files or sections of very long programs which will later be chained together. He can also save programs which may be used later or which may be called more than once. Several special commands called Privilege Control Commands are associated with the mass storage device. Among them are commands which will save and 8-3 delete programs, determine the amount of available core, list programs in storage, arid list the number of blocks in use. EduSystem 30 includes a CHAIN command which makes progr~m chaining possible and allows th~ running of' programs of any length. Each section of the entire program must be 6000 characters or less and is stored on the mass storage device. Data files may be used in a similiar manner by allowing temporary storage of data on the mass· storage device. Using WRITE statements, data may be written onto files; data stored in these files is called into a program via READ statements. EduSystem 30 includes a character-handling feature which allows words or characters to be entered into a BASIC program in response to questions. The special .characters # and $ are used to facilitate this procedure. Characters are stored as their respective numeric codes and. therefore may be used and manipulated with standard BASIC commands. The ASCII codes for these characters may be found in Appendix B. For detailed· information concerning the features mentioned in this section, and all other available language capabilities, the user should refer to Chapter 5 when using EduSystem 20 and Chapter 7 when using EduSystem 30. Language Summaries and Error Message Summaries follow. LANGUAGE SUMMARIES BASIC Statements and Commands Table 8-1 lists the statements available in EduSystems 20 and 30; Table 8-2 summarizes the editing and control commands. These tables are abbreviated forms of those contained in Chapters 5 and 7. Table 8·1. Statement Statements Description & Format EduSystem 20 30 Input! Output DATA n1' n:! •.. nn Nllmbers n1 through nn equal variables in a READ Get VI through Vn input from TrY 8-4 x x x x Table 8·1. (Cont.) Statement & Format RESTORE WRITE n 1 , n2' .. nn Statements Description Print values of specified text, variables or expressions; also used for format-control Read variables VI through Vn from DATA list Reset DATA pointer to beginning value Record DATA nl through nn on mass storage file EduSyste:m 20 30 x x x x x x x Transfer of Control GOTOn Transfer control to line number n If relatio'nship r between el and e2 is true, transfer control to line number n Same as IF GO TO; under EduSystem 20 n may be a statement Conditionally change order of program execution according to evaluation of formula el (if integer of el =1 transfer control to nl; if integer of e 1 =2, transfer to n:h etc.) Conditionally change order of program execution according to evaluation of formula el (if integer of el = 1 transfer control t6 subroutine n t ; if integer of el =2 transfer to subroutine n:!; if integer of el =3 transfer to subroutine n;) x DIM v(nl), v(n2' n;:) Define subscripted variables x x FOR v=el TO e;! STEP e:\ Set up program loop; define v values beginning at e 1 to e2 incremented by ea Termipate program loop; incre. ment valu~ of v until v>e;! (in FOR statement) IF el r e;! GO TO n ~f el r e;! THEN n ON el GO TO n 1 , ON el GOSUB n 1 , n;!. n:\ x x x x x x Loops and Subscripts NEXT v 8-5 x x x x .. Table 8.1 (Cont.) Statement & Format EduSystem 20 30 Subroutines GOSUB n RETURN STOP Others CHAIN on' $ DEF FNA (x) =f(x) DEF FNA (x, y)= f(x, y) END LETv=f -RANDOMIZE REM text NOLINE CAT CTRL/C DELn n DELn,m EDln c KEY Description Enter subroutine at line . number n Returnfrom subroutine to statement following GOSUB Transfer control to END statement x x Link to next section of a program which is stored' within the system as file n Define a function x x x End of a program Assign value of formula f to v Randomizes random number routine Insert a remark or comment Suppress printing of line numbers in which program logic errors are found Table 8-2. Command & Format Statements x x x x x x x x x x x x x Edit and Control Commands Description List names of programs in storage. area Stop program execution: return to edit phase Delete line n Delete line n Delete lines n through m inclusive Search line n for character c typed following carriage return Return to keyboard mode after TAPE (EduSystem 30-HSR only) 8-6 EduSystem 20 30 x x x x x x x x x x Table 8-2. (Cont.) Command Edit and Control Commands Description & Format LIST LISTn LISTn LISTn,m LISTNH LISTNH n NEW OLD RUN RUNNH SCR BYE TAPE BATCH "'BATCHn ECHO LPT LENGTH NAME PUNCH PUNCHn PTP PTR RESEQUENCE TTY EduSystem 20 30 List entire program in core (If lowspeed punch is on, EduSystem 20 will cause a tape to be punched) List program starting at line n List line n only List lines n through m inclusive List program; no header (If lowspeed punch is on, program will be punched on paper tape) List program beginning at line n; no header Clear core; request program name Clear core; bring program to core from storage area Compile and run program in core Same as RUN; no header Erase current program from core Same as SCR Read paper tape from low-speed reader; suppress printing on TTY (also used with high-speed reader under EduSystem 30) Commence batch processing Same as BATCH; limits runs to n per program Switch from typeout to non-typeout mode or vice versa when using low-speed reader Print output on lineprinter, if available Request number of blocks to store current program Same as NEW but does not delete existing program Punch entire program on paper tape Punch program starting at line n Punch a program out on the high-speed paper tape punch. Read program from high-speed reader Renumber program lines Print output on TTY 8-7 x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x Table 8-2. (Cont.) Edit and Control Commands Description Command & Format PRIVILEGE (password) *HEADER (header) *LOG *MAXn * PASSWORD (new· password) *SAVE *STACK *STACK n *UNSAVE >I< Enable use of privileged commands Insert password, no echo Change header; type new header (max. 12 characters) for next batch run Print system10g Set instruction limit n times 200 per program for next batch run Change password Type new password, no echo Save program in storage area . Start unattended batch operation Same as STACK; limit runs per program Delete program from storage area EduSystem 20 30 x x x x x x x x x Privileged Mode Command Batch Control Cards The control cards in Table 8-3 are used when running an Edu. System 30 batch card deck. The user must mark the appropriate box in the upper left hand corner of the EduSystem 30 mark card. Each control card is explained in detail in Chapter 7. Table 8-3. Control Card Batch Control Cards. .. Description NEW Indicates a new program; contains the new program name; must be first card in the deck-any cards appearing before· this card are ignored. OLD Indicates an old program; contains the name of the program to be caned; must be first card in the deck-any cards appearing before this card are ignored. MSG Columns 6-39 contain a message which is printed as part of program output. OPR Message marked in columns 6-39; when encountered in program execution rings bell to alert operator and prints message on TTY. ~-8 Table 8··3. (Cont.) Control Card Batch Control Cards Description KEY Temporarily halts the batch operation and turns control over to the console terminal. LIST Instructs computer to print a listing of the program on the TTY. Should be placed at the end of the card deck before the RUN card. RUN Normally the last card in the deck; instructs the computer to begin execution. BASIC Functions and Arithmetic Operations Table 8-4 lists the functions available in EduSystem 20 and 30. Table 8-5 is true for all EduSystems. Table 8-4. Functions Function Description SQR(x) SIN(x) COS(x) TAN(x) ATN(x) Square root of x (Yx) Sine of x (x in radians) Cosine of x (x in radians) Tangent of x (x in radians) Arctangent of x (x in radians) (result in radians) eX (e=2.712818) Natural log of x (logex) Absolute value of x (Ixl) Greatest integer of x Sign of x ( + 1 if positive, -1 if negative, o if zero) Random number between 0 and 1 Truncates decimal portion of x Controls printing head position on TTY. Converts character code to character. Used only with PRINT command. EXP(x) LOG(x) ABS(x) INT(x) SGN(x) RND(x) FIX(x) TAB(x) CHR$(x) EduSystem 20 30 x x x x x x x x x x X X x x x x x x x x x x x x x I 8-9 Table8~5. Arithmetic Operations Symbols Meaning t exponentiation multiplication division addition subtraction '" + / 1. 2. 3. 4. Order of Execution parenthetical expressions exponentiation multiplicatio~ and division addition and subtraction ERROR MESSAGE SUMMARIES EduSystem 20 EduSystem 20 checks all commands be(ore execution. If an error is found, it prints one of the error messages in Table 8-6 and the number of the line in which the error occurred. Table 8·6. EduSystem 20 Error Messages Message Explanation WHAT? ERROR ERROR ERROR ERROR ERROR ERROR ERROR 1 2 3 4 5 6 7 ERROR ERROR 8 9 ERROR ERROR ERROR ERROR ERROR 10 11 12 13 14 Command not understood. It does not begin with a line number and is not a valid system command. Log of negative or zero number was requested. Square root of negative number was requested. Division by zero was requested. Overflow--exponent greater than approximately +38. Underflow---exponent less than approximately -38. Line too long or program too big. Characters are being typed too fast; use TAPE command for reading paper tapes. System overload caused character to be lost. Program too complex or too many variables. (GOSUB, FOR, or user-defined function calls are too deeply nested.) . Missing or illegal operand or double operators. Missing operator before a left parenthesis. Missing or illegal number. Too many digits in number. No DEF for function call. 8-10 Table 8.6. (Cont.) EduSystem 20 Error Messages Message Explanation ERROR 15. Missing or mismatched parentheses or illegal dummy variable in DEF. Wrong number of arguments in DEF call. Illegal character in DEF expression. Missing or illegal variable. Single and double subscripted variables with the same: name. Subscript out. of range. No left parenthesis in function. Illegal user-defined function-not FN followed by a letter and a left parenthesis. Mismatched parentheses or missing operator after right parenthesis. Syntax error in GOTO. Syntax error in RESTORE. Syntax error in GOSUB. Syntax error in ON. Index out of range in ON. Syntax error in RETURN. RETURN without GOSUB. Missing left parenthesis in TAB function. Syntax error in PRINT. An unavailable device was requested by the user-the device is either not present in the system, or in use. Missing or illegal line number. Attempt to GOTO or GOSUB to a nonexistent line. Missing or illegal relation in IF. Syntax error in IF. Missing equal sign or' improper variable left of the equal sign in LET or FOR. Subscripted index in FOR. Syntax error in FOR. FOR without NEXT. Syntax error in LET. Syntax error in NEXT. NEXT without FOR. Too much data typed or illegal character in DATA or the data typed in. Illegal character or function in INPUT or READ. Out of data. Unrecognized command during execution. ERROR ERROR ERROR ERROR 16 17 18 19 ERROR 20 ERROR 21 ERROR 22 ERROR 23 ERROR ERROR ERROR ERROR ERROR ERROR ERROR ERROR ERROR ERROR 24 25 26 27 28 29 30 31 32 33 ERROR ERROR ERROR ERROR ERROR 34 35 36 37 38 ERROR ERROR ERROR ERROR ERROR ERROR ERROR 39 40 41 42 43 44 45 ERROR 46 ERROR 47 ERROR 48 8-11 If . f s the 1U orm · 0 ERRORS . EduSystem 3 DE PROGRAM LOADING d b fore execution. BATCH MO h cks all cornman s e· EduSystem 30 also c e d 'EduSystem 30 cute a cornman, 7 it is unable to exe es in Table 8- . user by printing one of the error messag TableS-'. Batch Mode Program Loading Errors Message Explanation BAD CHARACTER One or more characters on a card could not be understood. The character % replaces any unreadable character. The information on the card is processed if possible. This error does not cause any subsequent RUN commands to be ignored. BAD CHARACTERLINE NOT USED Same as BAD CHARACTER message except that the information on the card is ignored. This error does cause any subsequent RUN commands to be ignored. WHAT? Line does not make sense to the system. It does not begin with a line number and is not a valid system command. NO ROOM The program is too big to be loaded, i.e. it is greater than 5000 characters. Larger programs should be run in interactive mode. FILE NOT SAVED The program named on an OLD control card is not available in the system storage area. FILE TOO BIG FOR BATCH MODE The program named on an OLD card is too big· to be run in batch mode. It must be run interactively. INTERACTIVE MODE PROGRAM LOADING ERRORS As each line is typed, a check is made for program loading errors. If an error is found, one of the messages in Table 8-8 is printed immediately after the line containing the error. 8-12 Table ,8-8. Interactive Mode Program Loading Errors Message Explanation WHAT? Line does not make sense to the system. It does not begin with a line number and is not a valid system command. LINE NO. TOO BIG The line number of a line or the argumem of a system command is greater than 4095 . LINE TOO LONG . Line just entered is longer than 80 char·· acters. NO ROOM There is no room to store the line just entered. FILE NOT SAVED The program named as the operand of an OLD command was not previously saved on the system device. NO SPACE There is not enough space to SAVE the current program (DECtape Systems). Bell If an invalid character is entered, the Tele.. type bell rings and the character is ignored. II 0 ERROR An input or output error occurred on the DECtape unit. Be sure that the unit is on· line, write-enabled, and the unit number is set correctly. Retry whatever was interrupted by the error. If the problem persists, there is a hardware problem (DECtape Systems). INVALID PASSWORD The password typed after a PRIVILEGE command is not the system password. Priv·· ileged mode is not entered. CODING ERRORS After the RUN or RUNNH command, but before execution, EduSystem 30 checks for mistakes in the BASIC program coding. ,If an error is found, one of the following messages and the appropriate line number is printed. 8-13 Table '8-9. ,Coding Errors Message Explanation CH There is an illegal character in the line. EN Program does not have an END statement as the last line in the program. FN - Not enough NEXT statements in the program. There must be a NEXT statement for each FOR statement in the program. Fa FOR and NEXT statements do not match. There is a NEXT statement in the program whose variable is not the same as the variable in the corresponding FOR statement. LI , Line contains an improperly written decimal number or constant. It may, for example, have two decimal points or have an alphabetic character in it. M1 M2 The program as a whole is too big to be run by the systern. Making the program smaller, reducing the size of subscripted variables, or using the, NOLINE command may help. NE Program has too many (more than 8) nested FOR-NEXT loops. ' PC Line contains an improperly used parenthesis. Generally, the problem is an expression which does riot have an equal number of left and right parentheses. RO Statement contains an invalid relational operator =, >, <=, >=). Relational operators may only be used in IF statements. SI S2 Statement as a whole is not, properly written and, as a result, does not conform to proper BASIC syntax. For example, a semicolon is allowed in a PRINT statement but not in a READ or INPUT statement. ST Statement cbmmand word is not one of the BASIC statement types. TB The program is too big to be run. Cause is usually an extremely large number of PRINT statements. TO Program is either too big or too complex to be run. The total number of variables, constants, functions, and line numbers should be reduced, if possible. «, 8-14 Table 8-9. (Cont.) Coding Errors Message Explanation UL A GOSUB, GOTO, or IF statement contains a line number which does not exist. UQ A quotation mark indicating the beginning of a string of text does not have a corresponding quotation mark at the: end of the text string. PROGRAM LOGIC ERRORS If a program logic error occurs, EduSystem 20 prints one of the: messages in Table 8-10 after execution. Table 8·10. Program Logic Errors Message Explanation CH A CHAIN statement tried to chain to a program which was not available in the DECtape storage area. co Program ran too long and was automatically stopped by the system. DA The program ran out of data. It attempted to do a READ after all data had been read. DO The program attempted to divide by zero. Instead of dividing by zero, BASIC divides by the smallest possible number, giving a result of about 10 500 • This error does not cause the-program to stop. FN An expression contains a function which was not defined in aDEF statement. GS The program is too complex to be executed. The problem is generally that too many subroutines have themselves executed GOSUB instructions. LG Program attempted to take the logarithm of a negative;: number or zero. RE A RETURN statement was used outside a subroutim~ or a subroutine was entered by a GOTO instead of a GOSUB. SP Same as OS. SQ Program attempted to take the square root of a negative number. BASIC automatically takes the square root of the absolute value of the number instead. This error does not cause the program to stop. 8-15 Table 8-10. (Cont.) Program Logic Errors Message Explanation SS Program used a sUbscript which was too big for the variable. The maximum size of a subscript is specified in a DIM statement. WR There is no more room to write data. The program attempted to execute a WRITE statement when the data list was full. (Note that if this error occurs, the program text will no longer be intact. 'A NEW, OLD, or SCRATCH command must be used to clear the program area.) LOADING AND OPERATING INSTRUCTIONS The software for EduSystem 40 is distributed on five paper tapes -.EduSystem 40-20 and EduSystem 40-30 for Disk Systems, and individual EduSystem 20 and EduSystem 30 tapes for DECtape Systems. The us'er with a DECtape System should refer to Chapters 5 and 7 for loading and oper'lting instructions as the following instructions refer only to the standard Disk System. The EduSystem 40-20 and 40-30 tapes are used to build the EduSystem 40 system on DECdisk (either DF32 or RF08) when the system is installed. The building procedure is outlined below. Initializing the DECdisk Initialize the DECdisk by ensuring thai the disk unit is turned on ~nd that all disk protect switches are in the off position. Building EduSystem 40 on Disk The system tapes may be loaded into memory by use of either the RIM Loader (refer to Appendix A) or with the automatic loader (hardware bootstrap MI8-EF or MI8-EG). 1. Turn the key Jock on the computer console to POWER. 2. Turn the Teletype to LINE. 3. Place the EduSystem 40-20 tape in the appropriate reader (high or low-speed) with the leader code (ASCII 200) over the read head. 4. If the system contains a hardware bootstrap, set the SR == 5356; press and raise the HALT switch; press and raise the SW switch. 8-16 5. If using the RIM loader, set the SR = 7756: press and raise ADDR LOAD, CLEAR and CONT. 6. Turn the reader on. The tape should begin to move (if it does not, be sure the correct tape is being used and repeat the above procedure). When the tape has been read completely, the system prints the following message on the Teletype: IS SYSTEM DEVICE A DF32 DISK? The user should respond Y or N. If the response is N, the system asks: IS SYSTEM DEVICE AN RF08 DISK? The answer here should be Y; otherwise the system will repeat both questions until the answer to one of them is Y. When the correct system device has been specified, the system prints: EDUSYSTEM 20 BASIC NUMBER OF USERSCl TO 8)? At this point halt the computer by pressing and raising the HALT switch. (If the above messages are not printed, the above procedure should be repeated before continuing the building process.) 7. Place the EduSystem 40-30 tape in the appropriate reader. 8. If the system contains a hardware bootstrap, set the SR = 5356; press and raise the SW switch. 0000; press EXTD ADDR 9. Otherwise, set the SR LOAD; then set the SR 7756; press ADDR LOAD, CLEAR and CONT. = = Approximately one-third of the tape should be read before the standard EduSystem 30 dialogue begins. The system will print: STANDARD SYSTEM? Build EduSystem 30 as detailed in Chapter 7 and summarized below. The user is at point A on. the flowchart in Figure 8-1 and should continue with the dialogue presented in the flowchart. (If Y is typed as a response to this question, the system assumes the responses contained in brackets on the flowchart.) 8-17 N HOW MANY DISKS ? (USER RESPONDS FROM 1-4) [1] N HOW MANY BLOCKS FOR LOG ? (USER RESPONDS FRO~~-22) [N] MAXIMUM DATA COLUMNS PER CARD '? (USER RESPONDS FROM 0-80) Figure 8-1. Building EduSystem 40 8-18 TYPE INITIAL PASSWORD (USER TYPES A WORD OF 6 OR LESS CHARACTERS) (BASIC) TAPE READS Figure 8-1. (Cont.) Building EduSystem 40 8-19 When EduSystcm 40 prints READY on the Teletype, the disk is completely built and ready to bc used, with EduSystem 30 runmng. Starting EduSystem 40 Once EduSystem 40 has been bullt on the disk, it can be stopped and restarted by performing the following operations. 1. Press and raise the HALT switch. 2. A. If the system does not have a hardware bootstrap, the following instructions must be manually loaded: ~ Set SR=7750 and press ADDR LOAD. Set SR=7600 and lift DEP. Set SR=6603 and lift DEP. Set SR=6622 and lift DEP. SetSR=5352 and lift DEP. Set SR=5752 and lift DEP. Set SR=7750 and press ADDR LOAD, CLEAR and CONT. B. If the system contains a hardware bootstrap set the SR= 5350 and press and raise the SW switch. The system should respond by printing: EDUSYSTEM 40-SELECT (1=20,2=30): If thc system does not respond in this manner, repeat the starting' instructions; if the system does respond as it should, the user is at point A on the flowchart in Figure 8-2 and should continue with the dialogue in that flowchart. , 8-20 s) EDUSYSTEM 40 SELECT{1-20,2-3O)' ? NU~ER Of USERS (1-8) USER RESPONDS RO~~ ----] TELIiTYPE < 17> <"17> < 1 7> <12> 1• BLOCKS 1 • BLOCKS 1 • BLOCKS 1 • BLOCKS ·2. BLOCKS I .BIN .TMP .TMP .BAS .FCL < 17> < 17> <17> <17> <12> 1• 1• 1• 1• 2. BLOCKS BLOCKS BLOCKS BLOCKS BLOCKS :S DELETED DELETED S JOB I. USER (3,13) LOGGED OFF K00 AT 10:46:07 ON DELETED 3 FILES ( 3. DISK BLOCKS> SAVED 2 FILES ( 3. DISK BLOCKS) RUNTIME 00:00:25 ( 2. CPU UNITS) ELAPSED TIME 00:06:12 9 JUN 70 In the previous example, the user typed a question mark to check the LOGOUT options. When LOGOUT completed the printed explanation, it printed CONFIRM: and waited for a user reply. In this case, the user requested a listing of his files. LOGOUT followed this listing with a second CONFIRM: to which the user replied I. When using the 1 option, the user is advised not to type his reply to individual entries until printing stops. DELETED is printed automatically by the system to show that the temporary files are deleted without user intervention. The user saved binary file FIE and the FOCAL file PROG. The BASIC file INTER was deleted by typing the RETURN key. 9-9 Table 9-1. ,LOGOUT Options Option :S Function Save all nontemporary files. A temporary file is one of the following: BASOnn BASlnn TEMPnn where nn is the console number at which the user is logged into the system. A temporary file is created by a System Library Program and listed in CATALOG listings. A temporary file is also considered to be any file with a .TMP extension. If no option is specified in the LOGOUT command, :S is the default. :K Delete all unprotected files from disk. :L List the user's file dire~tory. After listing the files, the system prints CONFIRM: and the user replies with one of the options. :1 Allow the user to individually decide which files to save or delete. Temporary files are deleted automatically. :? Print a listing of the available options and their functions. An optional method of logging out of the system is to type K in response to the Monitor dot or K followed by a colon and an option designation. For example: .K JOB 01 1 USER (1234,ABCD) LOGGED OFF K13 AT 14:28:02 ON 02-28-73 SAVED 3 FILES ( .4. DISK BLOCKS) RUNTIME 00:00:07 ( 1. CPU UNITS) ELAPSED TIME 00:13:57 System Library Program Control Once logged into the system, the user can call any EduSystem 50 System Library Program.' To call a library program, the user 9-10 types the command R (meaning run) followed by one or more spaces and the program name. For example: .R BASIC NEW OR OLD-- The Monitor fetches the BASIC language processor from the System Library and starts it. BASIC begins its dialog by asking if the user wishes to work on a new program or retrieve an old one from disk storage. Notice that once BASIC begins, the console is no longer in ~.1onitor mode. Dots are no longer printed at the margin. An input is now processed by the BASIC language processor. If the user types a program name which cannot be found in the System Li,Qrary, the Monitor responds with an error message and returns the console to the Monitor mode, as follows: .R BASICK FILE NOT FOUND? • The exact contents ofa System Library may vary from installation to installation. The System Manager may choose to make any number of programs available to a11 users. Communication with Other Users Although EduSystem 50 gives each system user the impression that she is the only user of the system, it is actually supporting many users ata time. Often it is useful to communicate with another user or with the system operator; this is done with the TALK command. The TALK command requests the Monitor to print a message on another system terminal. For example, a user at terminal 7 can ask the system operator to turn on the high-speed punch by typing the following command (the initial dot is printed by the Monitor) : .TALK e PLEASE TURN ON THE HIGH-SPEED PUNCH. The above command causes the following to be printed at console O. . **Ke7** PLEASE TUI=iN ON THE HIGH-SPEED PUNCH. 9-11 **K07** indicates that terminal 7 sent the message. Any terminal can initiate a message to any other terminal. However, if the destination terminal is printing at that time, the message will not be sent. The initiating terminal would, in this case, receive the message BUSY as a response. System Status Reports The command SYSTAT initiates a printout of the full status of EduSystem 50, how many users are on-line, what they are doing, etc. The command SYSTAT is equivalent to typing R SYSTAT. The format of the status report is described in the section on Utility Programs. The user can obtain information on the amount of computer time used by him, the amount used by another user, or obtain the time of day with the TIME command. The TIME command can be issued in one of the following three forms: TIME . TIME 0 TIMEn Returns the elapsed processor time of the user issuing the TIME command since he logged into the system. Returns the time of day . Returns the amount of processor time used by job n since logging into the system. For example: .TIME 00100100 .TIME 0 17121106 .TIME UJ 00100134 Resource Sharing All system users, when logged into the system, have access to the System Library, disk storage, a virtual 4K PDP-8, and the EduSystem 50 Monitor. The Monitor handles disk resource requests automatically. The Monitor also maintains a pool of available devices which are assigned to users upon request on a first-come, first-served basis. Devices such as the high-speed paper9-12 tape reader cannot, by their very nature, be assigned to severa:l programs simultaneously. Therefore, the Monitor grants individuall users exclusive access to these devices when needed. Deviees such as the system disk, and sometimes DECtapes, are not assigned since they can be used by more than one user simultaneously. All systems include a high-speed paper-tape reader in the pool of available devices. Many systems also include a high-speed paper·· tape punch, high-speed line printer, and one or more DECtapes" These assignable devices are normally used with the System Library Programs PIP and COpy to store programs or data on paper tape or as DECtape flies. When a device is assignable (present on the system) and avail·· able (not being used), the ASSIGN command may be used to reserve the desired unit or units for exclusive use by the console issuing the command. The valid ASSIGN commands are for·· matted as shown below: ASSIGN R ASSIGN P ASSIGN 0 ASSIGN L Assign the high-speed paper-tape reader. Assign the high-speed paper-tape punch and line printer. Assign a DECtape unit. Assign the line printer and high-speed punch. If other devices are assignable, the System Manager will inform the user of the appropriate device designator. The following is an example of using an invalid device designator: .ASS I GN X ILLEGAL REQUEST The Monitor ignores the request, responds with the appropriate message, and prints another dot. When a valid ASSIGN command is issued, the Monitor checks the availability of the device and re·sponds accordingly. For example: .A.SSIGN R R ASS I GNED .A.SSIGN P JOB 02 HAS P 9-13 When the system contains multiple units of a device, the user simply specifies the device; the Monitor assigns an available unit and responds with the unit number. For example: .ASSIGN D D 0 ASSIGNED If all DECtape units are busy, the Monitor prints the message shown below: .ASSIGN D DEVICE NOT AVAILABLE A specific unit can be requested by leaving a space between the device designator and the device number. For example: .ASSIGN D " D " ASSIGNED NOTE If the user assigns a device with a nonexis- tent device number, that device will not be assigned; an error message does not result because that device is not busy. An error message only results when the device is already assigned. The ASSIGN command assigns only one device at a time. Therefore, when multiple devices are to be assigned, each must be assigned separately. The following will not accomplish the desired assignments, either with or without the illegal commas . • ASSIGN R, D 2, 'D R ASSIGNED The Monitor accepted the first device designator and ignored the rest of the command. If device R is unavailable, the Monitor prints 9-14 the appropriate message. The following commands complete the desired assignments (assuming available devices) : .ASSIGN D 2 D 2 ASSIGNED .ASSIGN D 1 D 1 ASSI GNED • When the user has finished working with an assigned device, he should use the RELEASE command to terminate the assignment and allow other users access to the device. (When a user logs out of the system, any devices still assigned to him are automatically released.) A particular device is released when the user enters the RELEASE command, a space, and the device designator (and unit number if required), as shown below: .RELEASE R .RELEASE D 3 In the previous example, the high-speed reader and DECtape unit 3 are released. The Monitor prints a dot on the next line if the release is accomplished; otherwise, it prints a message. If, for example, a request is made to release a device which has not been assigned to the issuing console, the following happens: .RELEASE D 2 ILLEGA L REQUEST • The Monitor printed ILLEGAL REQUEST after it checked and found that the specified device was not assigned to the console issuing the command. NOTE All commands must be formatted properJy; ILLEGAL REQUEST is printed if the user fails to separate the device designator and unit number with a space. 9-15 When multiple device units were reserved by a user, each must be individually released. For example: .RELEASE D 1 .RELEASE D 2 .RELEASE R • The Monitor does not perform checking when releasing a device as it does when assigning a device. The user may have two device units (e.g., two DECtape units) assigned and Monitor would not know which to release; therefore, device numbers are necessary with a RELEASE command. When only one unit of a specific device (one high-speed reader or punch, etc.) is on the system, the device designator alone is sufficient. Error Messages An appropriate error message is printed whenever:, a Mon,itor command cannot be perf01med at the time it is requsted, a typing error is made, or the command is illegal (or nonexistent). Following. each error message, the Monitor ignores the command and prints another dot, after which the user can issue another command. Table 9-2 is a list of the Monitor error messages. Table 9-2. Monitor Error Messages Message Explanation S1 The System Interpreter does not understand the command. S 1 = command. LOGIN PLEASE? The user attempted to use a console which is not logged into the system. UNAUTHORIZED ACCOUNT Tile user attempted to log into the system with an invalid account number or password. ALREADY LOGGED IN? The user tried to log in on a console which is already in use. FULL The system is full. Another user cannot log in until one of the present users logs out. / 9-16 Table 9-2 (Cont.). Monitor Error Messages Message Explanation TYPE tBS FIRST The user attempted to use a sys·, tern command which cannot pres· ently be honored due to the status of the user's program. The message may appear even after the user has . typed tBS, since his program may continue until the 110 in progress. at the time of the halt is completed. The user should wait a few seconds. and then type his command a sec·, ond time. ILLEGAL REQUEST The user requested an illegal com·, mand. This error usually results when some parameter has been given an incorrect value or' th(;: request refers to a facility not owned by the user. BUSY The user attempted to talk to a console which is currently print·· jng or on which another user IS typing. SYSTEM LIBRARY PROGRAMS The System Library contains a comprehensive set of user pro· grams for a wide range of applications. Language processors, such as BASIC and FOCAL, allow the user to code and run programs. in interactive languages. FORTRAN-D compiles and executes programs written in FORTRAN language. A complete assembly language system allows programs to be written in PAL-D, assem·· bled, and run. Various utility programs perform special functions . The DEC-supplied System Library consists of the following pro·· grams. • BASIC-an easily learned interactive language originally developed at Dartmouth College. • FOCAL-DEC's own interactive language for on-line problem solving, designed especially for use on minicomputers. 9-17 • FORTRAN-D-a modified version of FORTRAN II. • EDIT-a line-oriented text editor, used to create and modify source programs (such as FORTRAN) and data. files. • P AL-D-a 2-pass symbolic assembler. • LOADER-a binary loader used to load assembled programs for execution. • ODT-Octal Debugging Technique for testing and modifying assembly language programs. • PIP-Peripheral Interchange Program for transferring files between the system disk and paper tape. .. COPY-a utility program used to transfer files between the system disk and DECtape. • CAT-used to list all the files which a user has stored in his library. • SYSTAT-(System Status) a utility program that prints a brief description of the system status. A more detailed description of each of the above System Library Programs is presented in the following sections. General' File Characteristics A fundamental feature of the Monitor is its ability to save programs or other data for each user in his own private library. These individual user libraries are maintained on the system disk. Individual entries in the library are called files, whether they contain programs or data. Within the library itself, there is no distinction between types of files by their contents. Each file is identified with a file name by which it is known ~nd called into use. The user does not directly create and update the files in his library. He uses the System Library Programs for this purpose. For example, he can use the SAVE command in BASIC. The SAVE command takes the BASIC program named and saves it as a file in the user's library for future use. Similarly, EDIT can be used to modify an existing file, resulting in the creation of a new file .. Therefore, although the Monitor provides the actual file storage capability, most file 'manipulation is done while System Library Programs are being run. The System Library Programs which operate on these files must know which file to use, when to create a new file, and what to call . it. Each Library Program has its own method of determining 9-18 whether a user wishes to use an old file or create a new one; this is explained in the sections on individual library programs. Example 1: .R BASIC NEW OR OLD--OLD OLD PROGRAM NAME--PRIME READY Example 2: .R FORT INPUT,TYPE QUTPUT:BTYPE For most of his work, the user requires access to only his own library. However, it is often a useful feature to be able to obtain a program from another user's library, allowing a single file to be shared by several users. To access a program from another user's library, the user must tell the system in which individual library the file is stored. The user tells the system by entering the account number of the library's owner. (In the absence of an account number, the user's own library is the assumed source.) To get a file from the System Library, type an asterisk immediately after the file name. Example 1: .R SASIC NEW OR OLD--OLD OLD PROGRAM NAME--HOSSR* READY Example 2: .R PALO INPUT:NOTPIP OUTPUTIBINI 544~ NOTE Most examples in the discussions of individual System Library Programs use file names within the user's own library. The user is free (file protect permitting) to use files from other user's libraries. 9-19 Access to another user's files is gained only with his permission. A user may "protect" his files against other users, i.e., prevent them from gaining access to his files, eve_n' though they know his program name and account number. Library Programs never permit a user to write in another user's files.- Specifying a file which is' protected, or specifying a nonexistent file, is an error that is detected immediately. An error message is printed and the file name is requested again. The user places his output in a single file; however, it is often useful to input several files together. (For example, the user may wish to assemble two parts of a PAL-D program together.) To specify more than one input file, separate the file names by com-' mas. No Library Program allows more than three input files. FORTRAN is limited to two; BASIC allows only one. BASIC is a self-contained programming system, with an editor, compiler, and run-time system. It also has a distinctive file format. Files created by BASIC are not compatible with files created by other Library Programs. All other Library Programs depend on each other; therefore, all other Library Programs use the same format for their disk files. Consequently, files created by the Editor can be used as input to PAL-D or FORTRAN-D, and numerical files created with the use of the Editor can be read by FORTRAN programs as data files. Up to this point, only files that exist within the time-sharing system, i.e., on the system disk, have been described; however, EduSystem 50 provides two othe~ means of file storage: paper tape and DECtape. The Library Program PIP can be used to transfer files between paper tape and disk. The Library Program COpy allows files to be transferred between disk and DECtape. Controlling the Execution of System Library Programs EduSystem 50 provides the user with two options for stopping the system. CTRL/C (C with the CTRL key held down) allows the user to stop his BASIC program and return to the beginning of that program without returning to the Monitor. For example, if the user begins to run a BASIC program that has an endless loop, he can type CTRL/C to stop it. BASIC responds to tC wi\h READY. All other Library Programs respond in a similar manner. CTRL/B is used to stop the Library Program most recently 9-20 called. CTRL/B fo11owed by S and the RETURN key unconditionally rcturns the user to the Monitor mode; the user can then call anothcr Library Program. If the system is printing, two CTRL/B's and the S (tRiBS) arc required to stop the system. RUBOUT is another useful character that deletes the la.st typed character. Some Library Programs respond by printing '" or +while others print the deleted character. If the RUBOUT key is typed while entering file names for input or output to a Library Program, RUBOUT deletcs the whole line. The request for input or output is then rcpeatcd. Returning to the Monitor The user can stop the execution of a System Library Program at any time by typing CTRL/B followed by S and the RETURN key. The System Library Programs can also initiate a return to the Monitor. When the System 'Library Programs initiate a return, tBS is printed just as though the user had terminated the program. For example, BASIC returns to the Monitor when the user types the BYE command: READY BYE 1'85 FORTRAN returns to the Monitor after completing execution of a program. CAT and SYST AT rcturn afer printing their particular data output. PAL-D returns aftcr complction of an assembly, LOADER at the end of a normal load, and EDIT after completion of an EDIT. FOCAL, BASIC, ODT, PIP, and COpy never return to the Monitor; these programs must be tcrminated by the user with CTRL/B and S. Somc System Library Programs return to the Monitor when a fatal error condition is dctected. 9-21 9-22 BASIC EduSystem 50 BASIC is a time-sharing version of the BASIC language. It allows even the beginning computer user to write and run meaningful programs. In addition, EduSystem 50 BASIC has advanced language features such as strings, files, and program chaining. This section describes the BASIC language capabilities not discussed in Chapter 1. llable 9-6 contains a complete summary of the EduSystem 50 BASIC language. To call BASIC, the user types: .R BASIC After the user logs into EduSystem 50, and calls BASIC in the above manner, BASIC prints NEW OR OLD-. The user then types the appropriate adjective: NEW (if he wants to enter a new program) or OLD (if he wants to retrieve a program that was previously filed) . BASIC then asks NEW PROGRAM NAME-· (or OLD PROGRAM NAME-) and the user types any combination of six letters or less. If the user is recalling an old program file from the disk, he must use exactly the same name as when he originally . instructed BASIC to save it. BASIC prints READY to signal the start of the editing phase; the user then begins to type the new program. If the user types a line consisting of only a line number followed by the. RETURN key, that line is d€1eted. Each line must begin with a line number greater than 0 and less than 2047 and which contains no nondigit characters. To enter an entire line to the computer, the user must press the RETURN key. If the user makes a typing error while typing a statement and notices it immediately, he can correct it by typing the RUBOUT key (right-hand side of the keyboard), or the back arrow key (SHIFT /0). Typing either key deletes the character in the preceding space and prints a back arrow ( Ie INT(ABS(X)) ON GOTO Statement The ON .. ; GOTO statement may be used to provide a manyway branch. The general form of the ON ... GOTO is: On expression GOTO line number, line number . . . . If the value of the integer part of the expression is 1, a GOTO is performed to the first statement. If the value of the integer part of the expression is 2, a GOTO to the second statement number is performed, etc .. If the value is less than one, or greater than th.e number of statement numbers, the program terminates and an error message is printed. Examples of ON GOTO are shown below: SLEEP Statement The SLEEP statement causes a BASIC program to pause for a specified interval, then continue running. SLEEP is followed by the number of seconds the program is to pause. For example: 222 SLEEP 30 or 9-24 LET N=15 222 SLEEP 2*N 22~ causes a 30 second delay in the program. The SLEEP statement is a useful way for a program to wait for a>device (DECtape or line printer) which is busy. The ELSE clause in the OPEN statement can go to a routine which pauses for a while, then retries the OPEN. When the current user finishes with the device and releases it, the program may then proceed to OPEN and use it. This capability is especially useful when many users may be looking up information on a single DEC tape file. It may also be used to allow two programs to communicate with each other. Each writes information on a tape file for the other, or others, to read. SLEEP should always be used when waiting for a device. While the program is sleeping it i~ not using any processor time. A SLEEP time of 30.to 60 seconds is recommended. It is particularly important that the program not wait by repetitively retrying the OPEN. To do so wastes computer time' and slows down other users. The integer, part of the argument is used to determine the number of seconds to delay. This value must be between o and 4095. Comments An entire statement of comments may be included in the BASIC program by means of the REM statement. Often comments are easier to read if they are placed on the same line with an executable ., statement rather than in a separate REMARK statement. This can be accomplished by ending an executable statement with an apostrophe. Everything to the right of the apostrophe up to the statement terminator (carriage return or backslash) is ignored (unless the apostrophe occurs within a print literal or string constant.) For example: 10 LET X=Y 'THIS ISA COMMENT' PRINT "BUT THIS IS NOT A COMMENT" 3A LET X$="A'B" 2~ Thus, a comment is added to line 10 with an apostrophe, but in lines 20 and 30 the apostrophe is treated as a valid character. 9-25 Blank Lines To make BASIC programs easier to read, blank lines can be inserted anywhere in a BASIC program. These can be used to break a program into logical sections, or (as is often done) to . insert ren1arks with the apostrophe feature. For example: I~ 'PROGRAM WRITTEN BY SAM JONES 100 Note that to insert a blank line, you must type one or more spaces after the line number; typing the line number alone will just delete that line from the program. Multiple Statements per Line As many statements as will fit may be typed on a single program line~ E~ch statement must be separated by the backslash character ""-" (SHIFT /L) . The only statement requiring a line number is the initial one. For example: I"" FOR 1=1 "TO 10\PRINT I\NEXT I Note that the backslash character acts as a statement terminator and thus cannot be included in a comment statement. Editing BASIC Statements If a program line is incorrect, it can be corrected by retyping it. Minor errors in statements can be corrected by using the EDIT command. The user types EDIT followed by the line number of the statement to be edited. BASIC responds by printing a left bracket ([). The user then types a search character. BASIC prints a close bracket and prints the statement through the first occurrence of the specified search character. The user may then: 1. Type new characters which are inserted at that point in the statement. 2. Type one or more back arrows (~) to delete characters to the left of the search ·character. 3. Type the ALT MODE key to delete the entire line up to that point (but not the line number). 4. Type CTRL/L to continue to the next occurrence of the search character. 9-26 5. Type CTRL/G to specify a new search character. 6. Type LINE FEED to finish the edit, keeping the remainder of the line unchanged. 7. Type RETURN to finish the edit, deleting the remainder of the line. Saving Compiled Programs BASIC compiles the current program each time it is run. If, however, a program will be used frequently without being changed, it may be stored in its compiled form. A compiled program can be retrieved and executed faster than a BASIC source program. To save a compiled program, the user types: COMPILE FAME The program is saved on the disk under the specified name (FAME). If a file by that name exists, BASIC prints DUPLICATE FILE NAME and does not compile that program, Once a program has been compiled, it may be retrieved and run just like an ordinary BASIC source program. It may not,however, be listed, saved, or changed. If an attempt is made to do any of these things, the message EXECUTE ONLY is printed. The compile capability may therefore be used to protect programs from unauthorized listing or changing. Since only BASIC source programs can be edited, the user may wish to store both a source and a compiled version of a given program. Compiled files are distinguished from regular BASIC programs by their file extensions. BASIC source programs have an extension of .BAS. Compiled files have an extension of .BAC. These extensions are printed along with the flle name when a catalog is requested. File Protection EduSystem 50 permits a user to specify a protection code for each file. (See the section on Advanced Monitor Commands for a full description of protection codes.) The commands which write disk files (SAVE, REPLACE, COMPILE) also permit the user' to specify what protection is to be given to a file. This is done 9-27 by following the file name with the protection code brackets. For example: In angle SAVE DEMO < lei> will create and save a file named DEMO.BAS having a protection code of 10. When no prot~ction is specified, a protection of 12 is automatically assumed. / Project-Programmer Numbers In specifying the Account Number prior to requesting an OLD file, the user may optionally type a Project-Programmer number (giving the Account Number as two 2-digit numbers separated by commas instead of a single 4-digit number). In this way, the user may RUN files from another user's disk area. For example, both of the following are acceptable: OLD PROGRAM NAME--FILE 13,3 where 13 is the Project Number and 3 is the Progtammer Number, or: OLD PROGRAM NAME--FILE 1303 where 1303 is the account number. The two file name indications are equivalent. Restricted Accounts As an added system protection, BASIC checks to see if an attempt is being made .to run BASIC under Accounts 1 or 2. If so, BASIC prints the error message: IMPROPER ACCOUNT ABORT tBS * thus preventing BASIC from interfering with the System Directories or the System Libr~ry. 9-28 Catalog Format The CATALOG command prints file names and file extensions, file size, and file protection codes for the specified account (the ac-' count under which the user logged into the system). For example: CATALOG NAME SIZE PROT TEMPeJ0 1 12 BASeJ00.TMP 1 17 BASI00.TMP 1 1 '1 IBOLD .BAC 12 DEMO .BAS 10 Strings in BASIC EduSystem 50 BASIC has the ability to manipulate alphabetic information (or strings). A string is a sequence of characters, each of which is a printing ASCII character (see Appendix B). EduSystem 50 strings consist of one to six characters; strings of more than six characters are truncated on input to six characters. Variables can be introduced for simple strings, string arrays, and string matrices. A string variable is denoted by following the variable name with the dollar sign character ($). For example: Al$ V$(7) M$(1,l) A simple string of up to six characters. The seventh strin~ in the array V$(n). An element of a string matrix M$ (n,lll) . When string arrays or matrices are used, a DIM statement is required. For example: reserves space for eleven 6:-character strings for the array V$, and space for 36 6-character strings for the matrix M$. READING STRING DATA Strings of characters may· be read into string variables from DATA statements. Each string data element is a string of one to six characters enclosed in quotation marks. The quotation marks are not part of the actual string. For example: 10 READ A$IB$IC$ 200 DATA "JONJ::S"I"SMITH"I"HOWE" 9-29 The string JONES is read into A$, SMITH into B$, and HOWE into C$. If the string contains more than six characters, the excess characters are ignored. The following program: 10 READ A$ 20 PRINT A$ 30 DATA "TIME-SHARIN.G" 40 END RUN causes only TIME-S to be printed. String and numeric elements may be intermixed in DATA statements. A READ operation always fetches the next element of the appropriate type. In the followi!lgexample: 10 READ AIA$IB 20 DATA "YES"12.5 1 "NO"11 2.5 is read into A, YES into A$, and 1 into B. The standard RESTORE statement (as described in Chapter 1 ) resets the data pointers for both string and numeric elements. Two special forms of the RESTORE command, RESTORE* and RESTORE$, may be used to reset just the numeric or string data list pointers, respectively. For example: 10 READ AIA$IH 20 DATA "YES"12.51"NO"11 30 PRINT AIA$IB 40 RESTORE* 50 READ A1A$IB 60 PRINT AIA$IB 70 END RUN would print: • 2.5 2.5 YES :\10 9-30 If line 40 -Were changed to RESTORE, this program would print: YES YES since the numeric as well as string data lists would be reset. PRINTING STRINGS The. BASIC PRINT statement ~ay be used to print string information. If the semicolon character is used to separate string variables in a PRINT command, the strings are printed with no intervening spaces. For example, the program: 10 READ A$IB$IC$ 20 PRINT C$JB$JA$ 30 DATA ,"ING"I "SHAR"I "TIME-" 40 END causes the following to be printed: TIME- SHARING INPUTTING STRINGS String information may be entered into a BASIC program by means of the INPUT command. Strings typed at the keyboard may contain any of the standard ASCII characters on the user terminal except back arrow (<<-) and quotation mark ("). Back arrow is used in BASIC to delete the last character typed. Commas are used as terminators just as with numeric input. If a string contains a comma, the entire string must be enclosed in quotation marks. The following program demonstrates string input. 10 INPUT A$IB$IC$ 20 PRINT C$IB$IA$ 30 END RUN ? JONES1SMITH1HOWE HOWE SMITH JONES READY Strings and numeric information may be combined in the same INPUT statement as in the following example. Note that if an 9-31 input str~ng contains 'more than six characters, only the first six are retained. 10 INPUT A"A$"B$ 20 PRINT A$"B$"A 30 END RUN ? 01754"MAYNARD" MASS. MAYNAR MASS. 1754 The numeric variable A is set to 1754 (leading zeros are deleted), the string MAYNAR is put in the string variable A$,and the string MASS. is put into the string variable B$. To print the number 01754, the number could be input and output as a character string. LINE INPUT Strings of more than six characters may be entered by means of the LINPUT (line input) statement. A LINPUT statement is followed by one or more string variables. For example: The first six characters to be typed are stored in the first string variable, the next six in the second, and so until the line of input is terminated by a carriage return. Commas and quotes are treated as ordinary characters and hence are stored in the string variables. For example, if the following line were typed in response to the above LINPUT command: ?MAYNARD" MASS. 01754 then the values of the string variables would be as follows: A$ (1) = "MAYNAR" A$(2j = "D, MAS" A$(3) = "s. 017" A$( 4) = "54" A$ ( 6) = " "1 1. Strings may consist of zero characters. Such a string is empty (or null). If printed, it causes nothing to be output. The null string is usually repre- sented by a pair of- quotes with nothing between (""). The null string should not be confused with" a string of one or more spaces. 9-32 In the above example, the maximum number of characters which could be typed would be 30. Any additional chara~ters would be ignored. In all cases, the maximum number of characters which may be typed in response to LIN PUT is 50. If a longer line is typed, the message LINE TOO LONG is printed. The input line is ignored and must be reentered. It is possible to mix numeric and string variables in a LINPUT statement, but this practice is not recommended. As an illustration of how this might be done, consider the example given earlier: where the user might type: ? 01754 1 MAYNARDI MA This still sets the numeric variable A to 1754 (when used in LIN PUT statements, numeric input remains unchanged). However, the string variable A$ would now be MAYNAR, and the . . string variable B$ would be D, MA. When inputting strings with LINPUT, the error messages: MORE? and TOO MUCH INPUT, EXCESS IGNORED cannot occur. WORKING WITH ·STRINGS Strings may be used in both LET and IF statements. For example: 10 LET Y$="YES" 20 IF Z$="NO" THEN 100 The first statement stores the string YES in the string variable Y$. The second branches to statement 100 if Z$ contains the string NO. For two strings to be equal, they must contain the same characters in the same order and be the same length. In particular, trailing blanks are significant since they change the length of the string. "YES" is not equal to "YES ". The relational operators < and> may also be used with string variables. When used with strings. these operators mean "earlier in alphabetic order" or "later in alphabetic order", respectively. 9-33 They may be used to alphabetize a list of strings, for example .. The relation operators >=, <=, and <> may be used in a similar manner. The arithmetic operations (+, -, *, /, t) are not defined for strings. Thus, statements such as LET A$ = 3:1< 5 and LET C$ = A$+ B$ have no meaning, and should not be used in a BASIC program. They will not cause a .diagnostic to be printed; however, the results of such operations are undefined. THE CHANGE STATEMENT The CHANGE statement may be used to access and alter individual characters within a string. Every string character has~ a numeric ASCII code (see Appendix B), a number which is used to indicate that particular character. The CHANGE statement converts a string into an array of numbers, or vice versa; The CHANGE statement has the form: 100 CHANGE A TO A$ or 100 CHANGE A$ TO A where A$ is any string variable (or an element of a subscripted string variable) and A is an array variable with at least six elements. Any array variables used in CHANGE statements must have appeared ina DIM statement with a dimension of at least SIX. The following program illustrates the use of the CHANGE statement by changing a string variable into an array of numbers. 10 DIM A(6) 20 READ A$ 30 CHANGE A$ TO A 40 PRINT A(0)JA(1)JA(2)JA(3)JA(4)JA(5)JA(6) 50 DATA "ABCD) 50 DATA "ABCD" 60 END RUN 4 65 66 67 68 0 0 The CHANGE statement takes each character of the string and stores its corresponding numeric (ASCII) code in elements one to six of the array. Remaining array elements are -set to zero. The 9-34 length of the string (0-6 characters) is stored in the zero element of the array. In the example above, the character codes for A~ B, C, and D are stored in A(1) to A( 4). A(5) and A( 6) are set to zero. The number 4 is stored in A (0) since the string A$ is four characters long. . CHANGE may also be used to change an array of numeric: codes into a character string as in the following program: 10 DIM A(6) 20 FOR I=~ TU 5 30 READ A( I) 40 NEXT I 50 CHANGE A TO A$ 60 PH INT A$ 70 DATA 80 END 5169~6818515314H RUN EDU50 The length of the resulting string is determined by the zero e1e·· ment of the array. In the previous example, the string is five char·· acters long. The elements of the array, starting at subscript 1, are: assumed to be numeric character codes; these are converted to characters and are stored in the string. If any codes encountered' are not valid character codes, or if an invalid string length is given, the message BAD VALUE IN CHANGE STATEMENT AT LINE n is printed, and execution is stopped. A BASIC string of less than six characters always has the remaining character positions filled with zeros. For this reason, when such a string is changed to an array, the first six array elements are set to zero. The CHANGE statement always fills six array elements, even though the strings may not be six characters long. The user should be careful to dimension the array used in a CHANGE statement to at least six. If a string of characters is transformed into an array of less than six elements, an undetected error will occur. The CHANGE statement is usable with strings not created by BASIC. It may, for example, be used to access files other than BASIC data files. Each string variable corresponds to three PDP-8 words. The CHANGE statement treats these three words as six 6-bit bytes, converts each 6-bit byte to its numeric character code equivalent and stores it in the corresponding array element. The 9-35 zero element of the array, the string length; is set equal to the number of bytes (characters) before the first zero byte. When reading unspecified data, there may be non-zero bytes following this zero byte. If so, they will be transferred to the array as ,~ell. THE CHR$ FUNCTION Occasionally, it is desirable to type a character other than those in the printing ASCII set, or to compute the value of a character to be printed. For this purpose, the CHR$ function can be used in a PRINT statement. The argument of the CHR$ function is sent as an ASCII character to the Teletype'. For example: 10 FOR 1=121 TO 9 2121 PRINT CHR$(1+48); 30 NEXT I 40 END prints 0123456789, since 48 to 57 are the ASCII values for the characters 0 to 9. The following special characters can also be printed using the CHR$ function: Bell -Line feed Carriage return Quote (") Back arrow (~) Form feed CHR$ (7) CHR$ ( 10) CHR$ ( 13 ) CHR$ (34) CHR$(95) CHR$(12) The Teletype will accept characters from 0 to 255 (decimal), many of which do nothing on most kinds of teletypes. Some of the special (non-printing) characters should not be used. For example, CHR$ ( 4) causes a Dataphone to disconnect. For each ASCII code there is a second acceptable form permitted in CHANGE and CHR$. The second code is obtained by adding 128 to the code given in the table in Appendix B. For example, CHR$ would type A in response to either 65 or 193 as an argument. Program Chaining Most programs are easily accommodated by EduSystem 50 BASIC. If a program becomes very long, however, it may be necessary to break it into several segments. Typ~cally, programs of more than two to three hundred statements must be split into more 9-36 than one file. A program that has been broken into more than one piece is commonly called a chained program. Each part of a chained program is saved on the disk as a separate file. The last statement of each part to be executed is a CHAIN statement specifying the name of the next part of the program. The next file is then loaded and executed. It may in turn chain to still another part of the program. The general form of the chain command is: 414 CHAIN "NAM E" or 414 CHAIN Ai where NAME is the name to six characters enclosed next segment may also be case, the file of that name of the next segment to be executed (one in quotation marks). The name of the contained in a string variable. In either is loaded and run. Thus, the statement: 999 CHAIN "SEG2" is eq uivalent to: OLD OLD PROGRAM NAME--SEG2 RUN except that it happens automatically. Each separate part of the program automatically links to the next part of the program chain. The individual sections of a chained program may be either regular source files (.BAS) or compiled files (.BAC). If the sec-· tions arc source files, they must be compiled before they are runo A chained program runs more efficiently if all its sections have been compiled. Source and compiled files cannot be mixed in program files. If an error occurs while compiling or running a chained pro-gram, the name of the section containing the error is printed as 9-37 part of the error message. In all cases, whether a program terminates by an error or a STOP or END, BASIC returns to the first program in the chain. This is the one which is available for .editing and rerunning when BASIC prints READY. Most chained programs require that information from one section be passed to the next. The first section may, for example, accept input values and perform some preliminary calculations. The intermediate results must then be passed to the next section of the programs. This p~ssing· of values is done by means of data files which are explained in tbe next section. Whenever a CHAIN operation is performed, program data which has not oeen saved in a file is lost. Variable and array values are not automatically passed to the next program. Disk Data Files The standard BASIC language provides two ways of handling program data items. They may be stored within the program (in OAT A ·stater,nents) or they may.be typed from the terminal. OAT A statements, however, allow for only a limited amount of data. Also, the data is accessible only to the program in which it is em- . bedded. Typing data from the terminal allows it to be entered into any program, but this is a time-consuming process. In either case, the data or results of calculations cannot be cOliveniently stored for future use. All these limitations m'ay be overcome by the use of disk data files. A data f)·le is separate from the program or programs which use it. It is a file on the disk similar to a saved program, but it . contains numbers or strings rather than program statements. This information may be read or written by a BASIC program. ( I nformation in a data file is stored in a coded format; therefore, it cannot be listed by the BASIC Editor or EDIT.) (The maximum size of a data file is about 350,000 characters.) String and numeric information may be combined in a single data file. The number of data tllcs a user may have is limited to about 100, space allowing. When a file is first created, its contents are undefined. FILE RECORDS A data file is made up of logical units called records. A record may be as small as a single numeric or string variable. More typically, it is a group of variables or arrays. The design of the program lIsually dictates the most efficient size of the record. If, for ·9-38 , example, the program manipulates a series of 5 by 5 matrices, each record could contain one such matrix. If the program operates on 80-character alphanumeric records, 14 string variables might comprise a record. The size and composition of a record are defined with a RECORD statement. Like the DIM statement,RECORD is followed by a series of variables. They may, however, be unsubscripted as well as subscripted. For example: 10 RECORD A(S"S> 10 RECORD B$(14) 10 RECORD A,,B,,C$(8),,D,,E(S> J:he set of variables mentioned in a RECORD statement, taken together, constitute a record. Each element within the :record is a field. Numeric and string information may be mixed to comprise a more convenient record. Variables mentioned in a RECORD statement should not appear in a DIM statement. 'The RECORD statement reserves variable space exactly as a DIM statements does. The difference is that the variables are also identified as being used for file Input and output. Non-subscripted variables appearing in RECORD statements must not have been used previously in a program; therefore RECORD statements should always be the first statements in a program. Records may be any length. A long record is typically more efficient since more information is transferred in a single operation. Records should, however, be only as long as necessary since excess variables lengthen the file. In particular, it is important to remember that all arrays and matrices have zero elements. The array A(5,5) has 36 elements, not 25. If A appears as part of a record, all 36 elements should be used. It is also useful to try to make record sizes 43 variables long, or a multiple of 43. Each RECORD statement reserves program variable space in units of 43 whether or not the record is that big. Unless the record fills this area, some program variable space is wasted. It is not worthwhile, however, to make an inherently small record 43 variables long just to conform to this convention; this would make the file unnecessarily large. 9-39 OPENING A DISK FILE Disk data files are completely separate from the programs which use them. Therefore, the program must specify which file or files it will use. The OPEN command is used for this purpose. OPENing a disk data file associates it with an internal file number, either 8 or 9. (A program may have two disk data files open at one time.) For example: 100 OPEN 9 .. "DATA10" 11210 OPEN 8 .. A$ The name of the file to be opened may be explicitly stated in the OPEN commpnd. If i,t is, it must be contained in quotation marks. The file name may also be .contained in a string variable, allowing the program to decide which file to open, perhaps on the basis of input from the program's user. In either case, the name of the file is preceded by the internal file number, either 8 or 9. This argument may also be an expression whose value is either 8 or 9. When a file is opened on an internal file ,number which has a file already open, the previously opened file is closed and the new file opened. • If no file of that name exists, the file is created. In .either case, once the file is open, it is available for both reading and writing. BASIC disk data files are assigned an extension of .DAT which need not be spes}fied as part of the file name in the OPEN statement. READING/WRITING DISK FILES Once open, files may be read and written, one record at a time, using the G~T and PUT statements. GET statements read one record of information directly into the variable in the RECORD statement. PUT statements write the present values of the variables in the RECORD statement. Both GET and PUT statements are followed by the internal file number (8 or 9 or an expression), the line number of the RECORD statement 'containing the variables to be transferred, and the name of a control variable. For example: 100 110 120 130 RECORD A .. B .. C$(30)"D(8) OPEN 8" "FILE1" LET 1=0 GET 8 .. 100 .. 1 9-40 The control variable specifics the file record to be transferred. I n the example above, Fl LE 1 is opened as internal file 8. The value of the control variable, L is zero. The GET statement in Ii ne 130 reads the first record (record ()) of FI LE I into A, B, and the arrays ('$ and D. Single nlimeric values arc read into A and B, 3 I strings arc read in C$, and 9 numeric values are read into D. After each transfer, whether it is a GET or a PUT, -the value of the control variable is automatically incremented. Successive GET's or PUT's automatically proceed to the next record of the file. The PUT statement has a similar format. For example, if line 130 or the preceding program had been: C 130 PUT 8~100~I the present values of A, B. C$, and D would have been written to the first record of FI LE I. File records may be accessed randomly by setting the control variable to the desired record number before doing the GET or PUT. Single records may be read. changed. and then written with,out proces_sing the entire lile. When reading a file, the record referenced in the GET statement must. of course, be the same as the record referenced in the PUT statement which- wrote the data onto the file. The total length of the record and the relationship of string and numeric fields within the records used for the GET's and PUT's must be the same. If they arc not. improper information will be read and written. New files may be created by openiri'g a file which docs not alreadv. exist. As successive records are- written onto the file. its length is extended as necessarv. . When a new file is created. it is usct"ul to immediately write an end-of-file code in the last record. W.riting the last recl)rd first forces the entire file to be allocated. making sure that enough disk space is available. It also provides an end-or-file mark. Programs which read this file may. then check for this end-or-file mark to avoid readil~g past the end of the data file which results in an error. . Existing flies may be enlarged by writing a new record farther out. If the program do~s not know how big the file will be. it may simply write records to the file in sequcncc. - ~ ~ 9-41 The file will be automatically ex~ended. When all the records have been written, one final end-of-file mark can be added. In general,all records read or written on a specific file should be the same length, i.e., contain the same number of variables. However, if the user is careful he may intermix records of different lengths in a file. Suppose the following statement is executed: 40 PUT 8 .. 100 .. N and the value of N is n and the record specified by statement 100 is of length m. The PUT statement will write m variables in the file starting at the m*n variable. The simple rule for computing the first variable in the .file to' be accessed is the record length times the record number" (Remember the first record is record number zero.) c CLOSING/DELETING DISK FILES When all work has be~ncompleted on a data file, it should be closed with a CLOSE statement. Once the file is closed, it may not be read or written unless it is reopened. The file does, however, remain on the disk and is available for future use. The CLOSE statement is followed by the interna,l file number to be closed (B or 9). For example: 950 CLOSE 8 If the 'disk file was just created for temporary' scratch use (to pass parameters during a CHAIN, for example), it should be deleted at the end of the program instead of closed. The UNSA VE statement is used to delete files. For example: The file opened on internal file number 9 is deleted from the disk. Both CLOSE and UNSAVE may ,be followed by an expression e.quating to 8 or 9 instead of a constant. Open disk data files are automatically closed at the end of the program, unless the program CHAINs to another program. In this case, all open files remain open and the new program may access them without executing an OPEN statement. 9-42' DECtape Data Files Large permanent data files are best stored on DECtape rather than on disk. Each DECtape holds up to 380,000 characters of information. DECtape data files may be dismounted for safekeeping, thereby insuring their privacy. Data files on DEC tape are similar to files on disk except that they do NOT have filenames. Each reel of DECtape is treated as a discrete data file. When the tape is mounted on a DECtape drive, records may be read and . written *ectly onto the tape. A D~tape data file may be used by only one user at a time. Once a DECtape unit is assigned, a single user has exclusive access to it until he releases it. Each DECtape drive has a WRITE LOCK switch which physically prevents any write operations to that unit. If the WRITE LOCK switch is set, programs may not write on the tape even if the unit is assigned. DECtape data files may be used in a variety of ways. Programs which need large data files should use DECtape to avoid consuming large disk areas. Administrative files, such as student or employee records, are best stored on DECtape. Since they are removable and can be write-locked when mounted, their use can be tightly controlled. DECtapes are also useful for information retrieval. A data tap'e may be ~~pt permanently mounted but write-locked. Individual users may run programs which assign and query that file, then release it for others to use. DECT APE FILE RECORDS Records for DECtape data files are specified the same way as for disk data files: with a RECORD statement. All rules for disk records apply to DECtape records. In fact, the same RECORD statement may be used for both a DECtape and disk file .. (This. is useful when transferring a tape file to a disk file for processing. Access to disk data files is considerably faster than to DECtape data files.) it is possible to specify any record length for a DECtape data file, but a size of 43 -variables is' suggested, even more strongly than for'disk data files. DECtapes are physically structured into blocks, each of which holds exactly 43 variables. If the record specified by the program is, for example, 44 variables, it requires two full blocks on the tape. Records which are multiples of 43 variables are efficient in 9-43 utilizing DECtape space but are not efficient in speed. Such records are written in consecutive DECtape blocks. The tape unit cannot read or write consecutive blocks without stopping the tape and rewinding it slightly (rocking). This tape rocking also occurs when single block records (43 variables or less) are read or written as consecutive DECtCl.pe records. (In this case, each DECtape file record corresponds to a physical tape block.) The most efficient way to utilize DECtape is to make records 43 variables in length and write them onto every tenth record in the file (records 0, 10, 20, etc.). When the entire length of the tape has been traversed (the last block of the tape is number 1473), write next into records 1, 11, 21, etc. In this way, every record is eventually filled. Programs which will be used repeatedly should access the tape in this manner. OPENING A DECTAPE FILE DECtape data files, like disk files, are completely separate from the programs which use them. Therefore, the program may specify which tape, or tapes, it will use. The OPEN statement is used for this purpose. Since DECtape files do not have names,2 the OPEN statement specifies the DECtape unit number to be used. It is assumed that the proper tape reel has been mounted. If the file is to be updated, the uni_t shou18 be write-enabled. If not, it should be write-locked. The OPEN statement is followed by the unit number to be used (0-7). 100 OPEN 2 100 OPEN 7 The unit number could be an expression. Making the unit number a variable is very useful since it is hard to predict which units will be available at the time the program is run: When the unit specification is a variable, the user may mount the file on any free unit, then INPUT the number into the program. When the OPEN statement is executed, the indicated DECtape unit is automatically assigned to the user. It cannot subsequently be assigned to any other user. Thus, it is possible to try to open, 2 It is important to note that BASIC data file DECtapes are not the same as the file-oriented DECtapes used by COPY. There is no directory on a BASIC DECtape file. Each tape is considered to be one file of data. 9-44 hence assign, a unit which is already assigned. If, in the above examples, units 2 and 7 were already assigned to the current user or any other user, the program would be terminated arid an error message printed. An alternative form of the OPEN statement allows the program itself to handle this situation. OPEN statements may include an ELSE clause which specifies a line number. If the OPEN statement fails, BASIC automatically performs a GOTO to this line number. For example: 100 OPEN 2 ELSE 900 If unit 2 is available, it is assigned and BASIC goes on to execute the next statement. If unit 2 is not available, statement 900 is exe- cuted next. Statement 900 could print a message and perhaps ask for an alternate unit number. READING/WRITING DECTAPE FILES DECtape data files are read and written using the same GET and PUT statements as are used for disk data files. The internal file number is a number between a and 7, or an expression. Unlike disk data files, DECtape data files are of a constant length equal to the capacity of the tape. The exact number of records per reel depends on the record size as follows: Record Size Tape Capacity 1-43 variables 44-86 variables 87-129 variables 1474 records 737 records 491 records , As indicated in the section on DECtape data records, a record size of 43 variables or less is recommended since it conforms to the physical blocking of the tapes themselves. It is also desirable to space the records along the tape so that the tape does not waste: time rocking. The following subroutine could be used to write: 1474 records on the tape in this fashion. It assumes that R is set to zero before it is called the first time and that the unit number is in U. 9-45 500 510 515 517 524 530 540 545 547 550 560 REM SUBROUTINE TO WRITE RECORDS ALONG TAPE REM WRITES ONE RECORD EACH TIME CALLED PUTU"10,,R 'REMEMBER THIS INCREMENTS R LET R=R+9 'SPACE OUT 10 BLOCKS IF R<1474 THEN 550 'OK TO RETURN IF R=1479 THEN 560 'TAPE IS'FULL LET R=R-1479 IF R>0 THEN 550 LET R=R+10 RETURN STOP 'TAPE IS FULL The following function may also be used to convert a logical record number (0 to '1469) to a physical record block spaced along the tape. This function does not use blocksO-3. These blocks are, therefore, available for a header or label. Both the subroutine above and the function below assume a record length of 43 variables or less. FNC(X) = (X-INT(X/147)*147)*10 + INT (X/147)+4 Once opened, any record on the tape may be read. The tape unit must, however, be write-enabled if it is to be written. Trying to' PUT to a write-Iock.ed tape is an error. CLOSING OECT APE FILES Once all work on a OECtaQ.e data file has been completed it may be closed. Closing a file releases the tape unit and makes it available to other users. Thus, if the tape contains important information (and especially if it is write-enabled) the CLOSE should not be done until the tape reel has been removed. If no CLOSE statement is encountered in the program) the unit remains assigned after the program has finished. The OECtape unit remains assigned until a Monitor RELEASE command is executed or the user logs out. An example of a CLOSE statement follows: IIVl(i'J CLOSE 6 USING OECT APE OAT A FILES WITH OS/8 FORTRAN Numeric OECtape data mes written by BASIC may be read by OS/8 FORTRAN with the FORTRAN RT APE and WT APE subroutines. and vice-versa. (String and Hollerith variables use different character codes.) Thus, it is possible to use BASIC to 9-46 prepare an input or update tape for a stand-alone FORTRAN program. This provides a conyenient way to do big jobs in ofl·hours, without having to leave the time-sharing mode for very long. Line Printer Output If a line printer is "available, it may be used both to list BASIC programs and to serve as an output device for the programs themselves. The line printer may only be used by one ,,!ser at a time. The statements associated with line printer output are LLIST and LPRINT. LLIST is similar to the LIST command except that the program listing is output to the line printer rather than to the Teletype. The LLIST command assumes that no other user has the line printer assigned and "responds by typing WHAT? if the line printer is not available. After the listing is complete, the line printer is released and is available to any user. BASIC programs may use the line printer as an output device during execution by means of the LPRINT statement. LPRINT is exactly like PRINT except that the information goes to the line printer rather than to the Teletype. All formatting conventions of the PRINT statement are available with LPRINT. In particular, CHR$ ( 12) may be" used to skip to the top of the next form (page). " The LPRINT statemeht also assumes that no other user has the line printer assigned. However, using this statement when the line printer is not available causes the program to terminate. Once LPRINT successfully assigns the line printer, it remains assigned until the program terminates. . The OPEN and CLOSE statements may be used to assign and release the line printer. An OPEN statement with a device number of 11 assigns the line printer, or if it is not available and an ELSE clause is specified, transfers control to the line number specified in the EI;..SE clause. CLOSE 11 releases the line printer. Paper Tape Output The high-speed paper tape punch 1Jlay also be used as an output device. Like the line printer, the paper tape punch may only be used by one user at a time. OPEN and CLOSE statements with an internal file number of 10 will, respectively, assign and release the paper tape punch as shown in the following example: 9-47 10 OPEN 10 ELSE 100 'GOTO 100 IF ?UNCH UNAVAILABLE 20 CLOSE 10 Here too, a GOTO statement in combination with an ELSE clause can be used to transfer program control if the paper tape punch is unavailable. The LPRINT statement causes output to the paper tape punch when this device has been assigned. For example: 10 OPEN 10 20 LPRINT "THIS GOES TO PTP." causes the statement THIS GOES TO PTP. to be punched onto paper tape. If the paper tape punch is not released with a CLOSE statement, it remains assigned after the program terminates. Internal.Data Codes Using the file I/O capabilities and the CHANGE statement, it is possible to examine data which was written on a DECtape or disk file by a program other than BASIC. There are two data formats: numeric and string. NUMERIC DATA Each numeric value in BASIC is three PDP-8 words long. The storage format for numeric data is as follows: o WORD I SIGN 8 I 9 II -;--L--'-l---'------L.......--'------'----'-_ _L-.J.....---0.'----1 L-I -.-J '-'----..:....,r~----J '---.------'t BINARY EXPONENT • HIGH ORDER M A N T l S S A - - - - - - - - - - - - I o WORD 2 II LI_______________ MANTISSA o WORD 3 LI.'--_____________-.--J LOW ORDER MANTISSA A one in the SIgn bit means that the number IS negative. The • exponent is kept in excess 200 form where: 200~ is 2° 201 R is 21 177 8 is 2- 1 9-48 The assumed deci~al point is be,tween bit 8 ~nd bit 9 of word ]. AlSo, the number IS always normalized, meaning that bit 9 is aJ.ways 1 unless the number is zero. (Zero is represented by thre~~ zero words.) Note that this format is the same as the fprmat used by FORTRAN-D. Table 9-3. 'BASIC Internal Data Codes 6-Bit Byte Byte Octal Decimal 00 01 02 03 04 05 06 97 10 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 20 21 22 23 24 25 26 27 30 31 32 33 34 35 36 37 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 ASCII Char. NULL SPACE " # $ % & .() * + / 0 1 2 3 4 5 6 7 8 9 .. < > 9-49 6-Bit Byte Byte Octal Decimal 40 41 42 43 44 45 46 47 50 51 52 53 54 55 56 57 60 61 62 63 64 65 66 67 70 71" 72 73 74 75 76 77 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 ASCII Char. ? @ A B C D E F G H I J K L M N 0 P Q R S T U V W X y Z [ '" ] t STRING DATA'. . . DP-8 words long. Each word Each string v~nable IS th~ee ~ers If a string .variable is filled contains two 6-blt bytes or c. ahra . t written by a BASIC proGET f a source whlc . was no by a . romC' ay examine the data in the variable b. Y ram a BASI program m ' " n be ~erfO'rming a CHANGE on that variable. The SlX bytes WI translated as if they were internal character codes for BA.SIC string characters. Table 9-3 shows how this translation interprets the 64 possible types. Note that after such a CHANGE, the Oth element of the an:ay contains a count of the number of characters occurring before the first null. Error Messages Most programs, especially if they are at all complex do not execute correctly the first time they are tried. EduSystem 50 checks' all BASIC statements when they are entered and before executing' them. If it cannot execute a statement, it informs the user by printing one of the error messages shown in Table 9-4, followed by the lihe number, if present, in which the error occurred. In addition, the system checks for non-fatal execution errors and notifies the user that he performed a computational range error. When errors of this type occur, the messages shown in Table 9-5 appear, followed by the line number in which the error occurred. Table 9-4. BASIC Error Messages Message Explanation WHAT? The editor cannot understand the command given. SYSTEM 1-0 ERROR BASIC was unable to perform the desired dis.k 110. PROGRAM TOO LARGE The program js too large to be executed. Make it smaller. NO END STATEMENT IN PROGRAM All programs must have an END statement. ILLEGAL INSTRUCTION A statement was used which is not one of the legal ,BASIC statements. 9-50 Table 9-4 (Cont.). Message BASIC Error Messages Explanation ILLEGAL SYNTAX The expression in a statement does . not agree with the BASIC syntax. DEF STATEMENT MISSING A function needing a DEF statement exists in the program. FOR WITHOUT NEXT There is an unmatched FOR statement in the program. NEXT WITHOUT FOR The NEXT statement indicated has no preceding FOR statement. ILLEGAL CHARACTER The user attempted to use an illegal character in the statement being processed. ILLEGAL LINE NUMBER The format of the line number being used in a GOTO or IF statement is not acceptable. ILLEGAL OPERATION The expression being processed doecs not agree with the BASIC rules (this is probably due to unmatched parentheses) . STACK OVERFLOW The user programmed a situation in which the expression is too complicated :to be executed. ILLEGAL CONSTANT The format of a constant in the statement being processed is not valid. OUT OF DATA A~ attempt was made to READ more data than was supplied by the user. ILLEGAL FORMAT The structure of the statement does not agree with BASIC syntax. DIMENSION TOO LARGE Too large an array to fit in the available core. UNDEFINED LINE NUMBER The line number appearing in a GOTO or an IF-THEN statement does not appear in the program. BAD FILE NAME The file name used is not valid, e.g., it does not begin with a letter. 9-51 Table 9-4 (Cont.). BASIC Error Messages Message Explanation SUBSCRIPT ERROR A negative subscript was used for an array. MISUSED TAB The TAB function was used in an invalid manner . TAB can appear only in PRINT statements. GOSUB-RETURN ERROR Subroutines are too deeply nested or a RETURN statement exists outside a subroutine. ILLEGAL FOR NESTING FOR-NEXT loops are too deeply nested or NEXT appears before FOR. ILLEGAL VARIABLE An illegal variable was used in an array. DISK FULL There is no more storage space on the system disk. IMPROPER ACCOUNT # ABORT tBS A user logged in under account numbers 1 (system account) or 2 (system library) and tried to run BASIC. This is prohibited. BAD FILE FORMAT The program specified in response to OLD PROGRAM NAME was not acceptable to BASIC. This is generally caused by: (1) trying to load an obsolete compiled (.BAC) file, or (2) trying to load a non-BASIC (FORTRAN or PAL-D) program. MISUSE OF CHR$ The CHR$ functi~n was used in an invalid manner. CHR$, like TAB, can appear only in PRINT state-· ments. BAD VALUE IN CHANGE STATEMENT While performing CHANGE A TO A$, one of the elements of the array A was found to contain an illegal value. TIME LIMIT EXCEEDED The number of statements executed by a job has exceeded the maximum established by the system manager. Generally, some error was made and the program is caught in a loop. 9-52 Table 9-4 (Cont.). BASIC Error Messages Message Explanation PROGRAM IS "progname" This message may immediately folIowan error message, to identify the current program ina series of CHAINed programs. If there is no CHAIN, this message will not occur. PROGRAM NOT FOUND The file which the user tried to access with a CHAIN statement does not exist in his disk area. The PROGRAM IS message will also occur. BAD SLEEP ARGUMENT The argument of the SLEEP statement must have a number greater than or equal to 0, and less than or equal to 4095. ARRAY OR RECORD USED BEFORE DEFINITION The RECORD statement must occur before any reference to it is made. A DIM statement must occur before an array is used. (RECORD and DIM are placed at the beginning of a program.) IMPROPER DIM OR RECORD STATEMENT Syntax error in DIM or RECORD statement, or an array name that was previously dimensioned is reu:~ed. (Replaces IMPROPER DIM STATEMENT IN LINE n). CAN'T CREATE FILE An OPEN statement tried to create a file, but there is: (a)· no disk space available, (b) no file name speciHed, or (c) a null string has been given as the file name. CAN'T DELETE FILE UNSAVE cannot delete a file. This is usually due to the fact that another user has the file open, or the file is protected with a code ~20. UNOPEN DISK UNIT The user tried to do a GET, PUT, or UNSAVE to device 8 or 9, without a file being previously opened on the device. 9-53 Table 9-4 (Cont.). BASIC Error Messages Message Explanation DEVICE BUSY The user tried to OPEN DECtapes 0-7, line printef, or paper tape punch, but the device was unavailable, and there was no ELSE clause in the OPEN statement. INVALID RECORD NO. The record number must be ,a number which is greater than or equal to o and less than or equal to 4095. For DECtape II 0 the maximum record number is limited further by the DECtape size. ON INDEX OUT OF RANGE The value of the index is less than one, or greater than the number of statement numbers. INVALID DEVICE NO. The device number' in the file II 0 statement is not between 0 and I I inclusive, (or X and 11 inclusive where X is a number set by the system manager) . GET BEYOND END OF Disk data file is too small to have a record with the number specified in the GET statement at line n. FILE GET/PUT ERROR A hardware error occupied in GET or PUT. (This is usually due to a DECtape unit being write-locked.) CHAIN TO BAD FILE The file specified by the CHAIN has an invalid format: it is not a BASICformat file. The "PROGRAM IS ... " message will follow this error message. The program name will be the name of the bad file. 9-54 Table 9-5. Message /0 OV UN . LN SQ PW Non-Fatal Execution Errors Explanation Zero divide-an attempt was made to divide by zero. The largest possible number is used for the result. Overflow-the result of a calculation was too large for the computer to handle. The largest possible number is used for the result. Underflow-the result of a calculation was too small for the computer to handle. Zero is used for the result. An attempt was made to compute the logarithm of zer~ or. a negative number. Zero is used for the reKllt. An attempt was made to compute the square root of a negative number. The square root of the absolute value is used for the result. An attempt was made to raise a negative number to a fractional power. The absolute. value of that number raised to the fractional power is used. 9-55 Table 9-6. Statement EduSystem 50 BASIC Language Summary . Format Input/ Output Statements CLOSE CLOSE f DATA DATA n l ,n 2, ... nn GET GET f,l,r INPUT INPUT VI '2, ... Vn LINPUT LINPUT v$1,V$2, ... V$n , \0 VI LPRINT LPRINT el,e2, ... el~ OPEN OPEN-ELSE PRINT PUT READ RESTORE RESTORE * RESTORE$ UNSAVE OPEN f,n$ OPEN fELSEn PRINT e 1 ,e 2,...e n PUT f,l,r READ VI,V 2 , ... vn RESTORE RESTORE * RESTORE$ UNSAVEf 0"1 Explanation Close file f. Numbers nl through nn = variables in READ statement. Read record r from file f into the variables in line i. Get VI through Vn ,input from the Teletype. Get long character 'string input from Teletype (up to 50 characters) . Print values of specified text or expressions on line printer or high-speed paper tape punch. Open a file named n$ as file number t.Open a file, go to line n if unavailable. Print values of specified text, variables, or expressions. Write record r, formatted as in line 1, into file f. Read variables v through v from DATA list. Reset DATA pointer to beginning value. Reset DATA pointer for numeric data only. Reset DATA pointer for character string data only. Delete file f from disk storage. Table 9-6 (Cont.). 1.0 I VI -.l EduSystem 50 BASIC Language Summary Statement Format Explanation Transfer of Controls GOTO IF-GOTO GOTO 1 IF e 1 r e:! GOTO 1 Transfer control to line number 1. If relationship r between el and e 2 is true, transfer control to line number 1. Same as IF-GOTO. Computed GOTO. IF-THEN ON-GOTO Loops and Subscripts DIM FOR-TO-STEP IF e l r e:! THEN 1 ON e GOTO II,l:!, ... l;; NEXT NEXT v Subroutines GOSUB RETURN GOSUB 1 RETURN STOP Others CHAIN CHANGE DIM v(d 1), v(d1,d;l) FOR v=e 1 TO e:! STEP e;; Enter subroutine at line 1. Return from subroutine to statement following GOSUB statement. Transfer control to END statement. STOP CHAIN n$ CHANGE VI TO Dimensions, variables subscripted. Set up program loop. Define v values beginning at e l to e 2 • incremented by e 3 • Terminate program loop. (Increment value of v until v>e2·) V2 Link to next program. Change character string to array of character codes or vice versa. Table 9-6 (Cont.). Statement 'P. VI 00 DEF END LET RANDOMIZE REMARK SLEEP Edit/ Control Commands BYE CATALOG COMPILE CTRL/C DELETE Format DEF FNA(x)=f(x) END LET v=f RANDOMIZE REM. text SLEEP n BYE CAT COM name CTRL/C DELn n EDIT DEL n,m EDln EduSystem 50 BASIC Language Summary Explanation Define a function. End of program. Assign value of formula f to variable v.. Randomize random number routine. Insert a remark or comment. Cause program to pause for n seconds. Leave BASIC Monitor. List names of programs in storage area. Compile program in core and save it on disk. Stop program execution; return to edit phase. Delete line n. Delete line n. Delete lint;:s n through m, inclusive. Search line n for character c. (c) KEY LIST KEY LIST LISTn LISTn,m Return to keyboard mode after TAPE. List entire program in core. List line n only. List lines n through m, inclusive. Table 9-6 (Cont.). \0 I VI \0 EduSystem 50 BASIC Language Summary Statement Format Explanation LLIST NEW OLD REPLACE RUN SAVE SCRATCH TAPE UNSAVE LLIST NEW OLD REP REP name RUN SAVE name SCR TAP UN SAVE name List program to line printer. Clear core, request program name. Clear core, bring program to core from storage area. Replace old file on disk with version in core. If name is not specified, old name is retained. Compile and run program in core. Store program named on storage device. Erase current program 'from core. Read paper tape; suppress printing on Teletype. Delete program named from storage device. Functions ABS ATN COS EXP INT LOG RND SGN SIN ABS(x) ATN(x) COS(x) EXP(x) INT(x) LOG(x) RND(x) SGN(x) SIN (x) Absolute value of x. Arctangent of x (result in radians). Cosine of x (x in radians) e (e=2.712818). Greatest integer of x. Natural logarithm of x. Random number. Sign of x (+ 1 if positive, -1 if negative, 0 if zero). Sine of x (x in radians). Table 9-"6 (Cont.). ~t~tement \0 I 0\ o SQR TAN TAB FIX CHR$ . EduSystem 50 BASIC Language Summary Format Explanation SQR(x) TAN(x) TAB(x) FIX(x) CHR$(x) Square root of x. . Tangent of x (x in radians). Controls printing head position on Teletype. Truncates decimal portion of x. Converts character code to character. Used only with the PRINT statement. FOCAL FOCAL (FOrmula CALculator) is an on-line~' interactive, service program for the PDP-8 family of computers, designed to help scientists, engineers, and students solve numerical problems. The language consists of short imperative English statements which are easy to learn. FOCAL is used for simulating mathematical models, for curve plotting, for handling sets of simultaneous equations, and for many other kinds of problems. To call FOCAL, type: .R FOCAL FOCAL enters its initjal dialogue, and asks if its extended functions are to be retained. The extended functions are exponential, sine, cosine, arctangent, and logarithm. If the FOCAL program to be run uses any of these functions, the user responds YES. If not, the user responds NO to free more space for the user program. Without the extended functions, there is room for approximately 1800 characters of program. If the extended functions are retained, there is room for approximately 1100 characters. Using FOCAL Commands Whenever FOCAL prints any asterisk, it is in command mode, and the user may type any of the FOCAL commands in response to the asterisk. FOCAL commands may be direct or indirect. A direct command is typed directly after the asterisk and is .executed immediately. The format for direct commands is: *COMMAND An indirect command is always identified by a line number. Indirect commands are not executed until program control passes to the line number associated with the command. The format for indirect commands is: *GG.ss COMMAND When the user is typing indirect commands, he may use any line number in the range 1.01 to 31.99, except those ending in .00. Numbers such as 1.00 or 31.00 are illegal as line numbers; 9-61 ,they are used to identify an entire group of line numbers. Line numbers. are typed in the format: GG.ss where GG is the group number and ss is the step number. It is not necessary to type two digits after the" decimal; e.g., 2.1 is equivalent to 2.10. All FOCAL commands must be followed immediately with a space. All FOCAL command lines must be terminated with the RETURN key. FOCAL Overview FOCAL consists of 12 commands which are all the beginner needs to write programs. FOCAL commands may be typed in their entirety or abbreviated. The FOCAL commands are: Command Explanation TYPE Used to print text, results of calculations, and values of variables. ASK Used to assign values to variables from the keyboard. SET Used to define variables and evaluate expressions. GO or GOTO Used to direct program control to the lowest line number, or to some specific line number. IF Used to direct program control conditionally after a comparison. DO Used to cause a specific line or group of lines "to be executed. RETURN Used to terminate DO routines. QUIT Used to halt program execution and return control to user. FOR Used to increment number and execute a user-specified command for each value of the number incremented. a 9-62 Command Explanation COMMENT or CONTINUE Used for comments or non-executable program steps. ERASE or ERASE ALL Used to erase part of a program or an entire program. MODIFY Used to edit words or characters on a program line. These commands are explained in detail with actual computer output in this section. For the convenience of the user, a detailed FOCAL command summary is included in Table 9-7. Numbers. A FOCAL number may be any decimal number between -1 onl" and 10615 • Numbers may be written signed (+ or -) or unsigned, either with a decimal point and a fractional part or in exponential format (see Data Formats) with a mantissa and exponent. In FOCAL, all numbers are internally represented in exponential format, retaining up to six significant digits. If more than six digits are specified, the number will be rounded to six digits. The following numbers are identical in FOCAL: 60 60.00 6E10 600E-I0 60.00003 Variable Names FOCAL variable names may consist of ei ther one or two char-· acters. The first character must always be alphabetic; however, it cannot be an F becaluse FOCAL reserves that character for func-· tion names (see FOCAL Functions). The second character may be either alphabetic or numeric. The user may write variable names consisting of more than two characters, but FOCAL uses only the first two characters to identify the variable. a Therefore, the first two characters must be unique. 3 A variable is represented internally as a binary fraction with an exponent. See Data Formats. 9-63 *SET *SET *SET *SET *SET *SET A=56789 B=123456 Cl=15 C2=30 DEPTH=10 DISTANCE=Cl+C2 Variables may also be sUbscripted. For a discussion of what subscripted variables are and how they are used, see Subscripted Variables. Arithmetic Operations To print the· results of arithmetic calculations, the user types the FOCAL command TYPE followed by a space and the data to be calculated. Then he presses the RETURN key, and FOCAL prints the answer. For example: *TYPE 6+10-3-1 12.0000* = The above example shows two of the arithmetic operati9lls (+ and -) performed by FOCAL. Arithmetic operations are performed from left to right except when the operation to the right has priority or when enclosures are used. (See Enclosures.) *TYPE 6+5; TYPE 5+2-3; TYPE 10-6 = . 11. 0eJ00= 4.0000= 4.0000* NOTE Several commands may be typed on· the same line if they are separated by semicolons (;). This is true for all FOCAL commands .except the LIBRAR Y commands. Unless indicated otherwise, FOCAL mathematical computations retain an accuracy of six. significant digits. PRIORITY OF ARITHMETIC OPERATIONS The .FOCAL arithmetic operations priorities are: First priority -exponentiation (t) 4 Second priority -multiplication (*) 4 When exponentiation is performed by FOCAL, the power to which a number is raised must be a positive integer. If a calculated exponent exceeds the limits of size, no error message is given. The result will go to zero. 9-64 Third priority --division (I) addition (+) Last priority subtraction (-) 1 When FOCAL evaluates an expression which includes several arithmetic operations, the above order of priority is followed. Therefore, FOCAL evaluates . to have a value of because multiplication (*) has a higher priority than addition (+). ENCLOSURES The order of executing arithmetic operations is also influenced by enclosures. Three kinds of enclosures may be used with FOCAL: parentheses (), square brackets []~, and angle brackets <>. FOCAL treats them all the same. For example, the result of the expressIon: is the same as the result of: *TYPE * * If the expression contains enclosures within enclosures (called nesting), FOCAL executes the contents of the innermost enclo·· sures first and works outward. *TYPE <5*<2+3>-5>t2 400.0000* = 5 [and] are typed by SHIFT/K and SHIFTn"1;, respectively. 9-65 Input/ Output Commands TYPE COMMAND The TYPE command is used to print results of calculations, values of variables, text or character strings, and variable tables. TYPE may also be used to print combinations of text and variables. Example I-Result of a Calculation: *TYPE 1+1 = 2.eleleleI* Example 2-Value of a Variable or Variables: *SET N=5+5: SET M=3e1 *TYPE N~M 10.0000= = Example 3-Text: *TYPE "THIS IS A LINE OF THIS IS A LINE OF TEXT TEXT"~ ,6 * Example 4-Variable Tables: *TYPE $ N(H eleI) = Mi(eleI)= * The user may command FOCAL to print all of the user-defined variables (variable table) by using the TYPE command and a dollar sign ($). If a variable consists of only one letter, an at sign (@) is inserted as a second character in the variable table printout, as shown in the example above. *SET N=25 *TYPE "N IS"~N N 15= 25. eIeI 115 115* NOTE Any variable, constant, or expression in a TYPE or ASK command must be followed by a comma, semicolon, or carriage return. (l The exclamation mark (!) causes a carriage return and line feed. 9-66 ASK COMMAND The ASK command is normally used in indirect commands to enable the user to input numerical data during the execution of his program. The ASK command is similar to the TYPE command in form, but only single variable names, not expressions, are use:d; and the user-types the values in response to a colon (:) printed by the ASK command. When FOCAL encounters line 11.99 in the above example, it prints a colon and waits for the user to type a value (in any format) and a terminator7 for the first variable. This process continues until all the variables in the ASK command have been given values. The value is assigned to the variable when the user types a terminator; so any time before the terminator is typed, the value can be changed. If the user types back arrow (~ or SHIFT /0) immediately after the value and before he types a terminator, he can then type the correct value and a terminator. :6 :8"7 *TYPE X" ! " Y" !" Z = = = 5.13131313 6.13131313 7.13131313* User typed 5 and RETURN key. User typed 6 and RETURN key. User typed 8, ~, 7 and RETURN key. The ALT MODE key is a special non-spacing terminator which enables the user to have a previously assigned value unchanged. :3 : : 12 *TYPE = = = x .. I" Y.. !" Z 3.13131313 6.13131313 12.13131313* User typed ALT MODE because he did not want to change the value of Y. 7 Terminators are SPACE, comma, ALT MODE, and RETURN keys. If the user types the RUBOUT key, it is ignored. 9-67 Text Output with ASK The ASK command, just as the TYPE command, may be used to print text. Carriage return and line spacing are controlled the same as with the TYPE command (see Data Formats). *ASK "WHAT IS YOUR AGE?"- AGE WHAT IS YOUR AGE?:19 * The word following the text in the command line (AGE, in this example) is the variable. Computational Command SET COMMAND The SET command enables the user to assign a numerical value to a variable and store both the value and the variable. Then, when he uses the variable in an expression, 8 FOCAL automatically substitutes ·the numerical value that the user previously specified: *SET E=2.71828 *SET PI=3.14159 *TYPE "PI TIMES E"I PI*E PI TIMES E= 8.5397* The value of a variable may be changed at any time by another SET command. *SET Al= 3' 2 *SET Al=Al+l *TYPE Al 10.0000* = Control Commands GO OR GOTO COMMAND . The GO command causes FOCAL to go to the lowest numbered line in the program and begin executing the indirect commands. * 1. 1 * 1.3 * 1.5 *GO = SET A= 1 SET B=2 TYPE AlB 1.0000= 2.0000: 8 An expression is a combination of arithmetic operations or functions which may be reduced to a single number by FOCAL. 9-68 In the above example the GO command caused execution to begin at line 1.1. The GOTO command causes FOCAL to go to a specific line in the program and begin executing the indirect commands in ascending line number order. *ERASE * 1. 1 SET A= 1 *1.3 SET B=2 *1.5 TYPE A.. B *GOTO <1.3 = 0.0000= 2'. (iH?J00: :ERASE * In the preceding example, A and B are equal to zero at the start of the program. The ERASE and ERASE ALL commands are used to ensure that all variables are equal to zero until they are assigned a specific value. Since the GOTO command causes program exec:ution to begin at line 1.3, line 1.1 is never executed and A is not set to 1. IF COMMAND The IF command is a conditional command used to transfer program control after a comparison. The normal IF command format IS: IF space (expression) line1, line2, line3 The expression or variable is evaluated, and program control is transferred to the first line number if the value of the expression is less than zero, to the second line number if the value is zero, or to the third line number if the value is greater than zero. The program below transfers control to line number 2.1, 2.3, or 2.5, according to the value of the expression in the IF command. *2.1 TYPE "LESS THAN ZERO"; QUIT *2.3 TYPE "EQUAL TO ZERO"; QUIT *2.5 TYPE "GREATER THAN ZERO"': QUIT *IF <25-25>2.1 .. 2.3 .. 2.5 EQUAL TO ZERO* IF with Less Than Three Line Numbers The IF command format can be altered to transfer program control to one or two lines. For example, if a semicolon or a carriage 9-69 return is immediately after the first line number, control. goes to the first line number if the value of the expression is less than zero. If the value is not less than zero, control goes to the next sequential command. For example: *2.20 IF (X)I.8;TYPE"Q" When line 2.20 is executed, program control goes to line 1.8 if X is less than zero. If Xis not less than zero, Q is typed. If a semicolon or a carriage return follows the second line number, control goes to the first or second line number, depending upon whether the value of the expression is less than zero or equal to zero. If the value is greater than zero, control goes to the next sequential command. For example: *3.19 IF (B)I .. I.9 *3.20 TYPE B If B is less than zero, control goes to line 1. 8; if B equals zero, control goes to 1.9; and if it is greater than zero, control goes to the next sequential command, in this case line 3.20, and the value of B is printed. Arithmetic Comparison with IF Command The IF command can be used with all the arithmetic operations of FOCAL. Example I-Addition: Example 2-Subtraction: * 5. 1 6 I F ( A- 8.) 1 • 6; T Y P E "X" Example 3-Division: *3.10 IF (M/N)5.5 .. 5.6; *3.15 TYPE "GREATER THAN ZERO" Example 4-Multiplication: * 7. 20 I F (P* I ) 8. 1; *7.25 TYPE P*I 9-70 Example 5-Exponentiation: DO COMMAND The DO command is used to make subroutines of single lines or groups of lines. Control is returned to the line following the DO command after the subroutine is executed. *1.1 SET A=I; SET B=2 *1.2 TYPE "STARTING" *1.3 DO 3.2 *2.1 TYPl:; "FINISHED" *3.1 SET A=3; SET B=4 *3.2 TYPE A+B *GO STARTING= 3.0000FINISHED= * If the user types a command such as DO 3, the DO command treats the group of program lines beginning with 3 as a subroutine. Control proceeds in ascending order through the group numbers until the end of the group is reached, or until a RETURN command is executed. Nested DO DO commands may be nested as shown in the following example: * 1 • 1 TYPE "BEGIN" .. ! * 1. 2 DO 2 *1.3 TYPE "END" .. !; QUIT * *2.1 DO 5. 1; TYPE A.. ! *2.2 DO 5.2; TYPE A.. ! *2.3 DO 7.5; TYPE A.. ! * *5. 1 SET A=1 *5.2 SET A=2 * *7.5 SET A=3 *GO BEGIN = 1.0000 = 2.0000 = 3.0000 END * 9-71 The number of nested DO commands is limited only by the amount of core memory available after storage is allocated for program and variables. RETURN COMMAND The RETURN command is used to exit from a DO subroutine. When a RETURN command is encountered during execution of a DO subroutine, the program exists from its subroutine status and returns to the command following the DO command that initiated the subroutine status. QUIT COMMAND When the QUIT command is executed, FOCAL prints an asterisk and retuf11s to j;ommand mode. FOR COMMAND The FOR command is used to set up program loops and iterative procedures. The general command format is: *FOR A *FOR A = B,C,D; commands = B,D; commands The variable A is initialized to the value B, then the command or commands following the semicolon are executed: When the commands have been executed, the value of A is incremented by C and compared to the value of D. If A is less than or equal to D, the command after the semicolon is executed again. This process is repeated until A is greater than D, at which time FOCAL goes to the next sequential line. The command or commands will always be executed at least once. A must be a single variable. B, C, and D may be expressions, variables, or numbers. If the value C is omitted,it is assumed that the increment is one. If C and D are omitted, the FOR command is handled like a SET command and no iteration is performed. A FOR command may be used with a DO command and nested: 9-72 FOR with aDO *ERASE ALL * I. 1 * 1.2 FOR X=I .. I .. 51 DO 2 QUIT **2. 1 TYPE fit *2.2 SET A=X+100 *2.3 TYPE !It *GO X= A= X= A= X= A= X= A= X= A= X" .. X AIt .. A 1.0000 101.0000 2.0000 102.0000 3.0000 103.0000 4.0000 104.0000 5.0000 105.0000* Nested FOR and DO * 1. 1 * 1. 2 *1.5 *1.7 * *3. 1 FOR Z=I .. 3; TYPE A It B C It TYPE ! FOR A= I .. 3J DO 3 QUIT FOR B= I .. 3J DO 4 >I< *4.1 FOR c= I .. 31 *4.2 TYPE *GO A A B C = 1= 1= 1 = 1= = 1= 2= 1 = 1= = 1= 3= 1 = 1= = 2= 1= 1 = 2= = 2= 2= 1 = 2= = 2= 3= 1 = 2= = 3= 1= 1 = 3= = 3=·2= = 3= = 3= = 3= 3= * TYPE % I .. A.. B .. C.. B 1= 2'" 3= 1= 2= 3= 1= 2= ~J= C 2 2 2 2 2 2 2 2 2 = = = = = = = = = A 1= 1= 1= 2= 2= 2= 3= 3= 3= B 1= 2= 3= 1= 2= 3= 1= 2= 3= It It C 3 3 3 3 3 3 3 3 3 Another way of handling the same program is: *1.1 FOR Z=1 .. 3.:TYPE" A 8 C .. *1.2 FOR A=1 .. 3;FOR 13= 1.. 3.: TYPE !;FOR C=1 .. 3JTYPE *0'0 9-73 %~ .. A .. 8 .. C.. " Subscripted Variables Variables may be further identified by subscripts which are enclosed in parentheses immediately following the variables. For example: *SET AB(0)=S *SET AB(I)=10 *SET AB(2)=IS *SET AB(3)=20 *SET AB(4)=2S *SET AB(S)=30 *FOR X=0 I S; TYPE AB(X)I! =S = 0.1E+02 = 0.2E+02 = 0.2E+02 = 0.3E+02 = 0.3E+02 * In the above example, sUbscripts are used to set up an array cal1ed AR. Any element in the array can be represented by a subscript in the range 0 to 5. The first element in an array always has a subscript of O. A sUbscript may be a number, another variable., or an expression. If it is a number, it must be in the range ±2047. In order to be properly represented by the TYPE $ command, subscript numbers must be positive integers in the range from 0 to 99. The TYPE $ command will· print subscripts greater than 99 as two random characters, although their contents will be correct as assigned by the program. COMMENT OR CONTINUE COMMAND The COMMENT or CONTINUE command (abbreviated as C) causes the program line to be ignored by FOCAL. The user may use the C command to insert comments into the program, or he may use the C command line as a. non-executable program step. In either case, program lines beginning with C are skipped wh~n the program is executed. However, comments are printed in response to a WRITE q)mmand. 9-74 *ERASE ALL *1.1 C INITIALIZE VARIABLES * 1.2 SET A= 5 *1.3 SET B=6 * 1. 4 SET C= 7 **2.1 C PERFORM CAL.CULATION *2.2 TYPE A+B+C * Edit Commands WRITE OR WRITE ALL COMMAND The WRITE or WRITE ALL command causes FOCAL to print a program line, a group of lines, or an entire indirect program on the Teletype. *WRITE 2.1 *WRITE 2 *WRITE Print a single line. Print a group of lines. Print an entire program. Once the program is completed, the user may want to save it by putting it on paper tape. The procedure for saving a FOCAL program on-line is as follows: 1. 2. 3. 4. Make sure FOCAL is in command mode. Type WRITE Set low-speed punch to ON position. Type RETURN key. FOCAL will punch the entire program onto the paper tape and simultaneously print it on the Teletype. Whenever the user wants to run, the program he has saved on . paper tape, he does the following: 1. Makes sure FOCAL is in command mode. 2. Puts the program tape in low-speed reader. 3. Switches the low-speed reader to START. The program will be put into core the same as it would if the user were typ~ng it on the Teletype keyboard. When the entire program has been read into core, the user should type CTRL/C since the asterisk printed when the WRITE command is finished is also punched and may be interpreted as a command. CTRL/C ensures that FOCAL returns to command mode. 9-75 ERASE AND ERASE ALL COMMANDS The ERASE command de1etes symbolic names, lines, or groups of lines. . *ERASE 2.2 *ERASE 2 Delete all names defined in symbol table. Delete line 2.2 Delete all lines in group 2. The user can check to see if the line(s) has been deleted by typing the WRITE command after the ERASE command. This is a useful procedure for checking commands and also for obtaining a clean printout of the current program. The ERASE ALL command deletes the entire indirect program. It is good programming practice to type ERASE ALL before starting to type a new program. The ERASE ALL command is generally used only with direct commands because it returns control to command mode upon completion. MODIFY COMMAND The MODIFY command is used to change characters within a line without changing the entire line. The format for MODIFY is: MODIFY line number RETURN key Search character The search character is not printed. After the user has typed the line number, RETURN key, and search character, FOCAL prints the contents of the specified line until it encounters the search character. When the search character is read and printing stops, the user has anyone or more of the following options: 1.. Type new characters in addition to those already printed. 2. Type a form feed (CTRL/L). This causes the· search to proceed to the next occurrence, if any, of the search character. 3. Type CTRL/BELL; The user can then change the search character he specified in the MODIFY com1J1and. 4. Type the RUB OUT key. This causes FOCAL to delete a character, starting with the last character printed and deleting one character to the left each time RUBOUT is typed. 9-76 5. Type the back arrow (~) key. This causes FOCAL to delete everything between the back arrow and the line number. 6. Type the RETURN key. This causes FOCAL to terminate the line at that point, deleting everything to the right. 7. Type the LINE FEED key. This is normalJy done after the user has exercised one or more of the above options. After the user has modified the line, he may type LINE FEED and cause the remainder of the line from the search character to the end to be printed and saved. *7.01 JACK AND BILL W$NT UP THE HILL *MODIFY 7.01 JACK AND B\JILL W$\ENT UP THE HILL In the above example, B was typed as the search character for line 7.01. (Note that the search character did not print.) FOCAL stopped printing when it encountered the search character (B), and the user typed the RUBOUT key ("') to delete the B. Then he typed the correct letter J. Next he typed CTRLjBELL and the $ key to change the search character. FOCAL continued to print the line until the new search character was encountered. The user typed R UBO UT to delete the $ and then typed the correct character (E). He then typed the LINE FEED key and the remainder of the line was printed. CAUTION When any text editing is done. the values in the user's symbol table are reset to zero. If the user defines his symbols in direct statements and then uses a MODIFY command, the values of his symbols are erased and must be redefined. However, if the user defines his symbols by means of indirect statements prior to using a MODIFY command, the values will not be erased because these symbols are not entered in the symbol table until the statements 4efining them are executed. Notice in the example below that the values of A and B were set using direct statements. The use of the MODIFY command reset their values to zero and listed them after the defined symbols. 9-77 *ERASE ALL *SET A=1 *SET B=2 * 1.1 SET C=3 *1.2 SET D=4 *1.3 TYPE A+B+C+D; TYPE !1 TYPE $ *MODIFY 1.1 SET C= 3\5 *GO 107.22 @ 01.10 **MODI FY 1. 1 SET C= 3\5 *GO ::: 9 C@(00)= 5 D8(00)= 4 Aie (0)= 0 B@(00)= 0 * Library Commands In addition to the basic FOCAL commands, there are four special commands to perform the library functions: storing and retrieving data from the system disk. All commands following the LIBRARY command on the same line are ignored. Names of files may be from 1 to 4 characters long. Only alphanumeric characters, letters, and numbers should be used in file names. The library commands, like other FOCAL commands, may be abbreviated. LIBRARY SAVE This command copies the current program into the user's area on disk and gives it the name specified. For e,xample, the command: *L S TRUE will cause the current program to be stored on disk under the name TRUE. The program will also remain in the user's area. LIBRARY CALL This command copies the named program from disk into the user's area. For example, the commands: *L C TRUE *w will cause the program TRUE to be recalled from the disk.into the user's area and listed on the Teletype. Any program currently in 9-78 the user's area will be erased. The program TRUE can then be executed with a GO command. If the LIBRARY CALL command is given a line number and stored, it must have at least one numbered command following it. In this case, the LIBRARY CALL command will cause the named program to be called into the user's area and executed as if GO had been typed. For example: *3.10 L C TRUE *3.11 C If the above commands are included in a program, they w~ll cause TRUE to be brought in and executed at that point. If there are lines beyond 3.11 remaining to be executed, they will be deleted. This procedure allows the user to chain FOCAL programs as in BASIC. LIBRARY DELETE This command deletes the named program from the disk directory. For example, the command: *L D TRUE will remove TRUE from the disk. LIBRARY LIST This command causes the names of all the FOCAL programs stored on the disk to be listed on the Teletype, ten names to a line, followed by the total number of free blocks remaining on the disk. The LIBRARY LIST command removes the contents of the user's area with an ERASE ALL command. ERROR MESSAGES WITH LIBRARY COMMANDS When the . LIBRARY commands are used, five errors are possible. These are also listed iIi the error code summary in Table 9-9 at the end of this section. 9-79 Command ?30.71 Explanation The command appeared to be a LIBRARy command but was not, for example: LIBRARY OPEN No action is taken; the command should be retyped. ?30.<0 Either an unacceptable file name was specified or no name was specified where one was required. ?31.42 The file name specified does not match any name currently in the user's disk directory. This error will only occur with the LIBRARY CALL and LIBRARY DELETE commands. ?31.43 There is already a program with the specified name in the directory. This error will only occur with the LIBRARY SAVE command.· ?31.44 This user's disk directory is full. The current program cannot be saved until others have been deleted. This error will only occur with the LIBRARY SAVE command. Estimating Program Length FOCAL permits approximately 1060 (decimal) locations to be used for the user program and variables without the extended math functions, and approximately 670 locations with the ext~nded functions (sine, cosine, log, exponential, etc.). Since FOCAL requires five locations for each variable stored in the variable table and one location for each two characters of stored program, the approximate length of a program may be determined by the formula: 9-80 C Length of program = 5S + 2 + 2L where S = number of variables C= number of characters in program L = number of lines If the total program area or variable table area becomes too large, FOCAL prints an error message (06.54 or 1-0.: 5). The following routine allows the user to find out how many core locations are left for his use: *ERASE ? 06. 54 *TYPE %4"I*5,,"LOCATIONS LEFT" = 1075LOCATIONS LEFT* (Disregard error code.) * * Debugging USING THE ERROR DIAGNOSTICS Whenever FOCAL detects an illegal command or improbable condition within a user's program, the execution of the program stops and an error message is printed in the form ?XX.XX@GG.ss, where ?XX.XX is the error message and GG.ss is the line at which the error occurred. (See Table 9-9 for the complete list of error messages.) Depending upon the type of error detected, the user may ignore the error message or make program changes before continuing. For example, if the user types CTRL/C to terminate a loop, the error message ?01.00 is printed and program control goes to command mode; so, in this case, the user ignores the message and, types his next command. !fa program stops and the message ?03.05 is printed, the user must examine his program to determine which command line is wrong. In the following program, line 1.3 contains the instruction to transfer to a nonexistent line number. 9-81 *ERASE ALL *1.10 SET A=2; TYP~ "A"IAI! *1.20 SET B=4; TYPE; "B"IBI! *1.30 GOTO 1.01 *1.40 TYPE "A+B"IA+B *GO A= 2 B= 4 ?03.05 @ 01.30 * USING THE TRACE FEATURE The trace feature is used to check the logic in part of a FOCAL program. To imp.lement the trace feature, the user inserts a question mark (?) into a command string at any point. FOCAL prints each succeeding character as it is executed until another question mark is encountered or until the program returns to command mode. For example, the trace feature is used to print parts of 3 lines in the following program: *ERASE ALL * 1 • 1 SET A= 1 *1.2 SET 8=5 *1.3 SET C=3 *1.4 TYPE ?A+B-C?I! *1.5 TYPE ?B+A/C?I! *1.6 TYPE ?B=C/A? A+B-C= B+A/C= 3 5 8=C/A= 2* NOTE The WRITE command disables the trace feature. FOCAL Functions The FOCAL functions improve and simplify arithmetic capabilities. In general, the FOCAL functions may be used anywhere a number or a variable is legal in a mathematical expression. A standard function call consists of three or four letters beginning with the letter F and followed by an expression in parentheses. The FOCAL functions are summarized in Table 9-8. 9-82 The functions must be used with a legal FOCAL command. They cannot be used alone as commands. For example: *SET Z=A+FSQT(FSIN(X» Within a normal range of arguments, at least five significant digits of accuracy may be expected for the trigonometric, exponential, and logarithmic functions. The following functions are available to FOCAL users. SINE FUNCTION (FSIN) The sine function (FSIN) is used to calculate the sine of a user-specified angle in radians. The format for FSIN is: FSIN (angle) *TYPE FSIN(3.14159/4) = 0.7071* The format for calculation the sine of an angle in degrees is: FSIN (degrees *TYPE * 3.14159/180) FSIN(30*3.14159/1R~) 0.5~~~~* COSINE FUNCTION (FCOS) The cosine function is used to calculate the cosine of a userspecified angle in radians. The format for FCOS is: FCOS (angle) *TYPE FCOS(2*3.141592> = 1 .0el00* *TYPE FCOS(.50000> = 0.8776* *TYPE FCOS<45*3. 141592/180> = 0.7071* 9-83 EXPONENTIAL FUNCTION (FEXP) The exponential function. (FEXP) is us.ed to compute e (e=2.71828) to a power specified by the user. The format for FEXP is: FEXP (power) *TYPE FEXP C1 ) 2.7183* *TYPE FEXP(0) = 1.0000* *TYPE FEXPC-1-23456> = 0.0000* = LOGARITHM FUNCTION (FLOG) The logarithm function (FLOG) is used to compute the natural logarithm (loge) of a number specified by the user. The format for FLOG is: FLOG (number) ~TYPE FLOGCl.(0000) = 0.0000* *TYPE FLOG(I.98765) = 0.6870* *TYPE FLOGC2.(65) = 0.7251* The following formulas are useful for finding logarithms to base 10: logloX=10geX/1oge 10=0.434294 10geX ARCTANGENT FUNCTION (FATN) The arctangent function (FATIN) is used to calculate the angle in radians of a user-specified tangent. The format for FATN is: F ATN (tangent) *TYPE FATN C1 • ) 0.7854* *TYPE FATN(.31305) = 0.3034* *TYPE FATN(3. 141592) = 1.2626*· = 9-84 SQUARE ROOT FUNCTION (FSQT) The square root function (FSQT) is used to compute the square root of an expression. The format for FSOT is: FSQT (expression) *TYPE FSQT(4) = 2.00(i"~* *TYPE FSQT(9) = 3.0000* *SET Z=FSQT(144);TYPE Z = 12.0000* ABSOLUTE VALUE FUNCTION (FABS) The absolute value function (FABS) is used to indicate the absolute (positive) value of an expression. The format for FABS IS: FADS (expression) *TYPE FABS(-66) = 66.0000* *TYPE FABS(+23) = 23.0000* *TYPE FABS(-99.05) = 99.0500* SIGN PART FUNCTION (FSGN) The sign part function (FSGN) is used to output the. sign part (+ or -) of a number with a value of 1. FSGN (0) = 1. The format for FSGN is: FSGN (expression) *TYPE FSGN(6-4) = 1.0000* *TYPE FSGN (0) = 1.0000* *TYPE FSGN (-7) . =1.0000* 9-85 INTEGER PART FUNCTION (FITR) The integer part function (FITR) is used to output the integer part of a number. The format for FITR is: FITR (expression) For positive numbers, FITR(X) is the greatest integer function. For negative numbers, FITRC-X) is the integer part of ,-X. The greatest integer function for negative numbers is obtained by FITR(-X)-l. For example: *TYPE FITR(5.2) 5.0000* *TYPE FITR(55.66) = 55.0000* *TPE *TYPE FITR(-4.1) =4.0000* . = RANDOM NUMBER FUNCTION (FRAN2 The random number function (FRAN) is used to generate honstatistical pseudo-random numbers in the range 0.5000 tQ 0.9999. No argument is used with the FRAN function. The format for FRAN is: FRAN ( ) *TYPE FRAN () = 0.7376* *TYPE FRAN ( ) = 0.8959* FRAN can be used to produce a less biased number. For example: *SET A=FRAN() *SET H=A=VITR(A) The value assigned to B is a random number in the range 0.0000 to 0.9999. Focal Output Operations The following is a description of symbols used in FOCAL output operations: , 9-86 To set output format, Symbol I?xplanation TYPE %x.y Where x is the total number of digits, and y is the number of digits to the right of • the decimal point. TYPE %6.3, 123.456 FOCAL prints: =+123.456 To type symbol table, TYPE % Resets output format to floating point. TYPE $ Other statements may not follow on this line. Control Characters FOCAL control characters and their explanations are shown below: % Output format delimiter Carriage return and line feed # Carriage return $ Type symbol table contents ( ) Parentheses [] , Square brackets (mathematics) <> Angle brackets "" Quotation marks (text string) ?? Question marks (trace feature) * Asterisk (high-speed reader input) SPACE key (names) RETURN key (lines) (nonprinting) ALT MODE key (with ASK statement) Comma (expressions) Semicolon (c:ommands and statements) 1 1 9-87 Reading FOCAL P3per Tapes To ensure ~hat FOCAL paper tapes are read without error, they should be read silently. To do this, type tB (CTRL/B) followed by UNDUPLEX just prior to reading the tape. This Monitor command suppresses the printing of the program as it is read. As each line is read, a line feed and FOCAL's asterisk are printed,. indicating that the line is properly stored. After the tape has been completely read, type tB DUPLEX to restore FOCAL to its normal mode. An example is shown below: *ERASE ALL *tBUNDUPLEX * * * * * * **tBDlIPLEX *WRITE ALL C-FOCALI1969 IIIl.(il5 01.06 (ill.10 (ill.2(il 01.30 01.30 01.40 C PROGRAM TO CALCULATE THE HYPOTENUSE OF A C RIGHT TRIANGLE GIVEN THE TWO SIDES ASK "SIDES OF TRIANGLE ARE" AlB SET C=FSQT(At2+Bt2) TYPE "HYPUTNEUSE TYPE "HYPOTENUSE IS" CI! GUTO 1.1 * 9-88 Table 9-7. Command Abbreviation FOCAL Command Summary Example of Form ASK A ASK X, Y,Z COMMENT C COMMENT CONTINUE DO C D C D04.1 D DO 4.0 DA DO ALL ERASE E FOR F ERASE ERASE 2.0 ERASE 2.1 ERASE ALL FOR i=x,y,z; (commands) \0 I 00 \0 Explanation FOCAL prints a colon· for each variable; the user types a value to define each variable. If a line begins with the letter C, the remainder of the line will be ignored. . Dummy lines. Execute line 4.1; return to command following DO command. Execute all group 4 lines; return to command following DO command, or when a RETURN is encountered. Execute all program lines, until a RETURN is encountered. Erases the symbol table. Erases all group 2 lines. Erases line 2.1. Erases all user input. Where the command following is executed at each new value. x=initial value of i. y=value added to i until i is greater than z. Table 9·7 (Cont.). Command GO \0 I \0 o Abbreviation • FOCAL Command Summary Example of Form G GO GO? G? GO? GOTO G GOTO 3.4 IF I IF (X) Ln, Ln, Ln IF (X)Ln, Ln; (commands) IF (X) Ln; (commands) LIBRARY CALL LIBRARY DELETE LIBRARY LIST LIBRARY SAVE LC LD LL LS LIBRARY CALL name LIBRARY DELETE name LIBRARY LIST LIBRARY SAVe name Explanation Starts indirect program at lowest numbered line number. Starts at lowest numbered line number and traces entire indirect program until another ? is encountered, until an error is' encountered, or until completion of program. Starts indirect program (transfers control to line 3.4). Must have argument. ' Where X is a defined identifier, ,a value, or an expressio,n, followed by three line numbers. If X is less than zero, control is transferred to the first line number. If X is equal to zero, control is to the 'second line number. If X is greater than zero; control is to the third line number. Calls stored program from the disk. Removes program from the disk. Prints directory of stored program names. Saves program on the disk. Table 9-7 (Cont.). \0 I \0 FOCAL Command Summary Command Abbreviation MODIFY QUIT RETURN M R MODIFY n QUIT RETURN SET TYPE S T SET A=5/B*C~ TYPEA+B-C; Q ~ Example of Form TYPE A-B, C/E; TYPE "TEXT STRING" WRITE W WA WRITE WRITE ALL WRITE 1.0 WRITE 1.1 Explanation Enables editing of any character on line n. Returns control to the user. Terminates DO subroutines, returning to the original sequenc~. Defines identifiers in the symbol table. Evaluates expression and prints = and result in current output format. Computes and prints each expression separated by commas. Prints text. May be followed by ! to generate carriage return-line feed, or # to generate carriage return. FOCAL prints the entire indirect program. FOCAL prints all group 1 lines. FOCAL prints line 1.1. Table 9·8. FOCAL Functions Interpretation Function Format Square Root FSQT(x) Where x is a positive number or expression greater than zero. Absolute Value FABS(x) FOCAL ignores the sign of x. Sign Part FSGN(x) FOCAL evaluates the SIgn part only, with 1.0000 as integer. Integer Part FITR(x) FOCAL operates on the integer part of x, ignoring any fractional part. Random Number Generator FRAN (x) FOCAL generates a random number. The value of x is ignored. 9Exponential FEXP(x) FOCAL generates e to- the power x. (2.71828 X ) 9Sine FSIN(x) FOCAL generates the sine of x in radians. 9Cosine FCOS(x) FOCAL generates the cosine of x in radians. 9Arctangent FATN(x) FOCAL generates the arctangent of x in radians. 9Logarithm FLOG(x) FOCAL generates loge (x). 9 These are extended functions and may be chosen or deleted when FOCAL is loaded. 9-92 Table 9-9. Message ?OO.OO ?OO.OO ?01.40 ?01.78 ?01.96 ?01.:5 ?01.;4 ?02.32 ?02.52 ?02.79 ?03.05 ?03.28 ?04.39 ?04.52 ?04.60 ?04.:3 ?05.48 ?06.06 ?06.54 ?07.22 ?07.38 ?07.:9 ?07.;6 ?08.47 ?09.11 ?10.:5 ?11.35 ?20.34 ?23.36 ?26.99 ?28.73 ?30.05 ?31.<7 ?30.71 ?30.<0 ?31.42 ?31.43 ?31.44 FOCAL Error Messages Explanation Manual start gjven from console. Interrupt from keyboard via CTRLI C. Illegal step or line number used. Group number is too large. Double periods found in a line number. Line number is too large. Group zero is an illegal line number. Nonexistent group referenced by DO. Nonexistent line referenced by DO. Storage was filled by push-down list. Nonexistent line used after GOTO or IF. Illegal command used. Left of= in error in FOR or SET. Excess right terminators encountered. Illegal terminator in FOR command. Missing argument in display command. Bad argument to MODIFY. Illegal use of function or number. Storage is filled by variables. Operator missing in expression or double E. No operator used before parenthesis. No argument given after function call. Illegal function name or double operators. Parentheses do not match. Bad argument in ERASE. Storage was filled by text. Input buffer has overflowed. Logarithm of zero requested. Literal number is too large. Exponent is too large or negative. Division by zero requested. Imaginary square roots required. Illegal character, unavailable command, or unavailable function used. Undefined library command. Bad argument or missing argument to library command. No such name in library directory. Attempt to enter a duplicate name in the directory. Library directory is full. 9-93 9-94 FORTRAN-D FORTRAN-D compiles an,d runs programs written in the PDP-8 version of FOR~RAN II. Programs (usually created and stored with the Symbolic Editor) are compiled in a single pass and executed (automatically) immediately following compilation. Calling FORTRAN-D To use FORTRAN-D, type: .R FORT FORTRAN requests the name of the input file, i.e., the file containing the FORTRAN program to be compiled and run. The user responds with the file name and the RETURN key. FORTRAN then requests the name of an output file in which to store the compiled version of the program. For normal usage, just the RETURN key need by typed. FORTRAN places the compiled code in a file of its own, then proceeds to run the program. . If a file name is entered for output, FORTRAN creates a permanent file in which the compiled binary program is saved. It is then possible to rerun this program without recompiling it. To run an already compiled program, call the FORTRAN operating system directly by typing: .R FOSL FOSL requests the name of an input file. Enter the name of the file containing the compiled binary. For example, if the user types: .R FORT INPUT:MTRIX OUTPUT: FORTRAN compiles and executes the program MTRIX but does not save the compiled binary. FORTRAN compiles and executes the program MTRIX and 9-95 then leaves the compiled. binary in the file named. BMTRIX when the user types: .R FORT INPUT:MTR1X OUTPUT:BMT~lX The FORTRAN binary program BMTRIX is executed without first being compiled when the user types: .R FCiSL INPIJT:BMTRIX All FORTRAN programs return to the Monitor when they have completed execution. Using FORTRAN-D Differing versions of PDP-8 FORTRAN offer slightly different features. FORTRAN-D differs in the way it is called into use (described above), and in its more powerful I/O capability (described below). FORTRAN-D allows three data formats: I E A Integer format Exponential format Alpha format, ASCII value of a character is stored as an integer value. The standar~ device for READ and WRITE statements is the Teletype, which is assigned device code 1. Because the Teletype is so frequently ~sed, FORTRAN-D includes two special input/ output instructions, ACCEPT and TYPE. These instructions imply use of the Teletype; therefore, the device code need not be specified. ACCEPT is especially convenient if data is to be entered. at the keyboard because this instruction automatically supplies a line fe·ed when the RETURN key is typed. Also, the user can correct an erroneously typed value by striking the RUBOUT key. A FORTRAN-D program can also utilize the high-speed reader . and punch for I/O. These devices are assigned code 2. Because the high-speed reader and punch are shared by all users, it is necessary to assign them if they are to be used. Assign the appropriate devices and mount tapes in the reader before running FORTRAN-D. An 9-96 automatic DEASSIGN is performed by FORTRAN before it returns to the Monitor; therefore, the user must reassign the devices before each run. FORTRAN.;D also allows programs to read and write data files on the disk. These data files are completely separate from the program files. Data files are read and written by standard READ and WRITE statements within the FORTRAN-D program. The device code for the disk is 3. Because programs using the disk are treated differently by FORT (the FORTRAN-D compiler), it is necessary to identify programs which use the disk. These programs are identified by a DEFINE DISK statement as the first statement in any such FORTRAN-D program including a READ or WRITE statement with device code 3. Just as FORT itself must ask for the name of its input and output files, so must a FORTRAN program ask for the names of its disk files. FORTRAN-D programs do this by typing INPUT: and OUTPUT: a second time. The user responds by typing the name of the files to be read or written by the program. FORTRAN-D asks for both input and output for all programs which include a DEFINE DISK statement. If only input (or output) is to be used, the user responds to the other by typing the RETURN key. Line Format FORTRAN programs consist of a series of lines, each a string of 72 characters or less (the width of the Teletype paper from margin to margin). Each line contains two fields: the first, which begins at the left margin, is an identification field; the second contains the statement field. Termination of a line is indicated to the computer by a carriage return, accomplished by typing the RETURN key. The identification field can be blank and extends from the lefthand margin up to and including a semicolon character. This field can contain one of the following types 'Of identification: 1. A Statement number. This number, which can be any positive integer from 1 to 2047 inclusive, identifies the statement on that line for reference by other parts of the program. Statement numbers are used for program control or to assist the programmer in identifying segments of his program. 9-97 2. The letter,. C. This identifies the comment. remaind~r of the line as a Although the identification field may be left blank, it cannot be omitted entirely. The statement field begins immediately after a blank space and extends through the next carriage return. A sample FORTRAN program is shown below: C 5 10 30 32 33 35 200 300 400 THIS PROGRAM CALCULATES FACTORIALS TYPE 200 ACCEPT 300#N I FACT= 1 IF (N-I> 5 1 32#33 TYPE 400#N#IFACT GO TO 10 DO 35 l=l#N IFACT=IFACT*I CONTINUE GO TO 32 FOR.'1AT (1# "PLEASE TYPE A POS I T I VE NUMBER" # I ) FORMAT (I) FORMAT (/# 1#" FACTORIAL IS·· .. IFACT) END FORTRAN source programs are generated using the Symbolic Editor Program. The Editor will facilitate formatting lines by use of a tab character, .permittingautomatic movement to an indented second field. STATE~ENT NUMBERS Each statement cart have a positive, nonzero integer (0-2047) as its number. The statement number is used to reference that par. ticular statement elsewhere in a program. A statement number consists of one to four digits beginning at the left hand margin and is followed by a semicolon. Statement numbers can be assigned nonsequentially; however, no two statements can have the same number. There must be no more than 40 statement numbers in a given program, and they must have a value of 2047 (decimal) or less. STATEMENT CONTINUATION CHARACTER Frequently, a statement is too long to fit on one line. If the character single quote (') appears as the last character of a line before the carriage return, the next line ~s treated as a continuation of the preceding statement. A statement may be continued on as many lines as necessary to complete it, but the maximum number of 9-98 * characters in the statement cannot exceed 128 (about two formatted lines). For example: l~ A=H**2-(4.*A*C/(B**2+1.5*A*C»*4.3' ~B**2+«SQTF(C)*SQTF(D»/(B**2+1.5*A*C» is e:quivalent to the formula: A=B2- - Although the continuation character, ('), allows a single statement to extend over two or more lines, no more than one statement can be written on one line. }'ORTRAN Statements FORTRAN statements are of several types with various functions distinguished as follows: 1. Comment statements allow a programmer to insert notes within the program. 2. Arithmetic statements resemble algebraic formulas. They define calculations to be performed. 3. Control statements govern the sequence of statement execution within a program. These statements reference program line numbers. 4. Specification statements allocate data storage and specify input/ output formats. 5. Input/output statements control the transfer of information into and out of the computer. COMMENT STATEMENTS The character C, at the left margin of a line, designates that line as a comment line. A comment has no effect upon the compilation process but can serve as a guide to program logic for later debugging, etc. There is no limit to the number of comment lines which can appear in a given program. A comment cannot be continued by use of the continuation character, ('), but must be continued in a second comment statement. For example: C C THIS IS AN EXAMPL~ OF A COMMENT 9-99 CHARACTER SET The following characters are used in the FORTRAN language: 1. The alphabetic characters, A through Z. 2. The numeric characters, 0 through 9. 3. The control characters: semicolon CR carriage return period LF line feed single quote ( left parenthesis right p"arenthesis " double quote ) comma 4. The operators: ** exponentiation / division + addition * multiplication replacement subtraction All other characters are ignored by the Compiler except as Hollerith information found in FORMAT statements (where all Teletype chara(?ters are legal). The SPACE character has no grammatical function (it is not a delimiter) except in FORMAT stat~ments and can be used freely to make a program easier to read. CONSTANTS Constants are explicit numeric values appearing in statements. Two types of constants, integer and real, are permitted in FORTRAN. Integer Constants Integer (fixed-point) constants are represented by a string of one to four decimal digits~ written with an optional sign and without a decimal point. An integer constant must fall within the' range ±2047. For example: 47 +47 ( + sign is optional) -2 0434 -0 (leading zeros are ignored) (same as zero) 9-100 Real Constants Real constants are represented by a digit string, an explicit decimal point, and are written with an optional sign. 1o Real constants can also be written in exponential notation with an integer exponent to denote a power of ten (i.e., 7.2 x loa is written 7.2E+3). A real constant may consist of any number of digits but only the leftmost six digits appear in the compiled program. Real constants must , fall within the range 0.14 x 10- 38 to 1.7 X 1038 • For example: +4.50 4.50 -23.09 --3.0E14 7 (plus sign is optional) (same as -3.0 x 1014 ) (saved as 7.00000, not the same as the integer. 7) Fixed and Floating-Point Representation The diffe.r:ence between integers and real numbers in FORTRAN is the way in which each is represented in core memory. Both types of numbers are' converted to binary to be stored in the computer. A FORTRAN integer is stored in one 12-bit computer word. The sign of the number is kept in the high-order bit and the magnitUde (the integer value) in the remaining 11 bits. This representation, shown schematically in Figure 2-1,. is called fixed point, because the decimal point is always considered to be to the right of the rightmost digit. A FORTRAN integer may not exceed the range of ± 2047. All integers greater than ± 2047 are taken moaulo 2048 (i.e., 2049 is considered to be 1; 4099, to be 3). The floating-point format consists of two parts: an exponent (or c:haracteristic) and a mantissa. The mantissa is a binary fraction with the radix point assumed to be to the left of bit one of the mantissa. The mantissa is always normalized; meaning it is stored with leading zeros eliminated so that the leftmost bit is always significant. The exponent represents the power of two by which the mantissa is multiplied to obtain the true value of the ----Where a number is to be identified as being negative, a minus sign (-) 10 must be used. A plus sign (+) is optional; with no sign, a number is considered positive. 9-101 number for use in computation. The. exponent and mantissa are both stored in two's complement form. SIGN ~ I MAGNITUDE o Q. 11 FORTRAN INTEGER SIGN OF EXPONENT ~ EXPONENT I. 11 SIGN OF 0 MANTISSA ........... 2.,~--~------------M-A-N-T-IS-S-A----------------~ o 3. I~ 11 ________________M_A_N_T_IS_S~A ________________ ~ b. FLOATING POINT Figure 9-1. Number Represe!ltation Users should not attempt to input floating point constants of mor~ than six decimal digits, either in the FORTRAN source program or via the run-time ACCEPT statement. Integers cannot appear in floating-point expressions except as exponent or subscripts. Some examples of illegal and legal expressions are as follows: Expression Legal Mode A(I)*B(J)**2 I(M) *K(N) 16.*B (K+16)*3 A**(1+2)/B 8*A 4.*1 I+D Yes Yes Yes Yes . Yes No No No Floating Fixed Floating Fixed Floating VARIABLES A variable is a symbol whose value may change during execution of a program. The name of a variable consists of one or more alphanumeric characters, the first of which must be alphabetic. 9-102 Only the first four characters are interpreted as defining the variable name; the rest are ignored. For example, the name EPSILON would be interpreted by the Compiler as EPSI. Since only the first four characters are meaningful, the two names XSUM1 and XSUM2 would be considered identical. Spaces, as mentioned earlier, are ignored. The name EX IT represents one variable, not two. Thus, EX IT, EXIT, or even EXI T are identical names as far as the Compiler is. concerned, and they all refer to the same numerical quantity. The type (or mode) of a variable (integer or real) is determined by the first letter of the variable name. 1. Integer variables begin with the letters: I, J, K, L, M, or N 2. Real variables begin with any letter other than those above. Variables of each type may be either scalar or array variables, as explained below. Integer Variables Integer variables undergo arithmetic calculations with automatic truncation of any fractional part. For example, if the current value of K is 5 and the current value of J is 9, then J /K would yield 1 as a result. Real Variables A variable is real when its name begins with any character other than I, J, K, L, M, or N. Real variables undergo no truncation in arithmetic calculations. Real variables may be converted to integer variables, and vice-versa, across an equal sign. Scalar Variables A scalar variable, which may be either integer or real, represents a single number, as opposed to an array (below)- representing a collection of numbers. For example, the following are scalar variables: LM 02 A TOT AL (considered to be TOT A by the computer) J 9-103 Array Variables An array variable represents a single element of a one-dimensional array of quantities. The variable is denoted by the array name followed by a subscript enclosed in parentheses. The subscript may be any combination of integer variables and integer constants forming a valid expression, as follows: " (V) (V+C) (V-C) (C) where V is a fixed point (integer) variable, and C is a fixed-point constant (not equal to 0). The value of the expression in parentheses determines the referenced array element. For example, the row matrix, AI, would be represented by the subscripted variable A ( 1 ), and the second element in the row would be represented by A(2). Examples of array variables are: Legal Forms Illegal Forms A(2+1) Y(1) A(K+2) B(C) DIMENSION STATEMENT· Array names must be identified as such to the FORTRAN Compiler. Two items of information must be provided in any program usmg arrays: 1. Which are the subscripted variables? . 2. What is the maximum value of the subscript?· (When an array is used, a certain amount of storage space must be set aside by the Compiler for the array elements.) This information is provided by the DIMENSION statement: where A and B are array names, and the integer constants 20 and· 15 ar:e the maximum dimensions of each subscript. The rules governing the use of array variables and the DIMENSION statement are as follows: 1. All array names must appear in a DIMENSION statement. 9-104 2. DIMENSION statements may be used more than once and may appear anywhere in the FORTRAN program, provided that the DIMENSION of an array appears before any statement which references the array. 3. Any number of arrays can be defined in a single DIMENSION statement. 4. For notes on how to implement double subscripts (i.e., A(I,J», see the section on Implementation Notes. Array variables may be either integer or real, depending upon the initial letter of the array name. DIMENSION LIST(3~)~MAT(1~~)~REGR(2~) In the statement above; the names LIST and MAT designate integer arrays; that is, all elements of both arrays are integers. The third name, REGR, designates a floating point, or real array. The first array is a list containing a maximum of 30 elements; the second array has a maximum of 100 elements. The third array is a floating-point array and there are a maximum of 20 elements in it. Not all elements of an array need be used in the course of a program; but, if using the DIMENSION statement the variable LIST (3.1) could not be referenced without the occurrence of an error message. FORTRAN Arithmetic ARITHMETIC OPERATORS The arithmetic operators are symbols representing the common arithmetic operations. The important rule about operators in the FOR TRAN arithmetic expressions is that: every operation must be explicitly represerit'ed by an operator. In particular, the multiplication sign must never be omitted. A symbol for exponentiation is also provided since superscript notation is not available on a Teletype. Normally, a FORTRAN expression is evaluated from left to right. like an algebraic formula. There are exceptions to this rule; certain operations are always performed before others, regardless of order. This priority of evaluation is as follows: 9-105 1. 2. 3. 4. 5. ( ) Expressions within parentheses Unary minus Exponentiation Multiplication or Division Addition or Subtraction ** * or I +or- The term "binding strength" is frequently used to refer to the relative position of an operator in a table such as the one above, which is in order of descending binding strength. Thus, exponentiation has a greater binding strength than addition, and multiplicat;on and division have equal binding strength. The unary minus is the arithmetic operator which indicates that a quantity is less than zero, such as -53, -K, -12.3. It refers only to the constant or variable which it precedes as opposed to a binary operator, which refers to operands on either side of itself as In the expression A-B. A unary minus is recognized by the fact that it is preceded by another operator, not by an operand. For example: A + B**-2 I C-D The first minus sign (indicating a negative exponent) is unary; the second (indicating subtraction) is binary. At present it is not possible to raise an integer variable or integer constant to an integer value with FORTRAN-D. Only real values can be raised to integer powers. The left-to-right rule can be stated more precisely: A sequence of operations of equal binding streng~h is evaluated from left to right. To change the order of evaluation, parentheses are required. Thus. the expression A--B*C is evaluated as A-.(B*C), not (A-B)*C. Examples of the left-to-right rule follow: , The expression: Is evaluated as: (A/B)*C (A/B)/C (A**B)**C A/B*C AlBIA A**B**C 'Use of Parentheses Note the use of parentheses in the example below. They are used to enclose the subscript of the dimensional variable, D; to 9-106 , specify the order of operations of the expression involving A, B, and C; and to enclose the argument of the function SINF. D(I) + (A+B)**C + SINF (X) In algebra there are several devices, such as square brackets [ ], rococo brackets 1 etc., for distinguishing between levels when expressions are nested. In FORTRAN, only the parentheses are available, so the programmer must be especially careful to pair parentheses properly. In any given expression, the number of left parentheses must be equal to the number of right parentheses, An easy way to check the proper pairing of parentheses is by counting out, illustrated in the following example: (Z+AM* (AM+1.) )/( (X**2+C**2)*P) 1 2 10 12 1 0 The procedure is this: Reading the expression from left to right, assign the number, 1, to the first left par~nthesis (if you encounter a right parenthesis first, the expression is already wrong). Increase the count by one each time a left parenthesis is read, and decrease the count by one when a right parenthesis is found. When the expression has been completely scanned, the count should be zero. If it becomes less than zero during the scanning, there are too many right parentheses. If it is greater than zero at the end of an exp.ression, there are excess left parentheses. r, ARITHMETIC EXPRESSIONS An algebraic formula such as: Sa + 4b(x2 - xu) represents a relationship between symbols (a, b, x, xtJ and constants (S, 4, 2) indicated by mathematical functions and arithmetic operators (+, -, multiplication, exponentiation). This same formula can be written as a FORTRAN arithmetic expression _with very little change in appearance: (S.*A + 4.*B* (X**2 - XZRO) The construction of both expression~ is the same; the differences are notational. Elements of an arithmetic expression are of four types: constants, variables, operators, and functions. An expression may consist of a single constant or variable or a string of constants, variables, and functions connected by operators. 9-107 Examples of arithmetic expressions follow; each expression is shown with its corresponding algebraic form. Algebraic Expression FORTRAN Expression 2v'X 3 2. *SQTF(X) /3. 3x1l" -2(x+y) 4.25 (3.*X*PI-2.* (X+Y) ) /4.25 a-sin 0 +2a cos(O -45) A *SINF(THTA) +2. * A *COSF(THTA-0.78540) (A**2-B**2) / (A+B)**2 ARITHMETIC STATEMENTS The arithmetic statement relates a variable, V, to an arithmetic expression, E, by means of the replacement operator, (=): V-E Such a statement looks like a mathematical equation, but is treated differently. The equal sign is interpreted in a special sense; it does not represent a relationship between left and right members, but rather specifies an operation to be performed. In an arithmetic statement, the value of the expression to the right of the equal sign replaces the value of the variable on the left. This means that the value of the left-hand variable will change after the execution of an arithmetic statement. A few illustrations of arithmetic statements are given below: 1. 2. 3. 4. 5. 6. VMAX=VO+AXT T = 2. *PI*SQTF( l./G) PI = 3.14159 THTA= OMGA + ALPH*T* *2/2. MIN=MINO INDX = INDX + 2- With the interpretation of the equal sign stated above, Example 6 becomes meaningful as an arithmetic statement. If, for example, the value of INDX is 40 before the statement is executed, its value will be 42 after execution. 9-108 In arithmetic expressions, a binary operator requires an operand on its left and right. The equal sign of an arithmetic statement is also considered to be a binary operator, as demonstrated in the following revised table of operators: Operator Use Interpretation - (Unary) ** * -A A**B A*B I AlB + - (Binary) A+B A-B A=B negate A raise A to the B th power multiply A by B divide A by B add B to A subtract B from A replace the value of A with the value of B The replacement operator is considered to have the lowest binding strength of all the operators~ therefore, the expression on the right is evaluated before the operation indicated by the egual sign is performed. Multiple Replacement An important result of treating the equal sign as an operator is that operations can be performed in sequence. Just as there can be a series of additions, A+ B+C, there can also be· a series of replacements: A=B=C=D Notice that because the operand to the left of an equal sign must be a variable, only the rightmost operand, represented by D in the example, may be an arithmetic expression. The statement is interpreted as follows: "Let the value of the expression D replace the value of the variable C, which then replaces the value of the variable B" and so on. In other words, the value of the rightmost expression is given to each of the variables in the string to the left. A common use for this construction IS In setting up initial values: XZRO=SZRO=AXRO=O T=Tl =T2=T3=60 P=FP=4. *ATM-AK 9-109 Only simple variables will compile correctly in this manner. For example, statements of the type A( 1) =A(2) =R( 1) =0.123 are not allowed and will not compile properly (subscripted variables may' not be used in multiple replacement statements). Multiple replacement done in a single statement must not contain mixed mode variables. That is: compiles correctly compiles correctly does not compile correctly A=B=C=10 1=1-7 A=J=-7 Mode Conversion Another useful result in treating the equ?l sign as an operator is that the value of an expression on the right of an equal sign is converted to the mode of the left-hand variable, if necessary, before storage. For example: A=lVl Stores the value of M as a floating-point number in A K=B Stores the value of B (truncated) as an integer number in K = 1f B = 4.75 and M 7, the conversion above will result in the foHowing values being assigned: A = 7.00000 K=4 FUNCTIONS Functions are used in FORTRAN just as they are in ordinary mathematics, acting as variables in arithmetic expressions. The function name represents a call to a special subprogram which performs the calculations to evaluate the function; the result is used in the computation of the expression in which the function occurs. FORTRAN-D provides several mathematical functions: square root, sine, cosine, arctangent, exponentiation, and natural logarithm. The argument of a function can be a simple variable, a· subscripted variable, or an expression. The argument must be in a . floating-point format. FORTRAN recognizes a symbol as a function when it is a predefined symbol ending in F and followed by an argume~t enclosed in parentheses (if the F is' missing from the term, the symbol is treated as a subscripted variable). The argument of a function can consist of another function or groups of functions. For example, the expression: 9-110 LOGF(SINF(X/2)/COSF(X/2) ) is equivalent to log tan( ~) FORTRAN-D contains the following functions: Meaning Function Name SQTF(X) SINF(X) COSF(X) ATNF(X) EXPF(X) LOGF(X) Square root of X Sine of X, where X is expressed in radians Cosine of X, where X is expressed in radians Arctangent X, where X is expressed in radians Exponential of X Logarithm of X Program Control In this section, FORTRAN statements are discussed in the context of program sequences. FORTRAN statements are executed in the order in which they are written unless instructions are given to the c,ontrary by use of the program control statements. These statements allow the programmer to alter sequence, repeat sections, suspend operations, or bring the program to a complete halt. END STATEMENT END occurs alone on a line and indicates the physical end of the program to the FORTRAN Compiler. It can be preceded by a line number. Every program must contain an END statement. STOP STATEMENT A program arranged so that the last written statement is the final and only stopping place needs no other terminating indication; the END statement automatically determines the final halt. Many programs, however, contain loops and .branches so that the last executed statement can be somewhere in the middle of the written program. Frequently there is more than one stopping point. Such terminations are indicated by the STOP statement. This causes a final, complete halt; no further computation is possible, although the program may be completely restarted from the beginning. 9-111 When a STOP is encountered during program execution, the system signifies that a STOP has occurred by outputting an exclamation point (!) to the Teletype or high-speed punch, whichever is being used as the output device. PAUSE STATEMENT The STOP statement prevents further coniputation after it has been executed. There is a way, however, to suspend operation for a time and then restart the program. This procedure is frequently necessary when the user must do such tasks as loading and unloading paper tapes in the middle of a program. This kind of temporary halt is provided by the PAUSE statement. The PAUSE statement halts the program and returns control to the EduSystem 50 Monitor. The user may then perform any necessary manipulations and restart the program by typing the Monitor command START. GO TO STATEMENT There are various ways in which program flow may be directed. As shown schematically in Figure 9-2, a program may be a straightline sequence (1), or it may branch to an entirely different sequence (2), return to an earlier point. (3), or skip to a later point ( 4). The blocks represent sections of FORTRAN code. The lines indicate the path which control takes as the program executes. Figure 9-2. Program Flow 9-112 All of these branches can be performed in several ways, the simplest of which uses the statement: GOTOn where n is a statement number in the program. The use of this statement is described in the following example, which also illustrates the construction of a loop, the name given to program branches of the type shown in the example above. EXA1~PLE OF INTEGER SUMMATION In the following example, the sum of successive integers is accumulated by repeated addition. The main computation is provided by the three-instruction loop beginning with Statement 2. The statements preceding this loop provide the starting conditions, called the initialization. The partial sum is set to zero, and the first integer is given the value of one. The loop then adds the integer value to the partial sum, increments the integer, and repeats the operation. C 2 SUM DF FIRST N INTEGERS BY ITERATION KSUM=0 INUM=! KSUM=INUM+KSUM INUM=INUM+l GO TO 2 END IF STATEMENT The program shown in the preceding example performs the required computation, but note that the loop is endless. To get out of th{: loop the user must know when to stop the iteration and what to do afterwards. The IF statement fills both requirements. It has the following form: IF(E) K,L,M where E is any variable name, arithmetic expression, or arithmetic statement, and K, L. and M are statement numbers. The statement :is interpreted in this way: If the value of E E E < 0, GO TO statement K = 0, GO TO statement L > 0, GO TO statement M 9-113 Thus, the IF statement decides when to stop a loop by evaluating an expression. It also provides program branch choices with the transfer of control, depending on the results of the evaluation of E. For example: C 2 3 SUM OF THE FIRST 50 INTEGERS KSUt1= 0 INUM= 1 KSUM=INUM+KSUM INUM=INUM+l IF (INUM-50)2 1 2 1 3 STOP END In the foregoing example, the initialization and mC}.in loop are the same ~s for the example in Figure 9-2 except that the GO TO staterpent of the earlier program has been replaced by an IF statement. The IF statement says., "if the value of the variable INUM is less than, or equal to, 50 (which is the same as saying that if the value of the expression INUM-50 is less than or equal to zero), transfer control to Statement 2 and continue the computation. If the value is greater than 50, stop." (See the section on Implementation Notes for an alternate solution.) A loop may also be used to compute a series of values. The following illustration is an example of a program to generate terms in the Fibonacci series of integers, in which each succeeding member of the series is the sum of the two members preceding it: J C 5 6 10 FIBONACCI SER'IESI 100 TERMS DIMENSION FIB(100) FIBC1>=1.0 FIB(2)=1.0 K=3 FIB(K)=FIB(K-l)+FIBCK-2) K=K+ 1 IF CK-100)515iI0 STOP END In this program, the initialization includes a DIMENSION statement which reserves spa<;e in storage, and two statements which provide the starting values necessary to generate the series. Each time a term is computed, the subscript is incremented so 9-114 that each succeeding term is stored in the next location of the table. As soon as the subscript is greater than 100, the calculation stops. DO LOOPS Iterative procedures such as the program loop are so common that a more concise way of presenting them is warranted. Three statements are required to initialize the subscript, increment it, and test for termination. The following type of statement combines all these functions: DO n l=Kl, K2, K3 here n is a statement number, I is a simple (non-subscripted) integer variable, and Kl, K2, and K3 are simple integer variables or integer constants which provide, in order, the initial value to which 1 is set, the maximum value of I for which the loop will be executed, and the amount by which 1 is incremented at each return to the beginning of the loop. If K3 is omitted from the statement it is assumed to be one (1). Statement n must be a CONTINUE statement. C . 5 FIBONACCI SERIES~ 11210 TERMS DIMENSION FIBCletet) FIBCl)=l.f2I FIB(2)=1.0 DO 5 K=3~ If2lf21 FIB(K)=FIB(K-l)+FlB{K-2> CONTINUE STOP END In words, the DO statement says "Execute all statements through Statement 5 with K=3; when Statement 5 is encountered, perform the following test: If K + 1 is less than or equal to 100, set K:=K + 1 and continue the program by executing the first statement after the DO statement. If K + 1 is greater than 100, the next sequential statement following Statement 5 is executed." DO loops are commonly used in computations with subscripted variables. In such cases, it is usually necessary to perform the loops within loops. Such nesting of DO loops is permitted In FORTRAN. 9-115 C C 5 C 10 FIRST LOOP DO 10 1= 1" 20 X(I)=0 NESTED LOOP FOLLOWS DO 5 K=2" 40",2 X(I)=X(I)+B(K)-Z(K»**2 CONTINUE END OF NESTED LOOP A(I)=X(I)**2+C(I) CONTINUE Sequential elements in the array X(l) are formed by summing the square of the difference of every second element in the Band Z arrays. Then the array A(l) is formed by summing every element in the array C ( 1 ). and the square of every element in the array X(l). The algebraic expression for the loop is as follows: Ai=X1 2 :- for i=1,2,3, ... 20 Ci 40 where Xi= ~ (b k -zk )2 k=2 for k=2,4,6, .. .40 The following three rules about DO loops must be observed: 1. DO loops may be nested, but they may not overlap. Nested loops may end on the same statement, but an inner loop may not extend beyond the last statement of an outer loop. Figures 9-3 schematically illustrates permitted and forbidden arrangements. DOCE DO DO DO CONTINUE CONTINUE DO DO DO CONTINUE ~ DO CONTINUE . . CONTINUE ILLEGAL NESTING TECHNIQUES [G CONTINUE LEGAL NESTING TECHNIQUES Figure 9-3. Legal and Illegal Nesting Techniques 9-116 2. If the user transfers into the range of a DO loop, the value to be incremented (1, for example) is not autolllatically initialized as specified in the DO statement. Transferring into the range of a DO loop is allowed as long as: a. Control was originally transferred out of the DO loop by some means other than by completing it. b. Incrementing and testing start with the current value of I at the time control returns to the loop. 3. A DO loop must end on a CONTINUE statement. DO DO CONTINUE DO CONTINUE CONTI NUE L - - , - - _ CONTINUE ACCEPTABLE BRANCHING Figure 9-4. ILLEGAL . BRANCH ING Program Branching in DO Loops CONTINUE Statement A special statement (CONTINUE) is provided which is not an ex~cutable statement itself, but provides a termination for all DO loops. DO loops must be terminated on a CONTINUE statement. The CONTINUE statement is identified with the line number given in the DO statement. For example: 37 42 IrO 37 MM= 11 1 fIj IF (X(MM)-10f1j.) CONTINUE GO TO Iflj2 STOP 37 1 42 1 37 9-117 A single CONTINUE statement can be referenced more than once in a single DO loop or can serve as the terminating line for : two or more nested DO loops. COMPUTED GO TO The GO TO statement previously described is unconditional and provides no alternatives. The IF statement offers a maximum of three branch points. One way of providing a greater number of alternatives is by using the computed GO TO, which has the following form: GO TO (Kl,K2,K3, ... ,Kn),J where KII is statement number, and J is a simple integer variable, which takes on values of 1,2,3, ... n according to the results of some previous computation. For example: IVAR=14*J/2+K GO TO (5.1 7.1 5.1 7.1 5.1 7.1 10).1 I VAR causes a branch to Statement 5 when IV AR= 1, 3, or 5; to Statement 7 when IV AR=2, 4, or 6; and to Statement 10 when IVAR=7. When IVAR is less than 1 or greater than 7, the next sequential statement after the GO TO is executed. FORTRAN Input/ Output So far, we 'have assumed that all information (programs, data, and sub-programs) is in memory, withoul regard to how it is put there. Programs are read by a special loader, but the programmer is responsible for the input of data and the output of results by including directions for I/O operations in his program. For any input/output procedure, several questions must be answered: 1. In which direction is the data going? The data coming in is being read into memory; information going out is being written on whatever medium is specified. 2. Which device is being used? Information may be transferred between core and whatever input/output devices are available; each 1/0 operation must specify the device involved. 9-118 3. Where in core memory is the data coming from or going to? The amount of oata and its location in the computer storage must be specified. 4. In what mode is the data represented? In addition to floating and fixed-point modes for numeric data, there is the Hollerith mode for transferring alphanumeric or text information. 5. What is the arrangement of the data? The format of incoming or outgoing data must be specified. For every data transfer between core memory and an external device, two statements are required to provide all of the information listed above. The first three items are specified by the input/ output statement, and the last two items are determined by the FORMAT statement. DAT A FORMATS . FORTRAN-D provides for communication of data to and from a program in the fol1owing ways: ASCII Coded Data The Teletype can be used to transfer data to the program either via the keyboard (in which case the user types the data) or from previously punched paper tape (read via the Teletype tape reader). Data can be output from a program to the Teletype, producing a printed copy with or without the corresponding punched paper tape. The high-speed reader and punch can also be used for data transfer via punched paper tape. No printed copy is made when output is to the high-speed punch. Binary.Coded Data Disk and DECtape can also be used for data transfer, in which case the data is stored as a core image on tape in 128-word blocks of 12-bit binary words. Integers are read and written as single 12-bit words, floating-point numbers as three words. Alphanumeric information is transmitted as 8-bit ASCII coded characters right-justified in 12-bit words (one character per word). INPUT/OUTPUT STATEMENTS Input/Output statements control the transfer of information. As illustrated below, I/O statements consist of three basic items of information: the device being accessed and the direction of transfer, 9-119 the number of the FORMAT statement controlling the arrangement of data, and the list of variable names whose values are to be output or changed by new input. . NOTE There is a restriction on subscripted variables when used with I/O statements. Subscripts to be used with· I/O statements must be of the form: LL" where each L is a letter, and not of the form LD, where D is a digit. For example: DO 10 Ll=1,4 ACCEPT 7,A(L1) will not store information correctly. 'The statement should read: DO 10 LL=1,4 ACCEPT 7,A(LL) ACCEPT N,V(l),V(I+1),V*1+2 \ =y- J t List of variable names 1 - - Statement number of FORMAT statement Device Selection and direction of transfer ACCEPT and TYPE Statements , ACCEPT and TYPE transfer information between the Teletype and EduSystem 50. ACCEPT causes information to be read into core memory from either the keyboard, the Teletype paper tape reader, or the high-speed reader if it is assigned before calling FORTRAN-D. ACCEPT is especially convenient if data is to be entered at the keyboard since it automatically supplies line feed when the RETURN key is typ~d. Also,. the user may correct an erroneously typed value by typing the RUB OUT key. TYPE causes information to be transferred from core memory to the Teletype printer, the Teletype paper tape punch, or the high-speed punch if it is assigned before calling FORTRAN.;.D. 9-120 If the user needs the high-speed reader and punch for I/O, he must assign the devices for his use before calling the FORTRAN compiler (FORT) or operating system (FOSL). Once logged into EduSystem 50, he replies to Monitor's dot with the appropriate assign statements. For example: .ASSI GN P 'p ASSIGNED .ASSIGN R R ASSIGNED The Monitor replies with P ASSIGNED and R ASSIGNED in re:sponse to the user. If the device requested is not available (being used by someone else), Monitor replies JOB XX HAS X, where XX is the job number assigned the device X. The high-speed reader/punch is device code 2. If running several programs, the user should reassign the devices before each run. READ and WRITE Statements EduSystem 50 FORTRAN also allows programs to read and write data files on disk. These data files are completely separate from program files. Data files are read and written by standard READ and WRITE statements within the FORTRAN program. The device code for the disk is 3. Since programs which use disk are treated differently by FORT from those which do not use disk, it is necessary to identify programs which do. This is done by placing a DEFINE DISK statement as the first statement in any FORTRAN program which includes a READ or WRITE statement with a device code of 3. Just as FORT must ask for the names of its input and output files~ so must a FORTRAN program ask for the names of its disk files. FORTRAN programs do this by typing INPUT: and OUTPUT: a second time. The user responds by typing the names of the data files to be read or written by the program. FORTRAN will ask for both INPUT and OUTPUT for all programs which • include a DEFINE DISK statement. If only one is to be used, respond to the other by typing the RETURN key. VARIABLE SPECIFICATION IN I/O STATEMENTS Following the instruction that selects the device and direction of transfer is the statement number of the FORMAT statement that 9-121 controls the arrangement of the information being transferred. For example: ACCEPT 10 .. A 10 FORMAT (E) Every I/O statement must have a reference to a FORMAT statement. The final item specified in the I/O statement is the list of . variables. This is a sequential list of the names of variables and . array elements whose values are to be transferred in the order indicated. There is no restriction on"the number of names which may appear in the list of an I/O statement, as long as the total statement length does not exceed 128 ·characters. The modes of the variables named 'need not agree with the corresponding FORMAT statement; however, the modes specified in the FORMAT statement take precedence. For example, where A=3.2, J-:27, KAL= 302, and BOB=7.58: 23 TYPE 23 .. A.. J .. KAL .. BOB FORMAT (I .. E.. I .. E) The decimal portion of A is dropped and the number 3 is printed as an integer; the value of J is printed as a normalized number; KAL is printed as an integer; and ,BOB is printed as a normalized number. The output would look like the following: + 3 +0.270000E+2 + 302 +0.758000E+01 .NOTE In READ and ACCEPT statements~ although the number is read according to the FORMA Tstatement, it is stored according to the mode of the variable. For example: 5 ACCEPT l~,A 10 FORMAT (1) causes. the number 12.3 typed by the user to be read as 12 and stored as 0.120000E+2 .. 9-122 Array names included in I/O lists must be subscripted in one of the following forms: A(V) A(V+C) A(V-C) A(C) where A is the array name, V is a simple integer variable and C is a positive nonzero integer constant. HI TYPE10IAIIIBIC(I+I>IN(J+I> FORMAT (EII1E1 /> If the list contains more names than there are elements in the FORMAT statement, the FORMAT statement is reinitialized when the elements are exhausted. The first element in the FORMAT state:ment then corresponds to the next name in the list. For instance, in the preceding example when the value of the variable, B, is printed in the E format, the control character, slash (/), causes a carriage return/line feed to occur. Then the FORMAT statement is reinitialized, and the array element, C(I+K), is printed in the E format and the array element N(J+L) in the I format. The list does not have to exhaust the elements of a FORMAT statement. If there are fewer names in the list than there are elements in the FORMAT statement, the program completes the I/O operation and proceeds to the next sequential FORTRAN statement. If this next statement is another I/O statement that references a previously unexhausted FORMAT statement, that FORMAT statement is reinitialized. FORMAT statements are reinitialized when they are referenced or when all of their elements are exhausted. FORMAT STATEMENT The FORMAT statement controls the arrangement and mode of the information being transferred. The values of names appearing in the I/O statement list are transferred in the mode specified by the corresponding element in the FORMAT statement. These controlling elements consist of the characters E, I, A, slash (/), 9-123 and quote ("). The set of elements must be enclosed in parentheses and separated by commas. For example: FORMAT (AI E" 11'" "HOLLERI TH") The control elements E and I are used for defining the mode of the data being transferred. When a variable is transferred in the E format, it is stored or output in floating-point form. If the variable is transferred in the I format, it is stored. or output in fixed-point or integer form. Mode conversion on input or output can be accomplished because the elements in the FORMAT statement define the mode of the data. The mode of the original variable is overridden where necessary. For example: i0 TYPE 10"A FORMAT ( I ) The variable, A, is printed as an integer, and the fractional part of A is truncated. If A has a value of 14.96, only the integer part, 14, is printed. If A has an absolute value of less than one, zero is printed. THE A FORMAT SPECIFICATION The control element, A, is used for defining the alphanumeric mode of data I/O. When a variable is to be assigned an alphanumeric value, data is read one character per variable. FORTRAN ignores CTRL/C, blank tape, RUBOUT, and 0200 code (leader/ trailer tape) . FORTRAN does not see the form-feed character when input is from the disk. The decimal equivalent of the ASCII value of the character is assigned to the variable. For example: . A = 301 (ASCII) = 192 (decimal) Any variable assigned the. alphanumeric value, A, would be set equal to 192. It is possible to do arithmetic with integer variables assigned alphanumeric values. For. example: 10 12 DO 10 J= 1" 5 ACCEPT 12" KCJ> IF CKCJ)-141> 10,,40,,100 CONTINUE FORMATCA) 9-124 where the IF statement tests to see if the last character read is a carriage return (which is ASCII 215 or 141 decimal); if so, control transfers to Statement 40; if not, control stays within the DO loop. It is not possible to do arithmetic with real variables assigned alphanumeric values. Output in alphanumeric format converts the value of the variable into an ASCII character and prints that charactt~r. For example: 12 20 FORMATCA) DO 20 I = I" 5 TYPE 12" A(J) CONT INUE If the variables A (1) through A (5) were not originally assigned alphanumeric values, the results of the output can be meaningless. INPUT FORMATS Input data words can only consist of a sign, a decimal value, an exponent value if the data is floating-point, and' a field terminating character such as space. Any character that is not a number, decimal point, sign, or E can be used to terminate a field except the RUBOUT character. When typing data, any number of spaces or other nonnumeric characters can be typed before the sign or decimal value in order to make the hard copy more readable. Input data can be transferred into core memory from either the Teletype paper-tape reader, the keyboard, the high-speed reader, or DECtape. Input can be entered in either fixed- or floating-point modes (integers or decimal numbers). The mode in which data is stored in core memory is controlled by the first letter of the variable name. The characters read into core are determined by the corresponding element in the FORMAT statement. Integer Values-the I Format An integer data field consists of sign l l and up to six decimal characters. Some examples of integer values are as follows: 11 Plus sign can be represented by a plus or space character. Minus is represented by a minus character. If a sign character is absent from the data word, the data is stored as positive. 9-125 Typed Numbers Values Accepted -2001 -40 -0040 16 -2041 -2001 -0040 -0040 0016 2047 Real Values-the E Format A floating-point input word consists of a sign, the data value up to six decimal characters, an E if an exponent is to be included, the sign of the exponent, and the exponent (i.e., the power of ten by which the data word is multiplied). For example: ddd.dddEnn The d's represent numerical characters in the data and the n's represent the 2-digit power of ten of the exponent (preceded by a sign). Either the sign, the decimal point, or the entire exponent part can be omitted. If the sign is omitted, the number is assumed to be positive; if the decimal point is omitted, it is assumed to appear after the rightmost decimal character. If the exponent IS omitted, the power of ten is taken as zero. Some examples of floating-point values are as follows: Typed Numbers Values Accepted 16. .16E02 1600.E-02 0.16 x 10:! 0.16 X 102 0.16 X to:! OUTPUT FORMATS E and I Formats Integer values are always printed as the sign and 'a maximum number of four cha~acters with spaces replacing leading zeros. On output, integers are left justified within the stated field. Sufficient trailing spaces are printed to fill the field followed by one additional space. Floating-point values are printed in a floating-point format which consists of sign, leading zero, decimal point, six decimal characters, the character E, the sign of the exponent (minus or plus), and an exponent value of two characters. For example: 9-126 Integer Values Output Format -1043 -0016 +0016 -1043 16 + 16 Floating-point values are printed as follows: SO.ddddddEsnn where: S represents the sign, minus sign, or space dddddd represents six decimal digits of the data word E indicates exponential representation s represents the sign of the exponent value nn represents the exponent value Some examples of floating-point output are: Decimal Value Output Format -8,388,608.0 -.000119209 -0.8388608E+07 0.119209E-03 FORMAT Control Specifications In most cases when data is to be presented, it must be labeled and arranged properly on a data sheet. ]n order that this can be accomplished with FORTRAN-, a provision has been made so that text information and spacing can be printed along with the data words. These features are provided by the special FORMAT control elements quote (") and slash (/). The slash character causes a return to the left margin. Hollerith Output When text information is enclosed in quotes and is contained as part of a FORMAT statement, it is output to the specified device as it appears in the statement. This output occurs when a TYPE or WRITE statement references a FORMAT statement containing text, and all other elements of the FORMAT statement previous to the text have been used. All legal Teletype characters (other than the quote character itself) can be contained within quotes and output as text. 9-127 10 TYPE 10 FORMAT(/,,"THIS IS HOLLERITH""/) 100 TYPE 100"AMIN"AMAX FORMAT (I" "MIN IMUM="" E" I" "MAXIMUM="" E" I) 210 250 TYPE 210 FORMAT(/"I,," CUMULATIVE DISTRIBUTION""I"I' .. INCREMENTS FREQUENCY"" I) DO 220 K=I" 100 TYPE 250"K"VALUCL)"VALU(K+l)"COUNT(K) CONTINUE FORMAT (I" .... "E" .. ""E"/) Implementation Notes DOUBLE SUBSCRIPTS This version of FORTRAN does not have the facility for doublesUbscripted variables. To accomplish dO,uble subscripting, the pro- , grammer has to include indexing statements in the source program as illustrated below. In this example, the matrices are stored columnwise in memory; that is, sequential locations in memory are used as follows: Relative Position in Memory (1NDX) Element all a21 a31 a41 a51 a61 I 2 3 4 5 6 a12 a22 7 8 a56 a66 35 36 If referencing Element a56 in the array, M=5, N=6, (1=6 for a 6 by 6 array), and INDX=M+1*(N-1)=S+I*5=35. If ref- erencing Element a22, INDX=2+6* 1=8. 9-128 C C MATRIX MULTIPLY PROGRAM DIMENSION A(36)IB(36)IC(36) ACCEPT DIMEl'.JSION OF ARRAY ACCEPT III FORMAT ( I ) DO 10 M= 1 I I DO 10 N= 1 # I I N DX =M+ I (N - 1 ) ACCEPT FIRST MATRIX * C ACCEPT 2 10 15 C 20 C 30 C 40 21 I~A(INDX) FORMAT(E) CONTINUE TYPE 15 FORHAT(/I/#/) DO 20 t1= 11 I DO 20 N=111 INDX=M+U(N-l) ~CCEPT SECOND MATRIX ACCEPT IIB(INDX) C ( IN DX) =QJ CONTINUE MULTIPLY MATRICES DO 30 M=I,1 DO 30 N= 1 I I DO 30 K=I,I IC=N+I*U1-1 ) IA=K+l*(:1-1> I B= K+ 1 * (K- 1 ) C(IC)=C(lC)+A(IA)*B(IB) CONTINUE TYPE 15 PRINT RESULTS IN MATRIX TYPE 21 DO 40 i1= 1 # I TYPE 21 DO 40 N= 1, 1 IN DX= N+ I * (11- 1 ) TYPE 11 C (INDX) CONTINUE FORMAT (/) TYPE 15 END FOP~ SUBSTATEMENT FEATURE The most important result of treating the equal sign as a binary operator (as explained in the section on Arithmetic Statements) is that it may be used more than once in arithmetic statement. In addition to simple replacement operations (see section on Multiple Replacement), consider the following; CPRM = (CKL - CKG) / (CPG = P*(Q-I-l)) 9-129 The internal arithmetic statement (or substatement). CPG p* (Q+ 1). is set off from the rest of the statement by parentheses. The complete statement isa concise way of expressing. the following common type of mathematical procedure: Cl Let: =C k1 -C 1i/.;, Cpg Where: C v!;' = p.(q+1) . The stating of a relation followed by the conditions for evaluating any of the variables can be expressed in a single arithmetic statement in FORTRAN. A second use of the equal sign is shown below. For background on this short program, see the discussion of the same problem in the section on the IF statement. C SUM OF THE FIRST 50 INTEGERS' KSUM=0 INUM 50 KSUM=INUM+KSUM I F ( IN UM + IN UM - 1 ) 3" 3.1 2 STOP 2 3 In this example, the sum is formed by counting down, but the same results are achieved as in the section on the IF statement. The initialization is changed so that INUM starts with the value of 50 instead of 0, and the statement, INUM=INUM+ 1, is no longer required. ERROR CHECKING Because of the extremely compact nature of the FORTRAN-D Compiler, either FORTRAN features or error checking will suffer. In the case of FORTRAN-D, checking for .certain errors is not as important as preserving the language. Therefore, the programmer is advised to follow the rules as stated in this manual and carefully check his program for mistakes. For example, the statement A = B + C - will compile, although at execution time it will give unpredictable results. 9-130 It should be noted that data areas must not extend below loca- tion 5600 in FORTRAN-D. No diagnostic is issued unless program and data areas actually overlap. A maximum of 89610 words- are available for data. Care should be taken not to exceed the limits through use of large arrays, etc. Similar obvious errors are accepted by the Compiler; their effects are often unpredictable. FORTRAN-D SOURCE PROGRAM RESTRICTIONS The following limits are imposed upon all FORTRAN-D source programs: 1. Not more than 896 data cells. This includes all dimensional variables, user-defined variables, constants, and all constants generated by the usage of a DO loop. 2. Not more than 20 undefined forward references to unique statement numbers per program. An undefined forward reference is a reference to any statement label that has not previously occurred in the program. Multiple refer- ences to the same undefined statement numbers are considered as one reference. 3. Not more than 64 different variable names per program. 4. Not more than 128 characters per input statement. 5. Not more than 40 numbered statements per program. FORTRAN-D COMPILER AND OPERATING SYSTEM CORE MAP The Compiler occupies the following core locations: 0003-7600 7200-7600 Compiler plus tables Compiler tables (undefined forward reference tables, etc.) The Operating System occupies locations: 0000-5200 0000-6000 Operating System for paper I/O Operating System for disk I/O Locations 5201 through 7576 are available for the user's program when using paper tape input/output. 9-:131 Table 9-10. FORTRAN-D Statement Summary Statement and Form Explanation Arithmetic StatemenJs v=e v is a variable (possibly subscripted); e is an expression. Control Statements GO TO n n is a statement number. GO TO (n 1 ,n2, ... ,n ll ),i nl, ... ,nn are statement numbers; i is a nonsubscripted integer variable. IF (e) nl,n2,rl 3 e is an expression; nl,n2,n 3 are statement numbers. DO n i=k b k 2 ,k a n is the statement number of a CONTINUE; i is an integer variable; k 1 ,k 2,k B are integers or nonsubscripted integer variables. CONTINUE Proceed PAUSE Temporarily suspend execution. STOP Terminate execution. END 'Terminate compilation; last statement program. III Specification Statements DIMENSION v1(n 1 ), v2(n2) ,... ,vn (nn) Vl, ... ,vn are variable names; nl, ... ,nn are integers. DEFINE device Device is DISK or TAPE. s is a data field specification. COMMENT Designated by C as first character on line. Input/ Output Statements ACCEPT f, list f is a FORMAT statement number; list is a list of variables; input is from the Teletype. TYPE f, list f is a FORMAT statement number; list is a list of variables; output is to the Teletype. 9~132 Table 9-10 (Cont.). FORTRAN-D Statement Summary Statement and Form Explanation READ u,f, list u is an integer representing the device which data is to be read: 1=Teletype, 2= high-speed reader, 3=disk; f is a FORMAT statement number; list is a list of variables. WRITE u,f, list u is an integer representing which data will be written: 2=high-speed punch, 3=disk, MAT statement number; list variables. device onto 1=Teletype, f is a FORis a list of FORTRAN-D Error Diagnostics Diagnostic procedures are provided in the Compiler to assist the programmer in program compilation. When the compiler detects errors in a FORTRAN source program, it prints the error messages on the user termimil. These messages indicate the source of the errors and direct the programmer's efforts to correct them. To speed up the Compiler process, the Compiler prints only an error code. The programmer then looks up the error message corresponding to the code in Tables 9-11 through 9-13 and takes the appropriate corrective measures. COMPILER COMPILATION DIAGNOSTICS Format of Diagnostics xxxx xx XX L The identifying condition code '----The number of statements since the appearance of a n\1mbered statement (octal value). L..--....;The statement number of the last numbered statement. 9-133 For example: 10 A=I(.J+l) H=A*(H+SINF(THTA) .During compilation of the prevIOUS statements, the following error code would be printed: 1:,1 0 1 11 indicating that a statement which occurs one statement octal. (one decimal) after the appearance of Statement 10 is in error. The message corresponding to Code 11 shows that the number of left and right parentheses in the statement is not equal. If a statement number is referenced but does not appear in the source program, the diagnostic code will be printed as follows: xxxx 77 20 where the number usually reserved for the last numbered statement (xxxx) is replaced by the missing statement, e.g. GO TO lCilCil The diagnostic would appear as follows where Statement 100 is never defined. IV'lCi'l 77 ~Iil Table 9·11. Error Code 00 01 03 04 05 06 07 )0 ).) FORTRAN·D Compiler Compilation Diagnostics Explanation Mixed mode arithmetic expression Missing variable or constant in arithmetic expression Comma was found in arithmetic expression Too many operators in this expression Function argument is in fixed-point mode Floating-point variable used as a subscript Too many variable names in this program Program too large, core storage exceeded Unbalanced right and left parentheses 9-134 Table 9-11 (Cont.). F'ORTRAN-D Compiler Compilation Diagnostics -----------------------------------------------------Error Code Explanation 13 14 Compiler cQuld not identify this statement More than one statement with same statement number Subscripted variable did not appear in a DIMENSION statement Statement too long to process Floating-point operand should have been fixed-point Undefined statement number Too many numbered statements in this program Too many parentheses in this statement Too many statements have been referenced before they appear in the program DEFINE statement was preceded by some executable statement Statement does not begin with a space, tab, C, or number ------------------------------------------------------12 . Illegal character found in this statement 15 ]6 17 20 21 22 23 25 26 > -------------------------------------------------------COJvlPILER SYSTEMS DIAGNOSTICS Certain errors can make it impossible for the Compiler to proceed in the normal manner. These errors occur before the Compiler has been loaded into core. They may be caused by improperly loading the Compiler, by not having an END statement on a source file, bya machine malfunction, or by other errors. These errors, referred to as system errors, are explained in Table 9-12. Table. 9-12.. Error Code 0240 3100 3417 6145 6223 6226 6257 6724 6746 7114 FORTRAN-D Compiler Systems Diagnostics Explanation System file error. One of the FORTRAN components cannot be found or the disk is full, preventing FORTRAN from proceeding. Try recalling FORT. Illegal operator on compiler stack. Preprecedence error. Could not find FOSL on system device; if the error occurs, it may be necessary to reload FORT and FOSL. Error: while loading the Compiler. Same as above. Same as above. No END statement on source device. Same as above. Same as above. 9-135 OPERATING SYSTEM DIAGNOSTICS Not all errors are detected by the Compiler. Some errors can only be detected by the operating system (FOSL). Also there are . some conditions which indicate errors on the part of the Compiler and/ or operating system. When such an error occurs during running of a program, the computer. prints out an error message containing the word TILT or ERROR and an error number. The computer then halts. If the CONTINUE switch is pressed, the computer takes the action listed in Table 9-13. Table 9·13. I FORTRAN·D Operating System Diagnostics ErrQr CQde ExplanatiQn 01 02 04 05 06 11 12 13 14 15 16 17 20 21 22 40 41 76 77 Checksum'errQr Qn FORTRAN binary input Illegal Qrigin Qr data address Qn FORTRAN binary input Disk input-Qutputerrorl2 High-speed reader errQr Illegal FORTRAN binary input device Attempt to' divide by zero FIQating-PQint input data conversiQn error Illegal QP cQde Disk input-Qutput error1,2 NQn-FORMAT statement used as a FORMAT Illegal FORMAT specification FIQating-PQint number larger than 2047 Square rQQt Qf a negative number EXPQnential negative number LQgarithm Qf a number less than O'r equal to' zerO' Illegal device code used in READ Qr WRITE statement System ,device full, eQuId nQt cQmplete a WRITE statement Stack underflO'w errQr13 Stack Qverflow errQr13 May be caused by machine malfunction or operating system error. May be caused by source program or loading error; to correct, do the following in descending order. a. Use Diagnose to determine where the error occurred. h. Recompile the source program. c. Examine source program (in particular the arithmetic statements and subscripted variables). 12 13 9-136 PAL-D ASSEMBLER IlIltroduction The EduSystem 50 Assembly System is composed of the PAL-D Symbolic Assembler, LOADER, and ODT. The PAL-D Assembler is used to translate the user's source program into an object program (binary or machine code). LOADER is used to transfer the user's object program from the disk into core for debugging or execution. ODT (Octal Debugging Technique) is used to dynamically debug the object program which has been loaded into core using LOADER. The PAL-D Assembler is fully documented in Programming Languages 1972, Chapter 14. PAL-D source programs are usually written on-line using the EDIT program, which stores them in disk files. The Assembler checks for assembly language syntax errors and for undefined user symbols. To call the PAL-D Assembler, the user types: .R PALD PAL-D responds by requesting INPUT: Type the name of the source program or programs to be assembled. A maximum of three files can be assembled together. PAL ... D then requests OUTPUT: Type the name of the new file in which PAL-D will store the assembled program in executable binary form. PAL-D then requests OPTION: For a normal assembly, press the RETURN key. If an assembly listing is not desired, respond to OPTION with N. PAL-D then proceeds to assemble the program: any errors in the program are indicated; the program symbol table is printed; and finally, an assembly listing of the source program is printed. When the listing is completed and the assembly finished, ~ontrol is returned to the Monitor. EduSystem 50 PAL-D Because of the necessary hardware changes made for timesharing on EduSystem 50, PAL-D has been revised in the following ways (as differing from PAL-D on a non-timeshared PDP-8) : A. P AL-D, under EduSystem 50, allows 245 (decimal) user symbols in addition to the permanent symbols listed in 9-137 Table 9-14. Allsymt>ols reside in locations 5200 through 7777. The permanent s·ymbol table has beeR revised to include all instructions peculiar to the time-sharing system. B. A CTRL/C (tC) from the ·Teletype terminates the assembly, and halts.PAL-D, sending the user back to the Monitor. Example of a PAL-D Program .R PALD INPUT:TYPE2 OUTPUT: B IN2 OPT IO~: COt:NT CRLF Leep OUT REG START ·0415 0417 0406 0425 0416 0400 /PROGRAM TO *0400 START, CLA JMS TAD DCA TAD DCA LOOP, TAD JMS ISZ ISZ JMP Jr.-'s HLT COU:\JT, 0 REG, 0 0400 0401 041iJ2 0403 0404 0/.105 0406 0407 0410 0Lll1 011 12 0413 01114 0415 0416 7200 4217 1377 3215 1376 3216 1216 4225 2216 2215 5206 4217 7402 0000 0000 0417 0420 0421 0422 0/123 0424 0000 1375 4225 1374 4225 5617 CRLF, 0425 0426 01127 0430 0431 0432 0574 0575 0576 0577 0000 6046 6041 5227 7200 5625 0212 0215 0260 7766 OUT, TY·PE OUT "0123456789" CRLF ( - 1 2'> COUNT (260 ) REG REG OUT REG COUNT LOOP CRLF" 0 TAD (215) JMS OUT TAD (212) J~S OUT JMP I CRLF 0 TLS TSF JMP .-1 CLA JMP I OUT ISS 9-138 /ASC I I CODE FOR ZERO (0 ) /ASC I I FOR CARRIAGE RETUR:\J /LINE FEED Table 9-14. Mnemonic Code EduSystem SO Symbol List Operation Event Time Memory Reference Instructions AND 0000 Logical AND TAD 1000 Twos complement add ISZ 2000 Increment & skip if zero 3000 Deposit & Clear AC . DCA JMS 4000 Jump to subroutine JMP 5000 Jump GlrOUP 1 Operate Microinstructions NOP 7000 No operation lAC 7001 Increment AC RAL 7004 Rotate AC & link left one RTL 7006 Rotate AC & link left two RAJ{ 7010 Rotate AC & link right one RTR 7012 Rotate AC & link right two CML 7020 Complement link CMA 7040 Complement AC CLL 7100 Clear link CLA 7200 Clear AC Group 2 Operate Microinstructions .HLT 7402 Halts the computer 05T 7404 Inclusive OR switch register with AC SKP 7410 Skip unconditionally SNL 7420 Skip on nonzero link SZL 7430 Skip on zero link SZA 7440 Skip on zero AC SNA 7450 Skip on nonzero AC SMA 7500 Skip on minus AC SPA 7510 Skip on plus AC (zero is positive) Combined Operate Microinstructions CIA 7041 Complement & increment AC STL 7120 Set link to 1 GLK 7204 Get link (put link in AC, bit 11) STA 7140 Set AC=-1 LAS 7604 Load AC with switch register PSEUDO-OPERATORS DECIMAL OCTAL EXPUNGE PAGE FIELD PAUSE FIXTAB TEXT I XLIST Z 9-139 1 3 3 3 3 3 2 2 1 1 4 3 1 1 1 1 1 1 1 1 1, 1 1 1 Table 9-14 (Cont.). Mnemonic Code EduSystem 50 Symbol List Event Time Operation lOT Microinstructions PROGRAM INTERRUPT lOT 6000 (See Introduction to Programming 1972, Chapter 6.) KEYBOARD READER KSF 6031 Skip if keyboard/ reader flag 1 KCC 6032 Clear AC & keyboard/reader flag KRS 6034 Read keyboard/ reader buffer KRB 6036, Clear AC & read'keyboard buffer, & clear keyboard flag 6400 Set keyboard break KSB 6401 Set buffer control flags SBC 6030 Read keyboard string KSR = TELEPRINTER/PUNCH TSF 6041 Skip if teleprinter/punch flag = 1 TCF 6042 Clear teleprinter/punch flag TPC 6044 Load teleprinter/punch buffer, Select & print TLS 6046 Load teleprinter/punch buffer, Select & print, and clear Teleprinter/punch flag SAS 6040 Send a string 1 2 3 2,3 1 2 3 2,3 HIGH-SPEED READER (TYPE PC02) 6011 Skip if reader.flag = 1 1 RSF 6012 . Read reader buffer & clear flag 2 RRB 6014 Clear flag & buffer & fetch character 3 RCF RRS 6010 Read reader string HIGH-SPEED PUNCH (TYPE PC03) PSF 6021 Skip if punch flag 1 PCF 6022 Clear flag & buffer PPC 6024 Load buffer & punch character PLS 6026 Clear flag & buffer, load & punch PST 6020 Punch string = DECTAPE TRANSPORT (TYPE TU55) AND CONTROL (TC01) DTXA 6764 Load status register A DTSF 6771 Skip on flags DTRB 6772 Read status register B 9-140 1 2 3 2,3 3 1 2 Table 9-14 (Cont.). Mnemonic Code EduSystem SO Symbol List Operation PROGRAM CONTROL URT 6411 User run time TOD 6412 Time of day RCR 6413 Return clock rate DATE 6414 Date STM 6415 Quantum synchronization T5S 6420 Skip on TSS/8 USE 6421 User SSVV 6430 Set switch register CKS 6200 Check status ASD 6440 Assign device REL 6442 Release device DUP 6402 Duplex CON 6422 Console FILE CONTROL WHO 6616 SIZE 6614 RFILE 6603 VVFILE 6605 ACT 6617 REN 6600 OPEN 6601 CLOS 6602 PROT 6604 CRF 6610 EXT 6611 RED 6612 FINF 6613 Who Segment size Read file VVrite file Account number Rename file Open file Close file Protect file Create file Extend file Reduce file File information 9-141 Event Time Table 9-15. PAL-D Error Diagnostics Error Code Explanation BE Two PAL-D internal tables have overlapped-This situation can usually be corrected by decreasing the level of literal nesting or number of current page literals used prior to this point on the page. DE System device error-An error was detected when trYing to read or write onto the system device; after three failures, control is returned to the Monitor. DF Systems device full-The capacity of the systems device has been exceeded; assembly is terminated and control is returneQ to the Monitor . .-.~-,- IC Illegal character-An illegal character was encountered other than in a comment or TEXT field; the character is ignored and the"assembly continued. ID Illegal redefinition of a symbol-An attempt was made to give a previously defined symbol a new value by means other than the equal sign; the symbol. was not redefined. IE Illegal equals-An equal sign was used in the wrong context. Examples: TADA+=B A+B=C 11 the expression to the left of (he equal sign is not a single symbol or, the expression to the right of the equal sign was not previously defined Illegal indirect-An off-page reference was made; a link could not be generated because the indirect bit was already set. 9-142 Table 9-15 (Cont.). Error CO'de PAL-D Error Diagnostics ExplanatiO'n ND The prO'gram terminatO'r, $, is missing. PE Current nO'nzerO' page exceeded-An attempt was made to': a. O'verride a literal with an ins tructiO'n , O'r b. O'verride an instructiO'n with a literal; this can be corrected by ( 1) decreasing the number O'f literals O'n the page O'r (2) decreasing the number O'f instructiO'ns O'n the page. PH Phase errO'r-P AL-D has received input files in an incO'rrect O'rder; assembly is terminated and cO'ntrO'I is returned to' the MO'nitO'r. SE SymbO'l table exceeded-Assembly is terminated and cO'ntrol is returned to' the MO'nitO'r; the symbO'I table may be expanded to' cO'ntain up to' 1184 user symbO'ls by saving a file named .SYM O'n the system device. US Undefined symbO'I-A symbO'I has been prO'cessed during pass 2 that was nO't defined befO're the end O'f pass 1. ZE Page 0 exceeeded-Same as PE except with reference to' page O. 9-143 9-144 UTILITY PROGRAMS Symbolic Editor The EduSystem 50 Symbolic Editor (EDIT) provides the user with a powerful tool for creating and modifying source files online. Its precise capabilitif;S and commands are detailed in Introduction to Programming 1972, Chapter 5. EDIT allows the user to delete, insert, change, and append lines of text, and then obtain a clean listing of the updated file. EDIT also contains commands for searching the file for a given character. EDIT considers a file to be divided into logical units, called pages. A page of text is generally 50-60 lines long, and hence corresponds to a physical page of program listing. A FORTRAN-D program is generally 1-.3 pages in length; a program prepared for PAL-D may be several pages in length. EDIT operates on one page of text at a time, allowing the user to relate his editing to the physical pages of his listing. EDIT reads a page of t.ext from the input file into its internal buffer where the page becomes available for editing. When a page has been compl~tely updated, it is writ~ ten onto the output file and the next page of the input file is made available. EDIT provides several powerful commands for paging through the source file quickly and conveniently. NOTE The end of a page of text is marked by a form feed (CTRL/L) character. Form feed is ignored by all EduSystem 50 language processors. To call the Editor, type: .R EDIT EDIT responds by requesting INPUT: Type and enter the name of the source file to be edited. If a new file is to be created using EDIT, there is no input file. In this case, strike the RETURN key" EDIT then requests OUTPUT: Type the name of the new, edited., file to be created. The name of the output file must be different from the name of the input file. If EDIT is being called to Ust the input file, there is no need to create an output file; strike 9-145 the RETURN key. When EDIT sets up its internal files and is ready for a command, it rings the bell on the Teletype. For example: .R EDIT INPUT: WXZOL.D. OUTPUT:XYZNEft: (Bell rings at this point.) Table 9-16.< Symbolic Editor'Operations Summary Special Characters Carriage Return (RETURN Key) Back Arrow ( ~ ) Rubout (".) . Function Text Mode-Enter the line in the text buffer. Command Mode-Execute the command. Text Mode-Delete from right to of text, continue typing on same line. Command Mode-Cancel command. Editor issues a ? and carriage return I line feed. Text Mode-Delete from right to left one, character for each rubout· typed. Does not delete past th~ beginning of the line; Is not in effect during a READ command. Command-Mode-'Same as back arrow; Form Feed (CTRL/FORM Combination) Text Mode-End of inputs return to command mode. Period (.) Command Mode-Current line counter used as argument alone or in combination with + or - and a number (.,.+5L). Slash (!) Command Code-Value equal to number of last line in buffer. Used as argument (I-5,LI). Line Feed (J,) Text Mode-Used in SEARCH command to insert a CRI LF combination into the line being searched. . 9-146 Table 9-16 (Cont.). Symbolic Editor Operations Summary Special Characters Function -----------------------------------------------------Right Angle Bracket (» Command Mode-List the next line (equivalent to .+lL). «) Left Angle Bracket Command Mode-List the previous line (equivalent to . -1 L) . . Equal Sign (=) Command Mode-Used in conjunction with. and I to obtain their value (.=27). Tabulation ( CTRLI TAB Key Combination) Text Mode-Produces a tabulation which, on output, is interpreted as spaces· if bit 1 of the switch register is set to 0, or as a tab character I rubout combination if bit ] is set to 1. --Command -READ Table 9-17. EDIT Command Summary Meaning Format R Read text from the input file and append to buffer until a form feed is encountered. APPEND A Append incoming text from keyboard to any already in the buffer until a form feed is encountered. LIST L List the entire buffer. nL List line n. m,nL List lines through n inclusive. P Output the contents of the buffer to the output file, followed by a form feed. nP Output line n, followed by a form feed. m,nP Output lines m through n inclusive followed by a form feed. T Close out the output file and return to the Monitor. PROCEED TERMINATE 9-147 Table 9-17 (Cont.). Command NEXT EDIT Command Summary Meanin~ Format N Output the entire buffer and a form feed, kill the buffer and read the next page. nN Repeat the above sequence n times. KILL K Kill the buffer (i.e., delete all text lines) . DELETE nD Delete line n of the text. m,nD Delete lines m through n inclusive. I Insert before line 1- all the text from the keyboard until a form feed is entered. nI Insert before line n until a form feed is entered. nC Delete Hne n, replace it with any number of lines from the keyboard until a form feed is entered. m,nC Delete lines m through n, replace from keyboard as above until form feed is entered. MOVE m,n$kM Move lines m through n inclusive to before line k. GET G Get and list the next line beginning with a tag. SEARCH S Search the entire buffer for the character specified (but not echoed) after the carriage return. Allow modification when found. Editor outputs a slash (/) before beginning a SEARCH. nS Search line n, as above, allow modification. m,nS Search lines m through n inclusive, allow modification. INSERT CHANGE 9-148 Table 9-17 (Cont.). Command EDIT Command Summary Format Meaning END E Output the contents of the buffer. Read any pages remaining in the input file, outputting them to the output file. When everything in tHe input file has been moved to the output file, close it out and return to the Monitor. E is equivalent to a sufficient number of N's followed by a T command. tC CTRLI C Stop listing and return to Command Mode. Loader LOADER is used to load programs in BIN format from a disk file into the user's core area for execution. These files in BIN format can be created by P AL-D in the course of an assembly or they can be loaded from paper tape using PIP (see the PIP section for . special instructions on loading BIN format tapes). To call LOADER, type: .R. LOADER LOADER responds by asking for INPUT: Respond by entering the" name of the file or files to be "loaded. Although many System Library Programs allow mUltiple input files, the L6ADER uses this feature to special advantage. Because it loads the files in the order they are typed, LOADER can be used to load patches and overlays. After it has requested INPUT, LOADER requests OPTION: For normal operation strike the RETURN key; LOADER is able to load into any part of core below 7750. If the program to be loaded is to be debugged, respond to OPTION: with D. This will cause ODT to be loaded along with the input files and started. ODT indicates that it is ready by printing a second line ft!ed. ODT uses locations 7000 through 7577; and if loaded along with a program which uses any of these locations, the result of the load is unpredictable. 9-149 EXAMPLE 1: NORMAL OPERATION .R LOADER INPUT:MAIN" PATCHl" PATCH2 OPTION: 'BS EXAMPLE 2: 'LOAD OnT WITH INPUT FILE .R LOADER INPUT:PROGl OPTION: 0 As seen in the first example, LOADER returns control to Monitor when it is finished. The user can then start the program by using the Monitor command 'START. For example, LOADER can be used to load and run the short program given as an example in the section on PAL-D . • P. LOADER INPUT: BIN2 OPTION: 'BS .START 400 0123456789 'BS NOTE All BIN format files loaded by LOADER include a checksum. If LOADER detects a checksum error while loading, it prints LOAD ERROR and terminates the load. Octal Debugging Technique (ODT) ODT is a powerful octal debugging tool for testing and modifying PDP-8 programs in actual machine language. It allows the user to control the execution of his program and, where necessary, make immediate corrections to the program without the. need to reassemble. 9-150 Th.e .complete command repertoire of ODT is documented in Introduction to Programming 1972, Chapter 5. ODT (on EduSystem 50) is the high-core version which resides in locations 7000 through 7577. The paper-tape output commands of regular ODT are not available in EduSystem 50 ODT. To call ODT, the user types: .LOAD 2 ODTKI 0 7000 • STAHT 7000 If ODT is to be used to debug a program being loaded with LOADER, ODT can be loaded and started directly by specifying the Debug (D) option to LOADER. ODT executes an SRA (Set Restart Address) as part of its ini.tialization process. As a result, typing CTRL/C always returns control to ODT. If the program being debugged sets up its own restart address, typing CTRL/C transfers control to the new restart address. It is necessary to type tBS followed by START 7000 to force control back to ODT. Every time ODT regains control, it puts the Teletype in duplex mode. Users debugging programs which do not operate in duplex mode, should be aware of this fact. ODT saves the state of the delimiter mask, when it regains control via a breakpoint. The state of this mask is restored on a Continue (C) command, but not on a GO (G) command. Table 9-18. ODT Command Summary Command Meaning nnnn/ Open register designated by the octal number nnnn. / Reopen latest opened register. RETURN Close previously opened register. LINE FEED Close register and open the next sequential one for modification. UpArrow (t) ( SHIFT / N ) Close register, take contents of that register as a memory reference and open it. 9-151 Table 9-18 (Cont.). ODT Command Summary Command Meaning Back Arrow (-E-) (SHIFT./O) Close register open indirectly. Illegal Character Current line typed by user is ignored, ODT types ?CRILF. nnnnG Transfer program control to location nnnn. nnnnB Establish a breakpoint at location nnnn. B Remove the breakpoint. A Open for modification, the register in which the contents. of AC were stored when the . breakpoint was encountered. C Proceed from a breakpoint. nnnnC Continue from a breakpoint and iterate past the breakpoint nnnn times before interrupting the user's program at the breakpoint location. M Open the search mask register, initially set to 7777. It may be changed by opening the search mask register and typing the desired value after the value typed by ODT, then closing the register. LINE FEED Close search mask register and open next register immediately following,. containing the location at which the search begins. It may be changed by typing the lower limit after the one typed by ODT, then closing the register. LINE FEED Close lower search' register, open next register containing the upper search limit initially set to 7000 or 1000 (location of ODT). It may be changed by typing the desired upper limit after the one typed by ODT and closing the register with a carriage return. nnnn W Search the portion of core as defined by the upper and lower limits for the octal value nnnn. 9-152 Catalog (CAT) The Monitor ma;ntains a library of disk files for each user. The System Library Program CAT is used to obtain a catalog of the contents of this library. For each file, CAT prints the size of the file in units of disk segments. The size of a disk segment may vary among installations. Generally, it is 256 (decimal) words of disk storage. The protection code for the file is also given. (See the section on Advanced Monitor Commands for a precise explanation of protection codes.) If the program was created by any of the System Library Programs, it has a protection code of 12, meaning that other users can read the file, but only the owner can change it. To call CAT, type: .R CAT The CAT program then prints a listing similar to the one shown below and concludes by printing tBS and exiting to the Monitor. .R CAT DISK FILES FOR USER SIZE ~AME FIE .BI~ 1 PROG • FCL INTER .BAS BAS000.TMP BAS100.TMP .BAC INT2 FCLPRG.FCL 2 TOTAL DISK 1 1 1 1' 2 PROT 17 12 17 17 17 37 12 SEGME~TS: 3,,13 ON DATE 70 9-JUN-70 9-JUN-70 3-JU~" 9-JU~-70 9-JUN-70 9-JUN-70 9 - JUt\ -70 9 rBS 9-153 9-JU~-70 System Status (SYSTAT) It is frequently useful to know the status of the system as a whole; how many users are on-line, where they are, what they are doing, etc. The SYSTAT program provides this capability. To call SYSTAT, type: .SYSTAT or .R SYSTAT SYST AT responds by printing on the first line: 'the version of the Monitor being run, the time, and the date: SYST AT then reports the uptime which is the length of time in hours, minutes, and seconds since the system was last put on-line. SYSTAT then lists all on-line users. Each user is identified by his account number. The job number assigned to him and the number of the console he is using are indicated, as is the particular System Program he is running. The exact running state of each user, whether he is actually running (RUN), typing (KEY) or printing (TTY), doing input/output on another system devke (10 or FIP), or not running (tB), is indicated. The amount of computer time used by each user since he logged in is given. If more users are on-line than the system has core fields to hold them, the fact that the system is swapping is reported. The number of free core blocks used internally by the Monitor for Teletype buffering and various other purposes is printed. Then SYSTAT reports any unavailable devices, i.e., devices which are assigned to individual users. The job to which they are attached and their status (AS if they are assigned but not active, AS+INIT if they are assigned and active) is also indicated. Finally, the number of available segments of disk storage is reported. 9-154 A sample SYSTAT listing is shown below. SYSTAT terminates by printing tBS and exiting to the Monitor. .R SYSTAT STATUS OF TSS/8.21 DEC PDP-8 II AT 16: 32: 52 ON 2 JUN 70 UPTIME 08:55:52 ..JOE, 1 2 3 4 WHO 10 .. 10 3 .. 13 0 .. 10 0 .. 10 AVAILABLE CORE WHERE WHAT STATE RUNTIME K00 K15 Kl1 K22 COpy SYSTAT BASIC BASIC 'B RUN KEY KEY 00:00=06 00:00:05 00:00:02 00:00:01 0K FREE CORE=222 BUSY DEVICES DEVICE JOB D0 1 Dl 1 1 1 3 D2 D3 D6 WHY AS+INT AS'+INT AS AS AS+INT 119 FREE DISK SEGMENTS TSS • 9-155 9-156 PROGRAMS FOR PAPER TAPE AND DECTAPE CONTROL PIP (Peripheral Interchange Program) All System Library programs discussed in previous sections operate only on files which are on the disk. Disk is a convenient storage medium for many files; however, it may be more useful to keep some programs on paper tape. PIP provides a convenient means of transferring files between disk and paper tape, for those users who wish to preserve copies of their files off-line. PIP CONVENTIONS PIP may be considered a link between disk file storage and paper-tape devices. To punch a desired file, PIP obtains that file from the. disk and punches it on paper tape. Similarly, to load a paper tape, PIP inputs the tape from the reader, then outputs it to a disk file. The way files are named is important to PIP. Files on disk are always named. Paper tapes, on the other hand, have no names as far as the system is concerned (although the user can label the physical tape in any manner he chooses). Paper tapes never have file names; therefore, PIP uses the absence of a file name to indicate a paper tape (absence of a file name is indicated by striking the RETURN key). The way in which INPUT: and OUTPUT: is indicated provides the means for determining the direction of file transfer. If PIP is to get its input from the disk, the input is a file name; if the input is from a paper tape, no file name is given. Similarly, if PIP is to output to the disk, the file name is indicated; if output is to paper tape, no name is given. To call PIP, type: .R.PIP PAPER TAPE TO DISK TRANSFERS U pdpC:1 ldpt: to OlSK, stnk:e the RETURN key when PIP requests INPUT: Since PIP must output to the disk, respond to OUTPUT: by typing a file name. When PIP requests OPTION: So >oJ "IVY\,; 9-157 type T to indicate that the paper tape is being loaded from the Teletype' reader. For example: .R PIP INPUT: OUTPUT: FILEl OPTION:T The paper tape in the low-speed reader is read and stored in the system as FILE t. DISK TO PAPER TAPE TRANSFERS To move a disk file onto paper tape, the use of file names is reversed since PIP must input a disk file and output it to paper tape. The option remains the same. For example: .R PIP INPUT:FILEl OUTPUT: OPTION:T The contents of FILEt are then punched at the Teletype. HIqH-SPEED READER/PUNCH ASSIGNMENTS , ' P I P can also be used with high-speed paper-tape devices. The format of the INPUT: and OUTPUT: responses is the same. However, for the high-speed reader, the option is R and for the punch it is P. Since the reader and punch are assignable devices, they are not always available (other users may have one or both assigned). Therefore, Whenever PIP is given a command which utilizes one of these devices, it checks t6 make sure that the device is available. If it is, PIP automatically assigns it (thus, it is not necessary to assign the device before running PIP). If the device is unavailable, PIP informs the user. For example: INPUT: OUTPUT: ABeD OPTION:R PIP reads the paper tape in the high-speed reader and stores it in the system as ABCD. 9-158 INPUT:ABCD OUTPUT: OPTION:P PIP punches out file ABCD on the high-speed punch. INPUT:ABCD OUTPUT: OPTION:P DE:VICE NOT AVAILABLE The punch is assigned to another user, or there is no punch on the EduSystem 50, or there is one but it is turned off. BIN FORMAT FILE TRANSFERS The examples above work for all ASCII file transfers (except BASIC programs, explained below.) They are also valid for punching BIN files with either high- or low-speed devices. Loading BIN format tapes, however, is a special case. BIN format tapes must end with trailer codes. The easiest way to ensure that they do is to cut off the tape near the end of the trailer code. Failure to do this (or cutting it off very unevenly) does not prevent PIP from loading tape into the disk file. However, later attempts to load the file with LOADER will result in load errors. NOTE Some installations do not allow any BIN format tapes to be loaded from the lowspeed reader. lVIOVING DISK FILES PIP can be used to move the contents of one file into another. This is often useful in copying a file from another user's library (providing the file is not protected) into your own library. To copy from disk file to disk file, specify a file name for both input and output. Reply to OPTION: by striking the RETURN key. For example: I NPUT: F n r: A L ;~ OUTPUT: F()I~{\LX OPTIO:--J: PIP gets FOCAL from account number 2's library and moves it into the file FOCALX. 9-159 DELETING DISK FILES One of the principal reasons for punching files on paper tape is to free disk space. Once punched, the disk file is no longer needed. PIP offers a convenient means of deleting files, the Delete option: INPUT:ABCD OUTPUT: OPTION:D PIP deletes file ABCD, provided that the file is not protected against being changed. BASIC FILE TRANSFERS BASIC stores its programs in a unique file format. Therefore, it is not possible to load 'or punch BASIC files in the usual way. To provide a convenient means of handling BASIC programs, the B option is available in ~IP. The B option is used for both reading and punching BASIC programs. The responses to INPUT: and OUTPUT: indicate the' direction of the transfer; the high-speed reader or punch is always assumed for the B option. (To read or punch tapes at low-speed, use BASIC itself.) PIP assumes that any BASIC tapes it loads are clean and·errorfree. Only tapes actually created by -BASIC should be loaded with PIP. Tapes created off-line, and thus liable to contain errors, should be loaded low-speed by BASIC itself with the TAPE command. SAVE FORMAT FILE TRANSFERS Another special file format is that of the SAVE files, those pro- . grams directly executed by EduSystem 50. (The System Library Programs are examples of SAVE format files.) PIP provides the S option, to allow these files to be punched on paper ~ape. SAVE format tapes make sense only to PIP. They cannot be input to / any other System Program. The responses to INPUT: and OUTPUT: indicate the direction of the transfer; the high-speed reader or punch is always assumed for the S option. 9-160 NOTE SAVE format tapes include a checksum. If PIP detects an incorrect read, it prints LOAD ERROR, and terminates the load, repeating the request for input. Table 9-19. PIP Option Summary --------------------.....----------------------------------Option Explanation -------------------------------------------------------T Transfer a file between the disk and the Teletype reader or punch. The response to INPUT: and OUTPUT: indicates the direction of the transfer. R Read a tape from the high-speed reader and store it as a disk file. P Punch the contents of a disk file on the high-speed punch. D Delete the file specified for input. B Transfer a BASIC program file between the disk and the high-speed reader or punch. The response to input and output indicates the direction of the transfer. S Transfer a SAVE format file between the disk and the high-speed reader or punch. The response to INPUT: and OUTPUT: indicates the direction of the transfer. COpy Program Many EduSystem 50 installations' include one or more DECtapes. For these installations. DECtape provides a convenient and inexpensive means of file storage. The COPY program is used to transfer files between disk and DECtape. USING AND CALLING COpy COpy is thc intermediary betwecn disk and DECtape. To write a disk file out to DECtape. COpy inputs the file from the disk. then outputs it to the DECtape. To bring a DECtape file onto the disk, COpy inputs from the DECtape. then outputs to the disk. 9-161 Files kept on DEC tape have file names just as they do on the disk. To avoid confusion, the user must tell COpy where the file is to be found. If it is on DECtape, the DECtape designation and the number of the DECtape unit must preface the file name. The DECtape number is always separated from the file name by a colon. Thus DI :FILEI means the file name FILEI on the DECtape which is currently mounted on DECtape unit number one. The number of available tape units varies among installations. The maximum is eight (numbered 0-7). If a file name is not prefaced by a DECtape number, the file is assumed to be on the system disk. Files stored on DECtape do not have protection codes in the sense that disk files do. They are, however, protected against unauthorized access. When a DECtape is not mounted, it is not available to any user. When it is mounted, it is available only to the user who has assigned the DECtape unit on which it is mounted. Even then it can not be altered unless the DECtape unit is set to WRITE ENABLE. Users should be sure to assign a DECtape unit before mounting their tape, and dismount the tape before releasing the device. Normally, the DECtape unit to be used should be assigned before calling COPY. To call COpy, type: .R COpy COPY responds by asking which option the user wishes to employ. The COPY options are discussed below and summarized in Table 9-20. LOADING FILES FROM DECTAPE To load a file onto the disk from DECtape, use the COPY option. When COPY requests OPTION, respond with COpy, or C, or strike t~e RETURN key (the COPY option is assumed). When COPY requests INPUT, type the number of the DEC tape . unit on which the file can be found (DO, DI, D2, D3, D4, D5; D6, . or D7) followed by a colon and the name of the file on the DECtape. When' COpy requests OUTPUT, type and enter the name to be given to the output file on the disk. COPY then moves the DECtape file onto the disk. '(Wilen using COPY, it is 9-162 not mandatory to insert a space between the device designator and tht~ device number.) For example: OPTION- COpy INPUT - D4:PQR OUTPUT - PQR If for any reason, COpy cannot find the DECtape file specified for input (the specified DECtape is unavailable or nonexistent, or the file name does not exist on that DECtape), COpy prints a ? and repeats the request for input. If the disk file specified for output already exists, COPY prints a ? and repeats the request for output. COPY does not overwrite an existing file. For example: OPTION - C INPUT - D9:PQR ?INPUT - D4:PQR~ ?INPUT - D4:PQR OUTPUT - FILEl ?OUTPUT - PQR SAVING DISK FILES ON DECTAPE Savjng a disk file on DECtape is very similar to loading one. The option is still COPY. For input, respond with the name of the file on the disk. For output, type the DECtape unit number, colon, and the name to be given to this file. For example: OPTIO:\l - C I!'JPUT - ABeD OUTPUT - D4:ABCD If Copy cannot find the file on the disk, or if it is protected, COpy prints a ? and repeats the request for input. If COpy cannot create the desired DECtape file (the specified DECtape does not exist or is unavaihlble, or it is not WRITE ENABLED, or a file by that name already exists on the tape) COpy prints a ? and repeats the request for output. LISTING DIRECTORIES COpy can be used to list the directory of a device. To list a directory, respond to OPTION by typing LIST, or just L. COpy then asks which device directory it is to list. To list a DECtape 9-163 directory, respond with the device name (DO, ... ,D7). Do not follow it by a colon. For example: .R COpy OPTION- LIST INPUT- D 1 1372. FREE BLOCKS NAME SIZE BASIC .SAV 66 FACTAL.BAS 10 CONVER. BAC6 PALD .SAV 32 DATE 9-MAR-70 2-MAR-70 1-MAR-70 31-MAR-70 The unit of DECtape storage is the block, which is 128 (decimal) words. Because the unit of disk storage, the segment, is generally 256 words, a file occupies twice as many blocks of DECtape storage as· it did segments on the disk. COpy can also be used to list the user's disk directory. Use the LIST option, but respond to DEVICE by simply striking the RETURN key. The directory listing is similar to the listing obtained by running the CAT program. DELETING FILES COpy can be used to delete files, either on the disk or on a selected DECtape. To delete a file, respond to OPTION by typing DELETE, or just D. Respond to INPUT by typing the name of the file to be deleted. If the file is on a DECtape, preface the . file name with the DECtape unit number and a colon. For example: OPTION - DELETE INPUT - D4 :ABCD If COpy cannot find the file to be deleted, or having found it, cannot delete it (it is a protected disk file or a DECtape file on . a unit which is not WRITE ENABLED), COPY prints a ? and repeats the request for INPUT. DELETING ALL EXISTING FILES ON A DEVICE COpy can be used to delete all existing files on a device. To do so, respond to OPTION by typing ZERO, or just Z. When COPY requests INPUT respond with the name of the device. To delete all files on the disk, strike the RETURN key. The ZERO option 9-164 should also be used to format a blank DECtape before attempting to copy any files onto it. For example: OPTION - ZERO INPUT - D4 OPTION - Z INPUT - COpy cannot delete files from a DECtape unless it is WRITE ENABLED. -It cannot delete disk files which are write protected. Table 9-20. COpy Option Summary Abbreviation Explanation C Transfer a file between disk and DECtape. COpy L List a directory. DELETE D Delete a file. ZERO Z Delete all files. Option LIST ~ -EXAMPLE OF COPY USAGE .ASSIG~ D 5 D ·5 ASSIGNED .R COpy OPTXON - ZERO DEVICE - DS OPTION ~ LIST DEVICE - DS 1462. FREE BLOCKS ~AME SIZE DATE OPTION - LIST DEVICE: DISK i~ILES FOR USER 54,40 ON 27-MAY-70. NAME SIZE SOLVE .BAS 1 PROT 12 DATE 27-MAY-70 TOTAL DISK-SEGMENtS: 1 9-165 OPTION - COpy .INPUT - SOLVE OUTPUT - DS: SOLVE OPTION - DELETE INPUT - SOLVE OPTION - LIST DEVICE - D5 1460. FREE BLOCKS :JAME SOLVE SIZE 2 DATE 27-MAY-70 PT IO ~ - LIS T DEVICE- ~) DI SI-( FILES FOR USER 5 /l,40 NAME SIZE PROT ON 27-MAY-70'. DATE / TOTAL DISK SEGMENTS: 0 OPTIO\\:- COpy INPUT- D5:S0LVE OUTPUT- ABCD OPTION- LIST DEVICEDISK FILES FOR USER 54,40 ON 27 - MAY - 70 • NAME ABCD SIZE 1 PROT 12 DATE 27-MAY-70 TOTAL DISK SEG~ENTS: OPTION- RENAME INPUT- ABCD OUTPUT- FIE.BIN <17> OPTION- LIST DEVICE-DISK FILES FOR USER 54,40 ON 27-MAY-70. NAME SIZE FIE • BIN 1 PRO'T 17 DATE 27-MAY-'70 OPTION- 'BS .RELEASE 0·5 9-166 ADVANCED MONITOR COMMANDS Introduction The fundamental Monitor commands described previously are those needed to utilize existing System Library Programs. The EduSystem 50 Monitor also provides powerful commands for ~sers who wish to create their own library programs. To use the System Library Programs described previously, it was not necessary to be familiar with the actual machine that runs them, the PDP-8/E. To create new library programs for Edu-' System 50, this is necessary because they are written in the PDP... 8 assembly language. The user codes his programs for a 4K PDP-8, subject to the time-sharing conventions discussed in this section. The programs are created with EDIT, then assembled by PAL-D and loaded by LOADER. Only at this point are the programs able to be run by EduSystem 50. In the course of this program development, the same program exists in many formats. The source program is a disk file containing ASCII characters in an Editor format. P AL-D reads the file and translates it into a second file, the assembled program in BIN format. Neither of these files is capable of being executed directly by EduSystem 50. The BIN format tape must be loaded into core by LOADER before it can actually be executed. At this point it is possible to save the program in a file format that is directly executable by EduSystem 50. Such a file, caned a SAVE format file, contains an image of the user's core area after the program has been loaded by LOADER. These SAVE format files differ from, all the files which are created by System Library Programs and cannot be executed directly by EduSystem 50. Thus, it is not possible to save a BASIC program (e.g., FILEt while running BAS]C), then return to Monitor, type R FILEt, and get meaningful results. The program in FILEt must be executed under control of the BASIC language processor. Only SAVE format files can be called into execution directly by the R command. (All System Library Programs are stored in SAVE format and can be run with the R command.) 9-167 NOTE In the following examples, Sn, Cn, and Dn are used to stand for alphanumeric strings (such as file names), octal numbers, and decimal numbers, respectively. A number of Monitor command conventions are available to make the commands easier to use. First, more than one command may be typed on a line. Individual commands are separated by a' semi-colon (;). Second, only enough characters of a command to uniquely specify it need be typed. Thus, DEPOSIT can be abbreviated DE or DEP . • LeAD FILEl; DEP 20 7000; ST 200 is exactly equivalent to: .LOAD FILEl .DEPOSIT 20 7000 .START 200 These conventions are available for the elementary Monitor commands as well. They are, however, especially convenient for the advanced commands. Control of User Programs Once a P AL-D program has been loaded by LOADER, several Monitor commands are available for controlling its execution. These commands are shown in Table 9-21. It is possible to give these utility commands while a user program is running. The CTRL/B character (tB) gets the attention . of the Monitor without stopping program execution. (tB followed by the S command stops the program.) tB can be. used together with the WHERE command to follow program execution. After executing these commands, Monitor does not put the Teletype back into Monitor mode. 9-168 Table 9-21. Monitor Program Control Commands ------------------------------------------------------Command Explanation START Cl Start execution of a user program at location Cl. When a program is started, keyboard input is no longer interpreted as commands to Monitor. Input characters are passed to the running program. START Cl c1ears the user's AC and link. START Restart execution of a user program where it was interrupted (either by execution of an HLT or by tBS typed at the keyboard) . When the START command is given, the program's state is restored. DEPOSIT Cl C2 ... Cn Deposit the octal values C2 to Cn in the locations starting at C 1. DEPOSIT is used to make small octal modifications to a liser program. No more than 10 decimal locations can be modified by a single DEPOSIT instruction. EXAMINE Cl Print the octal contents of location Cl. EXAMINE Cl D 1 Print the contents of Dl locations starting at Cl. WHERE Print the present status of the user program. The user's AC, PC, and LINK are printed. If the processor includes the extended arithmetic element, two additional registers, the SC and MQ are printed. . Defining Disk Files The Monitor allows the user to save core images of his program on the disk for future use. However, before saving such a core image, the user must define a disk file in which to save it. Disk files, like the user's core, are made up of 12-bit words. Unlike the user's core, which is always 4K in size, a file can be any s,ize. The unit of disk file storage is the segment; in most installations a segment is 256 (decimal) words but: can be from 9-169 128 to 1024 words long. Files are at least one segment long when created and g~ow by appending additional segments to the . end of the file. In defining a file, the user first creates it, then extends it to whatever length he needs. To have a whole 4K image ona system with a. segment size of 256 (decimal) words, a 16 segment file is required. If only part of the contents of the user's core is to be saved, a correspondingly smaller file can be used. A file can be created at any time. However, to modify or redefine it in any way, the file must be open. Up to four files can be open for a user simultaneously. Opening a file connects it to an internal open file number (0, 1, 2, or 3). Once a file is open, 'it is referenced by this internal file number rather than by its file name. CREATING A DISK FILE The CREATE command defines em area of· disk space and associates it with the name given in the command line. The file name can be ohe to six alphanumeric characters of which the first must be a letter .. Creating a file deletes any existing file of the same name, unless that file is write protected. When created, files are always one segment in size. A new file is arbitrarily assigned a protection code of 12, meaning that other users may access it but only the owner may change it. Until it bas been written, the contents of a newly defined file are undefined. OPENING AND CLOSING A FILE To use a file, it must first be 9pened with the OPEN command. A file can be opened on any of four internal file numbers: 0, 1, 2, or 3. A user can have up to four files open at a time. If a file is open on an internal file number for which a file is already open, that file is first closed. For example: .CREATE An .Op·F:--J 1 AB AB is now an open file and can be referenced as file 1. An open file can be closed at any time by means of the CLOSE command. Once closed, a file cannot be accessed in any way until it is reopened. It is possible to close more than one file with a . single command. For example: 9-170 .CLOSE: (3 1 2 3 EXTENDING, REDUCING, AND RENAMING A DISK FILE 'When created, a file is one segment long. If a larger file is needed, the original file can be extended. For example, the command: .. EXTENU Cl Dl extends the file presently open on internal file Cl by Dl segments. Extending a file adds one or more segments to the end of that file. The contents of the old part of the file are not changed. Until written, the contents of the newly added, segments are unspecified. An existing file may be reduced in size by means of the REDUCE command. For example, the command: .. RE:UUCr.: C 1 Dl reduces the file presently open on internal file Cl by Dl segments. Reducing a file deletes the number of segments indicated from the end of the file. The contents of remaining segments of the file are unchanged. If a file is reduced to zero segments, or if D 1 is greater than the number of segments in the 'file, it is deleted entirely. An example of the creation and deletion of a 4K file: • CREATE • OPEN 3 .' EXTEND .REDUCE FOURK FOUHK 3 15 :3 16 Existing opened files can be renamed. Renaming a file does not c:hange its contents in any way. For example, the command: .RENAME,Cl 51 - renames as S1 the file open on internal file number C 1. PROTECTION CODES The user can protect his files against unauthorized ac£ess. He .canalso specify the extent of -access certain other users can have 9-171 to his files. For example, a user's associates can be permitted to look at the data of certain files but not permitted to alter that data. When it is created, a file is assigned a protection code of 12. This protection code is defim~d below and can be changed (see Storage Allocation), but only by the owner of that file. For example, the command: .PROTECT Cl C2 gives the protection code C2 to the file open on internal file number Cl. The protection code is actually a 5-bit mask. Each bit specifies a unique level of protection. (See the PROTECT lOT command for the meaning of each bit.) File protection masks (C2) are assigned as follows: 1 Read protect against users whose project number differs from owner's. 2 Write protect against users whose project number differs from ownet;'s. 4 Read protect against users whose project number is same as owner's. 10 Write protect against users whose project number is same as owner's. ,20 Write protect against owner. To change the program the owner must change the protect code. Protection codes are determined as the unique sum of any of the above codes. Some of the more common protection codes are as follows: Explanation Command PROTECT 1 12 Allow other users to access the file but not change it. PROTECT'1 17 Allow only the file owner to read the file. He can also change it. Allow only the file owner to read the file. He cannot, however, change it. (To change it, he must first change the protection.) PROTECT 1 37 9-172 Code Explanation .PROTECT 1 0 Allow other users to access the file and change it. Finally, .. the user can ask what file is open on a given internal fik number by means of the F (File information) command. For example, the command: -,F' C 1 prints the following information about the file presently open on an internal file C 1 : a. b. c. d. Account number of file owner. Name of file. Protection code. Size of file in segments (decimal). For example: •F 1 0010 TYPE 0012 2 ERROR CONDITIONS There are a number of error conditions which prevent the ex-. ecution of the file definition commands (as previously described). One of the following error messages is printed by Monitor if an error condition is detected: Message Explanation FILE NOT OPEN An EXTEND, REDUCE, PROTECT, or RENAME command has been issued for an internal file number for which no file is open. PROTECTION VIOLATION An attempt has been made to change a file which is write protected against the user. 9-173 Explanation Message FILE IN USE An EXTEND, REDUCE, PROTECT, or RENAME command has been issued for a file .which is in use elsewhere by another user. Because changing a file which is being used (i.e., has been opened) could disrupt another user'& work, under these conditions such a change is prohibited. DIRECTORY FULL A CREATE command· has been issued, but the user's directory is full. He can delete any of his files to make room for the new file. FILE NOT FOUND the user has attemped to OPEN a nonexistent file. FAILEDBYn SEGMENTS The user has attempted to extend a file, but the system has run out of disk segments. The number of segments requested, but not available, is printed. Saving and Restoring User Programs Once a file has been defined, the user can save all or any part of his Jlser core in the file. Files and user core are addressed in the same way, by 12-bit words. The user can transfer his file into any part of core. The SAVE command requires one to five parameters.· The name of the file to be written into must always be given. If the file is not in the user's own library, the appropriate account number is entered before the file name. (Writing into a file owned by another user is subject to file protection.) In either case, the 9-174 parameters are separated by spaces. The SAVE command writes the indicated section of core out into the indicated file. H no parameters follow the file name, Monitor starts at location zero of the user's core and saves it in location zero of the disk file. It continues to write core locations into the disk file until: ( a) it has written the whole 4 K or (b) it has filled the file. Either condition completes the SAVE. The user can further define his SAVE command by indicating parts of core to be saved in specific parts of the disk file. He does this by typing one to three parameters following the file name. The first parameter following the file name indicates a specific disk file address at which to begin writing. The second parameter following the file name indicates a specific core address at which to terminate the transfer. If only the first two parameters are typed, the transfer terminates when either the end of core or the end of file is reached. Command Explanation SAVE SI SAVE Cl SI Assuming that a disk file S 1 exists, and th~tit is not write protected, the contents of core are saved in S 1. In the first case, S 1 is assumed to be in the library of the user giving the command. In the second case, it is assumed to be in the library of the user whose account number is Cl. SAVE Cl C2 C3 C4 Localions C3 to C4 (inclusive) are saved in file SI starting at disk file location C2. SI is assumed to be in the user's own library. If S1 is preceded by the parameter C 1, it IS assumed to be in the library of the user whose account number is Ct. Once a core image has been saved in a disk file, it can be restored to core by means of the LOAD command. It should be noted that the Monitor command LOAD is very different from 9-175 the System Library Program LOADER. LOADER loads a BIN format file (created by PAL-D) into the user's core. LOAD loads a SAVE format file (created by a previous SAVE command) into core. The LOAD command requires from one to five parameters. The name of the- file to be loaded must always be given. If the file is in the user's own library, this file name is typed after the SAVE command itself. If it is in another user's library, his account number is entered before the file name. (Reading another user's file is subject to file protection.) In either case, the parameters are separated by spaces. Command Explanation LOAD Read the indicated section of a disk file into the indicated section' of core. LOAD SI LOAD Cl SI Assuming that a disk file SI exists, and that it is not read protected, _the contents of the file S 1 are loaded into core. In the first case S 1 is assumed to be in the library of the user giving the command. In the second case, it is assumed to be in 'the • library of the user whose accounJ number is D 1. The user can further define his LOAD command by using the same optional parameters discussed in the section on the SAVE command. Command Explanation LOAD SI C2 C3 C4 Locations C3 to C4 (inclusive) are loaded from file SI starting at file location C2. LOAD NEWF 5 10 17 Words 5 to 14 (inclusive) of the file named NEWF are loaded into locations 10 to 17 of the user's core. 9-176 It is not necessary to open a file before using it in a LOAD or SAVE command. Both commands automatically open the specified file on internal file number 3 before performing the transfer. After completion of the command, the file remains open on file number 3. A special macro-command, RUN, exists to allow a program to be loaded and started all in one command. Command Explanation RUNS1 RUN Cl S1 Load file S 1 into core from the disk and start execution af location O. In the first example, file S 1 is assumed to be in the user's own library. In the second, it is assumed to be in the library of the user whose account number is C1. RUN S 1 is exactly equivalent to LOAD S1; START O. RUN Cl SI is exactly equivalent to LOAD Cl S1; START O. The R command (see the section EduSystem 50 Monitor) is a special case of the RUN command. For example, the command: .R 51 loads file S1 from the System Library (account number 2) and starts at location O. R SI is exactly equivalent to RUN 2 S1. Utility Commands The Monitor provides a number of special purpose commands to aid in program development and use. The Monitor utility commands are summarized in Table 9-22. 9-177 Table 9-22. Monitor Utility Commands Command Explanation USER Print the number of the job connected with this user and the console number of the job. USER Cl Print the console numbers of job C 1. SWITCH Cl Set the user's switch register to Cl. Monitor maintains a switch register for each user. When his program executes on OSR (OR the switch register into the AC) this value is the one which is loaded. BREAK Print the current value of the user's delimiter mask. BREAK C] Set the user's delimiter mask to C 1. (The use of the delimiter mask is discussed in the chapter on assembly language programming. DUPLEX Place the user's Teletype in duplex mode. All characters typed at the keyboard are automatically printed as they are entered. UNDUPLEX Take the user's Teletype out of duplex mode. Input characters are received by the Monitor and by the user program without their being printed at the console. RESTART Cl Set the user program restart address to Cl. If CTRLI C is typed at the keyboard, Monitor forces a jump to location Cl in the user's program. VERSION Print the version of the Monitor being used. 9-178 WRITING ASSEMBLY LANGUAGE PROGRAMS Introduction In addition to tlIe higher-level programming languages available in the EduSystem 50 library, the user can also code and run programs written in the PDP-8 assembly language, PAL-D (Program Assembly Language). These programs are prepared with EDIT, assembled with P AL-D, then loaded with LOADER. For those users unfamiliar with assembly language programs, Introduction to Programming 1972 is a useful guide. A user can program EduSystem 50 just as he would any other 4K PDP-8. (Assembly language programs must fit in 4K of core.) All memory reference instructions (AND, TAD, ISZ, DCA, JMS, and JMP) function as on a stand-alone PDP-8. All operate instructions (instruction code 7) also function as on a regular PDP-8 (except that microcoding HL T or OSR with any other operate instruction but CLA gives unpredictable results). The major difference between EduSystem 50 programming and regular PDP-8 programming is in the lOT (input/output transfer) instructions. Some instructions which are valid on stand-alone PDP-8s, such as CDF, CIF, ION, IOF are considered illegal instructions under timesharing. There are a great many new lOTs within EduSystem 50 that are not valid on a regular PDP-8. Finally, there are lOTs which operate on EduSystem 50 in the same manner as on stand-alone PDP-8s. (Table 9-24 is a summary of EduSystem 50 lOT Instructions.) The way EduSystem 50 actually executes an lOT instruction is also different. Non-lOT instructions (except HLT and OSR) are executed by the hardware, while lOTs (and HLT and OSR) are executed. by the EduSystem 50 Monitor. In general, EduSystem 50 provides the programming capabilities of a 4K PDP-8 and allows programs of consideral?ly greater complexity to be run within the constraints of each user's 4K of core. System Library Programs, all of which were written in assembly language and make use of the EduSystem 50 lOTs dealt with below, are examples of programs which can be run on EduSystem 50. 9-179 Console I/O User programs handle console (Teletype) I/O in almost the same way as stand-alone PDP-8 programs. Tlie KRB instruction is ~sed to input a character, the TLS instruction to output a character. The KSF and TSF (followed by JMP. -1) can be used but are not needed. Monitor handles all timing problems whether these skip lOTs are present or not. EduSystem 50 differs from the stand-alone PDP-8 in that under EduSystem 50 the user program interacts with multi-character input and output buffers (maintained by Monitor) rather than with single character registers. Depending on the state of the system, these buffers may have one, many, or no characters in them. During normal program execution, this fact is of no consequence. User programs still send and receive characters one at a time. There are times, however, when it is useful to clear out any and all characters in the buffers; a special lOT exists for this purpose (SBC). On a stand-alone system, characters are input as soon as they are typed, whether they are of immediate interest or not. Usually, these characters are stored by the program until a terminating (or delimiting) character is found. At this time, the whole line of characters is processed. On a swapping, time-sharing. system such as EduSystem 50, this mode of operation is wasteful. It is far more efficient to allow input characters to accumulate in the Monitor input buffer until a delimiter is fouOd. There is an lOt to specify which characters are to be considered delimiters (KSB). EduSystem 50 also allows programs to input and output strings of characters. The read string (KSR) and send string (SAS) instructions provide a convenient and efficient means of doing lengthy transfers. All keyboard input uses full-duplexed hardware; there is no wired connection between the keyboard and printer (Le., characters are not printed on the console as typed). Input characters are echoed to' the console under program control rather than by hardware. Because input characters are allowed to accumulate in buffers before being pass~d to the user program, it is important to have Monitor perform the echoing rather than user programs. There is an lOT (DUP) to .set up this automatic echoing as well as an lOT (UND) to inhibit echoing for such operations as reading tapes. 9-180 Read Keyboard Buffer (KRB) Octal Code: 6036 Operation: Read the next input character into bits 4-11 of the AC. Load Teleprinter Sequence (TLS) Octal Code: 6046 Operation: The ASCII character in AC bits 4-11 is printed on the user's console. Skip on Keyboard Flag (KSF) Octal Code: 6031 Operation: The next instruction is skipped if there is a delimiter character in the user's input buffer. Read Keyboard String (KSR) Octal Code: 6030 Operation: Execution of this instruction initiates a transfer of one or more characters from th~ user's keyboard to a designated core area. Before executing KSR, load the AC with the address of a two-word block, where: Word 1: negative of the number of characters to be transferred. Word 2: address of the core area into which characters are to be placed minus one. The transfer is terminated when either: a. the indicated number of characters have been input or b. a dclimiter is seen. At the end of the transfer, the word count and core address are updated and the AC is cleared. Send A String (SAS) Octal Code: 6040 Operation: Before executing an SAS, load the AC with the address of a two-word block, where: Word 1: contains the negative of the number of characters to be sent. Word 2: contains the address -1 of the first word of the string. The characters are stored one per word right justified starting at the address specified by word 2. Upon execution of SAS, the system takes only as many characters as will fit in the output buffer. It then makes the appropriate adjustment to word 2 to indicate a new 9-181 starting address and to word 1 to indicate the reduced character count; it returns to the instruction following the SAS. If the character count is reduced to zero, the instruction following SAS is skipped. The instruction following the SAS should contain a JMP .- 2 to continue the block transfer of Teletype characters. The AC is clearly by SAS. Set Keyboard Break (KSB) Octal Code: 6400 Operation: Rather than activate a user's prog~am to receive each character as it is typed, EduSystem 50 accumulates input characters until a certain character, or characters, is seen. To tell the Monitor which characters to look for (these characters are referred to as delimiters), load the AC with a 12-bit mask before executing a KSB. For each bit in the mask which is set, Monitor considers the corresponding character or characters to be delimiters. Bit o 1 2 3 4 5 6 7 8 9 10 11 Specifies 0 = check rest of mask 1 = any character is break. 301-332 (alIletters) 260..,271 (all numbers) 211 ( Horizontal tab) 212-215 (line feed, vertical tab, form feed, RETURN) 241-273 (! " # $ % & *+ ,- ./ : ;) 240 (space) 274-300 « = >? @) 333-337 ([ / Jt ~) 377 (RUBOUT) 375 (ALT MODE) anything not in bits 1-10 I Duplex (DUP) ( ) Octal Code: 6402 Operation: DU£> informs Monitor that the user wishes each character typed at the console to be echoed on that console's printer as it is received by Monitor. The DUP instruction does not affect the user's registers. 9-182 Octal Code: 6403 Unduplex (UND) Operation: . UND informs Monitor that the user wishes to suppress character echoing. This can be done for reasons of privacy or because'a program does its own character echoing. The user's registers are unaffected by UND. Set Buffer Control (SBC) Octal Code: 6401 Operation: SBC permits the user program to clear its Teletype input and/or output buffer. Before executing SBC set bits 0 and 1 of the AC as indicated below: Bit 0 Bit 1 Clear output buffer. Clear input buffer. Files and Disk 1/0 All user programs can gain access to disk storage: The timesharing Monitor maintains a pool of available disk space which is allo~ated in units referred to as segments. (The size of. a disk segment varies among installations. Segm.ents may be 128, 256, 521, or 1024 words each.) These segments are used to make up user files on the disk. Monitor also maintains, for each user, a directory of all files which he has defined. The lOTs which allow the user to access the disk are of two types: those which define files on the disk and those which transfer data between a defined file and the user's core. NOTE CREATE and OPEN require that a user set up a file name in core. FINF and WHO return file names to core. Each must be specified in internal code (excess 40 code) as shown in Table 9-23. Characters are packed two to a word. The first step in defining a file is to create it. Creating a file reserves a single segment of disk storage and associates it with a name. This file can then be extended to any length desired. Extending a file appends more segments to it. Similarly, a file can be reduced by any number of segments. Reducing a file removes th.e 9-183 last segment or segments from the file. Reducing a file to zero segments deletes it entirely. Once created, a file can be protected, thereby restricting access to it. When created, a file can be read by any user, but only the creator can write in it. This protection can be reset if desired. Finally, it is possible to rename an existing file. None of these actions affect the contents of the file-they only reserve space on the disk Until it has been written in, the actual content of a file is unspecified. Extending a file does not alter the content of the file as it previously existed. Once defined, files can be used to read and write data. Any number of words (1 to 4096) can be moved from any p'art of the user's core to any part of a file (subject to file protection). The user program specifies a location in core and a word count. This indicates how many words are to be transferred and from (or to) where in core they are to be moved. Also specified is a disk file address indicating what part of the file is involved. This address is the address of a word in the file. Files are addressed in the same manner as core: in 12-bit words. -Unlike core, however, files can be longer than 4K. To address these files provision is made for a 24-bit disk file address, containing the high-order and lpw-order file addresses. File addresses are independent of any consideration of segments. The file address is meaningfuJ only in defining files. Files can be read and written across segment boundaries without restriction. (The user cannot read or write beyond the last segment boundary.) When it exec'utes a file read or write lOT, the system updates the core address and word count and places an error code in the error word (see RFILE) if any error is detected. (The error word must be cleared before execu'ting the lOT.) At the end of a successful transfer, the word count is set to zero and the ,core address set to the last word transferred. If the transfer cannot be completed for some reason, the word count and core address indicate how much of the transfer was successful; the error word indicates the cause of the failure. All file operations except CREATE (and OPEN) require that the file be open. Up to four files can be open at a time. The process of opening a file associates it with one of four internal file numbers '(0, 1,2, or 3). All file lOTs except CREATE and OPEN, are specified in terms of one of these internal file numbers, rather than a fiJe name. lOTs operate on the file which is indicated by that internal file number at the time. It is therefore possible to 9-184 write file handling programs which are independent of the actual file (s) they operate on. ' File lOTs, that are successfully completed, return with the AC cleared. If an error was found which prohibited execution of the lOT, one of the following error codes is returned: Code Explanation 4000 There was no file opened on the specified internal file number. 4400 Attempting to redefine a file which is open to another user. 5000 Attempting to create a tIle for a user whose directory is full. 6000 File protection violation. 6400 I nvalid file name. 7000 Attempting to open a nonexistent file. 7400 Disk is full. Octal Code: 6610 Create a File (CRF) Operation: The user can request the system to create a new file' of one segment. The user program provides the new name for the file. Load the AC with the beginning address of a 3-word block, where: Words 1 through 3: contain the 6-character name. If there is some reason why the request cannot be granted, the system will return a non-zero error code in the AC. The protection code of a newly created file is 12. ' Octal Code: 661 1 Extend A File (EXT) Operation: To extend the length of an existing tlle, that file must be currently open. Load the AC with the beginning address of a 2-word block, where: Word I: contains the internal file number of the file to be extended. 9-185 Word 2: contains the number of segments the system should append to the file. If for some reason the request to exte~d a file cannot be granted, the AC will contain 4000, 4400, 6000, or the number of segrrients it failed to append. Reduce A File (RED) Octal Code: 6612 Operation: To reduce the length of an existing file, that file must be currently open. Load the AC with the beginning address of a 2-word block, where: Word 1: contains the internal file number of the file to be reduced. Word 2: contains the number of segments to be removed. This request is granted unless !he file to be reduced is currently opened to another user or if the file is write protected against the user. Octal Code: 6600 Rename A File (REN) Operation: REN is used to change the name of a ,file. Load the AC with the address of a 4-word block where: Word 1: contains the internal file number associated with the file whose name is to be· changed. Words 2-4: contains the new name. This name characters packed two in a word. IS III 6-bit Octal Code: 6604 Protect A File (PROT) '. Operation: The owner of a file can protect his file from unauthorized attempts to access it by uSing this instruction. Before. executing PROT, load theAC with: Bits 5 and 6 Internal file number ,of the reserved file to be protecteQ. Bit 7 Write protect against owner. Bit 8 Write protect against users whose project number is same as owner's. 9-186 Bit 9 Read protect against users whose project number is same as owner's. Bit 10 Write protect against users whose project number differs from owner's. Bit 11 Read protect against users whose project number differs from owner's. A file must be opened before it can be protected. PROT is legal only when performed by the file owner, i.e., the user who created the file. All attempts to access the file which violate any of the protection flags are considered illegal. (For further information on project numbers, see the section on Storage Allocation.) Octal Code: 6601 Open A File (OPEN) Operation: OPEN is used to associate a file with an internal file number, which is necessary because all file operations are in terms of the internal file numbers. Before executing the OPEN lOT, load the AC with the beginning address of a 5-word block, where: Word 1: contains the internal file number. Word 2: contains the account number of the owner of the file. If 0, the account number of the current user is specified. Word 3-5: contain the name of the file to be opened. This name is in 6-bit characters packed two to a word. If there was another file associated with the internal file number before the execution of the OPEN lOT, it is closed automatically before the new file is associated with the internal file number. Octal Code: 6602 Close A File (CLOS) Operation: CLOS terminates the association between files and their internal file numbers. Before executing ci..os, load the AC with a selection pattern for the internal file numbers whose associated files are to be closed. The file is closed if bit I is 1, where I = bit 0, 1, 2, or 3. 9-187 READ File (RFILE) and Write File (WFILE) Octal Code: 6603 & 6605 Operation: Once the association of a file with an internal file number has been made, these lOTs allow the actual file reference to be made. They are illegal on a file that has not been opened (associated with ail internal file number). To read or write a file, load the .AC with the address of a6-word block, then execute the lOT. The format for the 6-word block is: Word 1: contains the high-order file word address. Word 2: contains the internal file number. Word 3: contains the negative of the number of words for the operation. This number is either the number of words to be read or the number of words to be written. Word 4: contains a pointer to the beginning address -1 of a buffer located in the user program. On a read operation this buffer receives the information from the file: on a write operation this buffer holds the information that is to be sent to the file; Word 5: contains the least significant 12 bits of the initial file word address to begin the operation. Word 6: contains an error code: o if no error 1 if parity error 2 if file shorter than word count 3 if file not open 4 if protection violated The read or write .begins at the word specified by. words 1 and 5. For example: TAD x WFILE x., .+1 (II 1 -200 6477 200 9-188 means: write 200 (octal) words starting at word 200 of the file that is associated with internal file number one from a core area starting at location 6500. After completion of the transfer, the word count (word 3) and core address (word 4) are updated. If an error was detected the appropriate error code is placed in word 6. File Information (FINF) Octal Code: 6613 Operation: FINF enables a user program to determine what file, if any, is associated with an internal file number. Load the AC with the beginning address of a 7-word block, where: Word 1: contains the internal file number for which the user program wishes information. Words 2 through 7: contain the information that the system returns after executing FINF. Word 2: contains the account number of the owner or zero if no file is associated with the internal file number, that is, the file is not open. Words 3-5: contains the name of the file in 6-bit code. Word 6: contains: Bit 1 Word 7: Means 7 write protected against owner 8 write protected against users whose project number is same as owner's 9 read protected against users whose project number is same as owner's 10 write protected against users whose project number differs from owner's 11 read protected against users. whose project number differs from owner's contains the number of segments which compose the file. 9-189 Assignable Devices . Users can access bqth their own Teletype and the disk; with the remaining system devices (referred to _as the assignable devices) this is not true. One function of the Monitor is to ensure that device usage never conflicts. Only one user at a time can access the high-speed paper-tape reader or punch, or anyone of the DECtapes. To ensure that only one user can access a device, EduSystem 50 requires that the device be assigned before it is used. After a device is assigned, it is not available until it is released by its owner. Once assigned, the device is programmed exactly as on a standalone PDP-8. The RRB instruction is used to read a character from the high-speed reader; the PLS instruction is used to punch one on the high . . speed punch. The skip lOTs (RFS and PSF) can be used (followed by JMP .-1) but are not necessary. For block transfers, there are two string transfer commands: RRS and PST. The DEC tape instructions have been simplified. A single instruction, DTXA, initiates the transfer of a block of data. The DTRB instruction is then used to determine if the transfer was successful. The skip instruction, DTSF, can be used (followed by JMP .-1) but is not necessary. Executing any of the assignable device lOTs without first assigning the device gives the following results: (a) If the device is assigned to another user, the instruction is considered illegal; program execution is now terminated and an error message printed; (b) If the device is available it is automatically assigned before execution of the lOT. Th(~ device then belongs to this user until he releases it. Because these devices are shared by all users, the Monitor must ensure that they are operable at all times. In particular, the Monitor must ensure that a user is not waiting for a device which is not available. This situation can arise when trying to use the punch when it is turned off, or when the reader has read off the end of a tape. All these conditions, known as "hung devices" are considered to be system errors. If the program doing the transfer has been enabled for system errors (by executing an SEA), control transfers to the error routine indicated which must clear the error flag in the status word before continuing (See Program and System Status). If the user program has not been enabled for system errors, a hung device causes the program to be terminated and an error message is printed. 9-190 Octal Code: 6440 Assign Device (ASD) Operation: If the device specified by the content of the AC is available, it is. assigned to the user program and the AC is cleared. Otherwise, the number of the job owning the device is placed in the AC. If the device does not exist, 7777 is returned in the AC. 4000 4001 4005 +N Paper-tape reader Paper-tape punch DECtape unit N The assignment is in effect until a corresponding REL instruction or LOGOUT. Octal Code: 6442 Release Device (REL) Operation: The device specified by the contents of the AC is released (providing it was owned by the user executing the REL). The AC is cleared. Releasing a device makes it available to other users. Skip on Reader Flag (RSF) Octal Code: 6011 Event Time: 1 Operation: The reader flag is sensed, and if it contains a binary 1, the contents of the PC are incremented by one so that the next .sequential instruction is skipped. The reader flag is bit 8 of status . register 1, and has a value of 1 if the reader buffer is not empty. Read Reader Buffer (RRB) Octal Codes: 6012 & 6016 Event Time: 2 Operation: The contents of the reader buffer are transferred into bits 4 through 11 of the AC and the reader flag is cleared if the reader buffer is empty. This instruction does not clear the AC. If the reader buffer is empty, the user program is dismissed until the reader flag is 1 or an end-of-tape condition is detected. 9-191 Table 9·23. Character Space ! " # $ % & ( ) * + I 0 1 2 3 4 5 6 7' 8 9 < > ? 14 EduSystem 50 Internal Character Set 6-Bit14 Octal 8-Bit Octal 06 01 02 03 04 05 06 07 10 240 241 242 243 244 245 246 247 250 251 252 253 254 255 256 257 260 261 262 263 264 265 266 267 270 271 272 273 274 275 276 277 11 12 13 14 15 16 17 20 21 22 23 24 25 26 27 30 31 32 33' 34 35 36 37 Character @ A B C D E F G H I J K L M N 0 P Q R S T U V W X Y Z [ '" ] t ~ 6-Bit 14 Octal 40 41 42 43 44 45 46 47 50 51 52 53 54 55 56 57 60 61 62 63 64 65 66 67 70 71 72 73 74 75 76 77 8-Bit Octal 300 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 333 334 335 336 337 The 6-bit octal code is used to store passwords and file names only_ 9-192 - Reader Fetch Charact.er (RFC) Octal Code: 6014 . Event Time: 3 Operation: The reader flag and the Monitor reader buffer are both cleared, the reader is started to fill the Monitor reader buffer and the reader flag is set after the buffer is full or the end of tape is detected. Read Reader String (RRS) Octal Code: 601.0 Operation: This instruction initiates a transfer from the high-spe(!d reader to a selected area in the user's core. Before executing RRS, load the AC with the address of a 2-word block, where: Word 1: minus the number of characters to be transferred. Word 2: the address of the user core area minus one. The transfer is terminated by either of two conditions: (a) the word count is zero indicating that the required number of characters have been read or (b) the reader has read off the end of the tape (a system error condition). In either case, the word count and core address are updated. RRS clears the AC. Load Punch Buffer Se:quence (PLS) Octal Code: 6026 Operation: The ASCII character is in AC bits 4 through 11 and is transmitted to the high-speed punch. PLS does not clear the accumulator. Skip on Punch Flag (PSF) Octal Code: 6021 Event Time: 1 Operation: The punch flag is sensed, and if it contains a binary 1, the contents of the PC is incremented by one so that the next sequential instruction is skipped. The punch flag is bit 9 of status register 1, and has a value of 1 if the punch buffer is not full. If the punch flag is 0, the program is dismissed until the punch flag is 1. ~9-193 Octal Code ': 6020 Punch String (PST)' Operation: PST allows a user program to punch a string of characters. Before executing PST, load the AC with the beginning address of a 2-word block, where: Word 1: contains the negative of the number of characters to be punched. Word 2: contains the beginning address -1 of the string to be punched; the characters should be right justified one per word. After execution of PST, the system takes only as many characters as fit in the punch buffer; it then makes the appropriate adjustment to word 2 to indicate a new starting address and to word 1 to .indicate the reduced character count. It returns to the instruction following the PST which should be a JMP .- 2 to continue the transfer. If the character count is reduced to zero, the instruction following PST is skipped. The AC is cleared by PST. Load Status Register A (DTXA) Octal Code: 6764 Operation: DTXA allows a user program to read and write records ( 129-wordblocks) on DECtape. Load the AC with the beginning address of a 3-word block, where: Word 1: contains: Bit 1 Means 0-2 contains the transport unit select number, 3-5 0, 6-8 ~ 9-11 2 for read data function, 4 for write data function, O. Word 2: '. contains the DECtape blo'ck number. Word 3: contains the beginning core address -1 of record buffer. 9-194 After DTXA is given, the DECtape request is placed in the DECtape request queue. After the completion of any DECtape request, the DECtape flag in status register 2 is turned on. DTXA does not update word 3. The AC is cleared by DTXA. Skip on Flags (D~SF) Octal Code: 6771 Operation: The content of both the error flag and the DECtape flag is sampled, and if either flag contains a binary 1, the content of the PC is incremented by one to skip the next sequential instruction. If both flags are zero, the user program is dismissed until the skip is satisfied. Read Status Register B (DTRB) Octal Code: 6772 Operation: The content of DECtape status register B is loaded into the AC by an OR transfer. The AC bit assignments are: Bit Assignment o error flag mark track error end of tape select error parity error timing error unused DECtape flag 1 2 3 4 5 6-10 11 Program Control There are a number of ways thatthe status of a running program can be changed. The program can be terminated in one of three ways: by execution of a HLT, by the user typing tBS to force a program halt, or by a program error which forces Monitor to terminate the program after printing an error message. It is also possible for the status of a running program to change without it being terminated. First, the user program can request that it handle its own program error conditions. In this case, Monitor does not terminate a job on an error; instead, it transfers control to a user error handler. This error handler then determines what the error was, by a CKS instruction and takes appropriate action. Monitor also provides the program with an interrupt key, tC. If the user types a tC, the Monitor unconditionally transfers 9-195 control to. a restart address. Thus, the user program can handle its own restarts. Halt (HLT) Octal Code: 7402 Operation: This instruction is used to stop the user program and . return control to Monitor. Executing HLT is equivalent to typing tBS followed by RETURN. Set Restart Address (SRA) Octal Code: 6417 Operation: This instruction allows the user to specify an address to which control is transferred when an tC is typed on the user's console. Load the AC with the restart address and execute SRA. If tC is detected, the program's input and output buffers are cleared, the AC and Link are cleared and control goes to the restart address. Set Error Address (SEA) Octal Code: 6431 Operation: This instruction allows the user to specify an address to which control is transferred in the event of a system error. Load the AC with an address before executing SEA. If a system error is detected, Monitor simulates a JMS to the error address. The program counter is stored in the error address and control transferred to the error address + 1. AC, Link, and input! output buffers are not affected. The error code of the system error is in STRO bits 9-11. Bit 10 of STRI is set. The error" routine must read these bits (by a CKS) to determine the cause of the error, then clear them by means of a CLS. The only error code that occurs in the course of normal system usage is due to a hung device. This error occurs when the user attempts to use a punch not already turned on, access a DECtape not yet selected, or allows the paper-tape reader to run off the end of a tape. The error routine must release the device to clear the error condition. The illegal lOT error probably means that an assignable device lOT was executed without the device first being assigned. Swap and file errors occur if a hardware error is detected while Moni~or is swapping user program.s or while reading or writing file directories. These are system malfunctions from which there is no recovery. 9-196 Program and System Status Because EduSystem 50 programs run under control of a timesharing Monitor, it is important for them to determine their status within the system and the status of the system as a whole. Several lOTs, listed below, have been defined for this purpose. Octal Code: 6200 Check Status (CKS) Monitor maintains for each user a complete set of status information, his program's running status and the state of his input/output devices. This status information, stored in three words, can be accessed by a running program with the CKS instruction. Before executing a CKS, load the accumulator (AC) with the address of a three-word block. Executing CKS stores the three status words (STRO, STR1, and STR2) in the three-word block and clears the AC. Information about the status of individual devices can also be checked by the skip lOTs. The formats of these registers are: STRO Bits o 1 2-4 5 6 7 8 9-11 Run Bit Error Enable JSIOT JSIOTC JSEXON Error Code User program is in the run state Program handles its own errors Unused System use only System use only System use only Unused System detected error condition 1 Illegal lOT 2 Swap read error 3 Swap write error 5 Disk file error 6 Hung device STR1 Bits o 1 2 3 4 Timer File 0 File 1 File 2 File 3 Time is up Jnternal file 0 is not busy Internal file 1 is not busy Internal file 2 is not busy Internal file 3 is not busy 9-197 STR1 Bits 5 6 7 8 9 10 Teleprinter Reader Punch Error 11 Wait There is a delimiter in the input buffer Unused Output buffer is not full Character in reader buffer Punch buffer is not full System error detected, code in bits 7 through 11 of STRO Job is not waiting DECtape Error DEC tape Unused DECtape transfer requested DECtape error DECtape flag Delimiter STR2 Bits 0-8 9 10 11 Each user has available to him a 12-bit switch register just as he does on a stand-alone PDP-8. This switch register can be manipulated by means of the Monitor command SWITCH or under program control. OR With Switch Register (OSR) Octal Code: 7404 Operation: The content of the user's switch register is inclusively ORed into the AC. Set Switch Register (SSW) Octal Code: 6430 Operation: The content of the AC is stored in the user's switch register. The AC is cleared. Assembly language programs run under control of the Monitor. The following lOTs are defined to allow a program to determine the status of the system as a whole. Segment Size (SIZE) Octal Code: 6614 Operation: The segment is the basic unit ·of on-line file storage. Different EduSystem 50's have differing segment sizes. SIZE allows a program to determine the segment size. The segment size 'is returned in the AC. 9-19g Octal Code: 6406 Segment Count (SEGS) Operation: The number of available disk segments is returned in the AC. Account (ACT) Octal Code: 6617 Operation: The account number (of the job number given) is re. turned in the AC. If AC is 0, the account number for the current job is returned. If the requested job does not exist, zero is returned. Who (WHO) Octal Code: 66-16 Operation: The account number and password of the current job are returned to the 3-word block whose address is in the AC and . the AC is cleared. User (USE) Octal Code: 6421 Operation: Return in the AC the number of the current job. Console (CON) Octal Code: 6422 Operation: Return in the AC the console unit number assigned to the job whose numbe! is in the AC, if that console number does not exist, -1 is returned. User Run Time (URT) Octal Code: 6411 Operation: Load the AC with the address of a 3-word block, where word 1 contains the number of the job for which the run time is sought. ·The run time is returned in the last two locations of the block. If job is specified, the run time of the current job is returned. The AC is cleared. ° Time-of-Day (TOD) Octal Code: 6412 Operation: Returns the value of the System Clock in military time (using a 24-hour cycle) in the two locations starting at the location of the addl:ess in the AC. The AC is cleared. Return Clock Rate (RCR) Octal Code: 6413 .t. Operation: The number of clock ticks per second is returned in the AC. 9-199 Octal Code: 6414 Operation: Returns the date in the AC. The format of this 12-bit number is: DATE= ( (YEAR-1964 ) * 12+ (MONTH-I) ) *31 + DAY-l Skip on EduSystem 50 (TSS) Octal Code: 6420 Operation: This instruction is used by programs which run under both EduSystem 50 and on a standard PDP-8. Under EduSystem 50, the instruction following TSS is skipped and the Monitor ver. sion number is returned in the AC.On a standard PDP-8, the lOT has the effect of an NOP instruction. Quantum Synchronization (SYN) Octal Code: 6415 Operation: Upon execution of this instruction, the system dismisses the user program and sets it in the run state so that it will be run again in turn. Ordinarily, this instruction is used to ensure a full time quantum to perform some critical operation. Set Time (STM) Octal Code: 6416 Operation: The system provides a clock time for each user program. By means of this lOT, the time can be set to "fire" after a specified number of clock ticks have elapsed. Load the AC with the time (in seconds) to prime the timer. Upon execution of the STM instruction, the system sets the time to "fire" in the specified number of seconds and turns the time bit (bit 0) in status register 1 to 0, clears the AC, and dismisses the job. After the speci~ fled time has elapsed, the system turns bit 0 back to 1, and the job is restarted. PDP-8 Compatibility Programming EduSystem 50 in assembly language is very similar to programming a stand-alone PDP-8. All instructions except the lOTs 'operate identically in either case. As discussed previously, programming such devices as the Teletype and high-speed reader/punch for EduSystem 50 is somewhat simpler. EduSystem 50 runs programs which include timing loops:. It also properly executes the JOTs not mentioned in this manual, e.g., TCF, PCF, etc. Thus,' programs written for stand~alone PDP-8s with Teletype 9-200 and high-speed reader or punch will run on EduSystem 50, although generally not as efficiently as programs which are written specifically for EduSystem 50. The same is not true for disk and DECtape operations because EduSystem 50 uses a simplified programming structure for these devices. The actual differences in coding are very small. It is a simple task to adapt previously written code for EduSystem 50 disk and DECtape. There are a few standard changes which users generally make in adapting PDP-8 code to EduSystem 50. Monitor does the echoing rather than the user program. The TLS which does the echo can be deleted and a DUP instruction added somewhere near the start of the program. Also, for efficiency, the EduSystem 50 delimiter capability can be used. A KSB in the program determines what the delimiters are. Many PDP-8 programs execute a reader and punch lOT early in the program, to initialize the device, whether they are actually to be used or not. If the devices are free, they can be assigned and thus made unavailable to other users. If they are unavailable, the program terminates on an illegal lOT. Thus, it is important not to execute these lOTs randomly. If disk or DECtape is involved, the actual transfer code must be altered to conform to EduSystem 50. (The fact that core page 37, locations 7600 through 7777, is available to EduSystem 50 programs is useful in making these changes. New code can be placed in the area normally reserved for the Binary Loader.) The most difficult code to convert is that code which operates under interrupt. To be run under Edu~ystem 50, these programs must be recoded so as not to use the interrupt. lOTs for nonexistent devices are ignored as are CDFs and CIFs to field zero. (Other CDFs and CIFs are illegal.) It must be remembered that many lOTs have been redefined for use as special EduSystem 50 instructions. In all other situations, EduSystem 50 remains compatible with stand-alone systems whenever possible. 9-201 Table 9-24. Number EduSystem 50 lOT Instruction Summary Instruction Program Control 6200 CKS 6402 DUP 6403 UND 6405 CLS 6411 URT 6412 TOD 6413 RCR 6414 DATE 6415 SYN 6416 STM ·6417 SRA 6420 TSS 6421 USE 6422 CON 6430 SSW 6431 SEA 6440 ASD 6442 REL 7402 HLT 7404 OSR Function Check Status Duplex Console Unduplex Console Clear Status User Run Time Time of Day Return , Clock Rate Date· Quantum Synchronization Set Timer Set Restart Address Skip on TSS/8 User Console Set Switch Register Set Error Address Assign Device Release Device Halt OR With Switch Register File Control 6406 6600 6601 6602 6603 6604 6605 6610 6611 6612 6613 6614 6616 6617 SEGS REN OPEN CLOS RFILE PROT WFILE CRF EXT RED FINF SIZE WHO ACT Segment Count Rename File Open File Close File Read File Protect File Write File Create File Extend File Reduce File File Information Segment Size Who Account Number 9-202 Table 9-24 (Cont.). Number Instruction EduSystem 50 lOT Instruction Summary Function Input Buffer Control 6030 KSR 6031 KSF 6032 KCC 6034 KRS 6036 KRB 6400 KSB 6401 SBC Read Keyboard String Skip On Keyboard Flag Clear Keyboard Flag Read Keyboard Buffer Static Read Keyboard Buffer Dynamic Set Keyboard Break Set Buffer Control Flags Output Buffer Conn"ol 6040 SAS 6041 TSF 6042 TCF 6044 TPC 6046 TLS Send A String Skip On Teleprinter Flag Clear Teleprinter Flag Load Teleprinter and Print Load Teleprinter Sequence High-Speed Paper Tape Reader and Control (Type PC02) .RRS Read Reader String 6010 6011 RSF Skip On Reader Flag 6012 RRB Read Reader Buffer 6014 RFC Reader Fetch Character High-Speed Paper Tape Punch and Control (Type PC03) 6020 PST Punch String 6021 PSF Skip On Punch Flag 6022 PCF Clear Punch Flag 6024PPC Load Punch Buffer and Punch Character 6026 Load Punch Buffer Sequence PLS , DECtape Control (Type TCOl) 6764 DTXA Load Status Register A 6771 DTSF Skip On Flags DTRB Read Status Register B 6772 9-203 9-204 STORAGE ALLOCATION Storage Map The system's storage allocation is illustrated below. DISK STORAGE CSI _r~~J~~~~-~I~;:;B ~-------MONITOR Figure 9-5. 0) I fJ (R~~\- ~::J::1 ~ FI~EJ fOB ~I.. SWAPPING AREA-+-FILE AREA------l EduSystcm 50 Storage Map File Directories There are two direCtories on the disk: the Master File Directory (MFD) referenced mainly by the system, and the User File Directory (UFO), referenced by the user. One of the functions of the MFD is to service the UFO. A UFO is a particular user's file directory containing thc names of programs he has created on the disk. The UFO is a file like any other file except that its filename is the project-programmer number and password. When a user is logged in under a specific number and references the disk, he is actually referencing his own file area on the disk through the UFD which has his project-programmer number as its name. He can specifically code hiS routine to reference UFDs of other users or the MFO; whether he is successful or not depends on the type of protection that has been specified for the area he is trying to reference. 9-205 USER FILE DIRECTORY MASTER FILE DIRECTORY WORD 1 PROJECT NO. IPROG. NO. (1 CHAR.) FI LE (1 CHAR.) (1 CHAR.) PA SS (1 CHAR.) (1 CHAR.) NA ME (1 CHAR.) (1 CHAR.) WO RD (1 CHAR.) (1 CHAR.) WO RD (1 CHAR.) LINK TO NEXT ENTRY LINK TO NEXT ENTRY UNUSED I PROTECTED BITS UNUSED SEGMENT Co,UNT CONSOLE TIME CPU TIME WORD 8 ( PROTECTED _.' BITS DATE OF CREATION POINTER TO RETRIEVAL POINTER C TO RETRIEVAL LINK TO NEXT RETRIEVAL BLOCK. 0 SEGMENT #1 SEGMENT #1 SEGMENT #2 'SEGMENT #2 SEGMENT #3 SEGMENT #3 SEGMENT #4 SEGMENT #4 SEGMENT #5 SEGMENT #5 SEGMENT #6 SEGMENT #6 ·SEGMENT #7 SEGMENT .#7 Figure 9-6. File Directories Project-Programmer Numbers . System account numbers are a combination of project number and programmer number. The account number (always written in octal) has a binary equivalent. When expressed~s a 12-bit binary number, the project number is formed by the leftmost 7 bits and the programmer number is the rightmost 5 bits. For example, the account number 623 (octal) equals 000 110 010 011 (binary). The left 7 bits (leading zeros included if any) are 0001100 (binary) and equal 14 (octal) which is the project number. The programmer number is 10011 (binary) or 23 (octal). Therefore a user with account number 623 has: project number 14 and programmer number 23. 9-206 a character codes ASCII 1 Character Set 8-Bit Character Octal 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 1 2 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 6-Bit Octal 01 02 03 04 05 06 07 10 11 12 13 14 1~ 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 ) >I< 672 736 + 800 864 928 992 / 1056 1120 1184 < 1248 l312 >? 1376 1440 @ 1504 [ 1568 "1632 ] 1696 t( 1\)2 ,-992 ~(_f.l Leader/Trailer -928 LINE FEED -864 -800 Carriage RETURN SPACE -736 RUBOUT -672 Blank -608 BELL -544 ,-480 TAB 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 33 34 35 36 37 -1952 -1888 -1824 -1760 -1696 -1632 -1568 -1504 -1440 -1376 -1312 -1248 -1J84 -1120 -1056 -352 -288 -224 -160 -96 -32 32 1760 1844 1888 1952 2016 40 -2016 72 73 74 75 76 77 An abbreviation for American Standard Code for Information Interchange. The character in parentheses is printed on some Teletypes. A-I A-2 a read ..in mode loadep The Read-In Mode (RIM) Loader is the first program loaded into an EduSystem computer.1 This program is loaded by toggling 17 instructions into core memory using the console SWITCH REGISTER (SR). The RIM Loader instructs the computer to receive and store, in core, data punched on paper tape in RIM coded format-primarily the EduSystem system tapes. There are two RIM Loader programs: one is used when the input is to be from the low-speed (Teletype) paper tape reader; the other is used when input is to be from the high-speed paper tape reader. The locations and corresponding instructions for both programs are listed in Table A-I. The procedure for loading (toggling) the RIM program into core is illustrated in Figure A-I. The RIM Loader is loaded into field zero of core. Table A-t. Location 7756 7757 7760 7761 7762 7763 7764 7765 7766 7767 7770 7771 7772 7773 7774 7775 7776 1 RIM Loader Programs INSTRUCTION High-Speed Low-Speed 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 The RIM Loader is not needed if the EduSystem has a hardware boot- strap. A-I LOAD RIM INTO FIELD 0 Figure A-t. Loading the RIM Loader 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. A-2 When loaded, the RIM Loader occupies absolute locations 7756 through 7776. EduSystems do not use the RIM locations; therefore, RIM need not be reloaded unless the contents of the RIM locations have been altered by the user. Figure A-2. Checking the RIM Loader A-3 A-4 b character codes The ASCIP character codes shown in the following table are used by EduSystems as the argument in the CHR$ function. For each ASCII code a second acceptable form is permitted in CHR$. The second code is obtained by adding 128 to the code given in the following table. For example, CHR$ would print A in response to either 65 or 193 as an argument. These codes are also used with the CHANGE statement in EduSystem 50. Character linefeed form feed RETURN space ! # $ % & ( ) '" + J 0 1 2 3 --"> 4, 5 6 7 8 9 < > ? ASCII Code No. . (Decimal) Character ASCII Code No. (Decimal) 10 12 13 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 @ A B C D E F G H I J K L M (~:-S2>-- 53 55 56 57 58 59 60 61 62 63 72 73 74 75 76 77 N 0 P 78 79 80 Q 81 R S T 82 83 84 85 86 87 88 89 90 91 U V 54 64 65 66 67 6R 69 70 71 W X y Z [ "-] t 0 0 0 10" * 0 I"" * "" " " "* 61 61 " 0" "" * 33 33 " Ii) 33 67 " D-18 I"" 0 I"" 0 * * * * "* "'" ""'" 61 '" 33 " "" * "" ""0 """ " 33 " " 33 * Ii) Ii) 33 33 1"" " " 33 " "" IIJ " " 61 "* """ "" " "" "" "" "" ""'" "" ""0 IIJ 0 " "'" "" 0 QUESTION NUMBER I 2 3 4 5 6 7 8 9 10 I 1 12 13 14 15 16 17 18 19 20 21 22 23 24 25 PAI=tT 2 NO ANSWER ANSWER ANSWER ANSWER ANSWER D(~) EU) RESPONSE B(X) C(X) A(X) 100 0 0 0 0 0 0 0 67 67 ,. 67 * 0 0 0 0 0 '" 100 33 0 0 0 0 0 0 67 0 100 33 0 0 0 33 ,.: 33 33 0 0 0 33 '" 100 0 67 ,.: 0 0 0 0 0 100 33 * 0 0 67 0 0 '" 67 * * * * * 33 0 0 100 0 0 0 100 0 0 0 100 0 0 0 100 0 0 * 0 0 ''"" '0" 67 0 100 * '" * * 33 100 0 0 * * 0 0 0 0 100 0 0 0 0 0 0 '" 100 0 67 * * * 0 0 0 0 0 )jill 0 0 33 0 0 0 '" * '" '0" * (iJ * '" 0 10'" * * 67 0 0 0 * 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...................................... .................. ~ D-19 QUESTIONANALYSrS QUESTION PART I I 2 3 4 5 6 7 8 9 1(}J 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 VALUE 1.75 1.75 3.51 3.51 .R8 1.75 .88 1.75 1.75 .RR 2.63 2.63 .R8 2.63 .RR 1.75 3.51 .88 2.63 1.15 1.75 .88 .88 .88 PART 2 PERCENT COR'RECT 10'" 1(}J(}J 33.3 IXX lYtYt 66.7 I I IX I 1 vt~ I(}JYt 33.3 IYtYt IYHJ 100 33.3 66.7 66.7 66.7 l.YtYt 100 33.3 66.7 1YtYt 1.75 HI(Ij 1.75 1.75 2.63 3.51 lYt0 66.7 66.7 66.7 33.3 10Yt lVJ0 lVJ0 66.7 1 .75 11 2.63 2.63 12 13 14 15 16 17 .88 2.63 2.63 3.51 lR 1 .75 19 20 21 1.75 1.75 1.75 2.63 3.51 1.75 .88 22 23 24 25 IX IX I I IXX IX I CORRECT 10VJ 5 lYt I I 10Yt I(}J(}J 6 7 R 9 ~xx Note the actual decimal I value assigned to each I response as a result I . of Jhe individualized ~ ~x weighting factors. lItl0 4 MIS 5 E D I I I I 1(}J(}J iV}Cil 3.51 2.63 3.51 1 .75 1 2 3 TIM E S 100 I I IX IX 66~7 66.7 I I IX IX IX IXX I I I IX I I I 100 lVJYt 10Yt 66.7 lYtYt This chart gives you the quickest look at what the most difficult questions were. IX I I 1 100 lYt0 33.3 IXX I I 1(}J0 IX .......................................................... D-20 D ISTR 1 BUT ION OF SCORES RANGE NUMBER 1~0 I 1 IX IX IX 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 I ~ 95 TO 99.99 90 TO 94.99 85 TO 89.99 80 TO 84.99 75 TO 79.99 70 TO 74.99 65 TO 69.99 60 TO 64.99 55 TO 59.99 5!i'J TO 54.99 45 TO 49.99 4!i'J TO 44.99 35 TO 39.99 30 TO 34.99 25 TO 29.99 20 TO 24.99 15 TO 19.99 10 TO 14.99 5 TO 9.99 0 TO 4.'99 0 0 '" (if 0 0 0 0 !i'J !i'J !i'J 0 !i'J 0 !i'J 0 0 ................ ............................ ..... . ~ ~ ~ STATISTICAL MEASURES •••••••••• THE MEAN (AVERAGE) SCORE IS 86.8419 •••••••••• THE MEDIAN (MIDDLE) SCORE IS 85.965 •• ~ ••••••• THE STANDARD DEVIATION IS 2.58237 •••••••••••••••• ~ • • eo • • • • • • • e· • • • • • • • • • • • • • • • • • ~ ••••. 9 DO YOU WISH TO SPECIFY GRADES (Y OR N)1Y A B C D FOR FOR FOR FOR GRADE THOSE SCORES EQUAL ~O OR GREATER THAN195 REMAINING SCORES EQUAL TO OR GREATER THAN?85 REMAINING SCORES EQUAL TO OR GREATER THAN?75 REMAINING SCORES EQUAL TO OR GREATER THAN?!i'l NUMBER· A 0 1 B 2 IXX C IX D ~ 1 F (Ij 1 D-21 •• DO YOU WISH TO RESPECIFY THE GRADES CY OR N)?Y A B C D FOR FOR FOR FOR THOSE SCORES EQUAL TO OR GREATER THAN?85.965 REMAIN ING SCORES EQUAL TO OR GREATER THAN·? 80 REMAINING SCORES EQUAL TO OR GREATER THAN?60 REMAINI-NG SCORES EQtJAL TO OR GREATER THAN?30 GRADE NUMBER A - IX IXX B 2 C 0 .I D 0 I F 0 I DO YOU WISH TO RESPECIFY THE GRADES (Y OR N)1N A GRADES ARE: STUDENT II II B GRADES ARE: STUDENT 10 STUDENT 12 * * C GRADES ARE: D GRADES ARE: F GRADES ARE: THIS IS THE END OF THE EDUTEST RUN. THANK YOU. D-22 EDTEST The key cards and the student answer cards are imbedded in EDTEST as a mass of data statements. EDTEST is just the barest of programs necessary to read and write this data onto the disk (DECtape) and CHAIN to the next program, EDTST2. This technique allows EDTST2 to have much more 'working' program and to pull in data as it is required. The 4K version of EduSystem-30 allows either 6,000 characters of program and no variables, 600 variables and no program, or some trade-off in between. This version of EduTest allows you approximately: 2~00 REM ~EnTEST" FlRST PROG~AM IN fOUTEST 2010 REM COP~RIGHT 1972 DIGITAL EQUIPMENT CORPOR~TION 2020 REM MAVNARO, MASSACHUSETTS 203~ REM EOUSVSTEMS 30 AND 40 2040 DIM N(S50) ~0~1 FOR 1-1 TO 5Se\REAO NCI'\IF N(1)-·2 THEN 2042\NEXT I 2~~2 FOR J.l TO I-1\WRITE N(J)\NEXT J 20~3 RESTORE\CHAIN "EOTST2" 20~5 DATA -1,-1,-1,-1,-1,-1,-2 204& END 25 questions x 50+ students 50 questions x 35 students 75 questions x less than 10 students. The quickest way to significantly expand these limits is to delete the Unequal Weighting Option of EDTST2 and all handling of V ( 1) thereafter. If done, 100/ Q is the value of each question. D-23 EDSTS2 100 ~EM "EDTST2" SECOND PROGRAM IN EOUTEST 110 REM COPYRIGHT 1972 D1GITAL EQUIPMENT CORPORATION 120 REM MAVNARD, MASSACHUSETTS 130 REM EOUSYSTEMS 30 AND·40 1~0 DIM K(50"NC36)i~(S),VC50) 15~ PRINT "HOW MANV QUESTIONS IN THE TEST", ~60 INPUT Q 170 C.INT(CQ-l)/2S1'1 180 FOR l a l 'TO C 190 READ N\IF,Na.9 THEN 200\PRINT "KEY CARD",I,"HAS ,BAD I.D."\STOP ~ 2~0 READ 81,82,a3,B4,BS\NEXT I\RESTORE N 2;0 FOR 1-1 TO C\READ N ~ 220 ~OR J-l TO 5\READ B\GOSU8 1000 230 FOR K.t TO 5\~((I-l)*25+CJ.l)*5+K)aR(K) 2~0 IF (I~1)*25+(J.l)~~+~aQ THEN 210 250 IF R(K)»>al TMEN 260\PRINT"ttAD MARKS ON I -1 THEN 380 3b0 PRINT "NOT ENOUG~ STUDENTS HERE • THERE 'ARE"lI-U"STUDENTS" 370 S-I-l\GO TO 600 , , Q= # students C=# cards/ student This set of code checks the key cards for hlanksand sets K (1) to the correct . key. s= # students Z=# marks counted, M=# missing marks end of file? 38~ 3q0 4f10 410 420 43~ 440 450 4&0 470 480 4q0 t;; I tv V'I 500 510 520 530 540 550 5&121 510 58121 59121 &0121 &10 &20 630 &40 &50 6&0 670 &80 J.l Read a 5 digit answer ,'OR K-t TO 5 READ 8 block. GOSUB 1000 NEXT "IF Z>.Q THE'" 560 GOSUB 9&0 This loop is entered FOR J-i, TO C only when each student READ Ni . h d IFNi aN (I) THEN 500 enteiS mor~ t an 1 car PRINT "*******.*.STUOENT NUH8ER",N(1)," HAS MISMATCHED 1=0 0 " , (>25 questIons). PRINT" ON CARO",J This set of code conFOR K_t TO 5 tinues to check for REAU ~\GOSUB 10~0 missing marks, and NEXT I( also matches the I.D. IF Z>.Q THEN 5b0 numbers of cards 2, 3, GOSU8 960 etc. against the stuNEXT J dent's first card. NEXT I READ N IF N•• l THEN 600 PRINT "TOO ~ANV CARDS FOR",S,"STUDENTS" PRINT "END OF CARD CHECK • SHALL ~E GO ON (Y OA N)1"r\INPUT SA\PAINT IF A.jV THEN bia'IF AC>,N THEN 600\STOP FOR I-t TO 65\PRINT ".",\NEXT I\PRINT PRINT PRINT PRINT\PRINT "ARE THE QUESTIONS EQUALLY WEIGHTED CY OR ~)1"' This is the code which INPUT SA\PRINT allows unequal weightIF Aa,V THEN 840\IF AC>.N THEN 650 ing and generates Vi' PRINT "ENTER THE WEIGHT FACTOR FOR EACH QUESTION." the decimal value of 690 fiCA 1-1 TO C' each question. 7021 7U'I 720 730 740 750 7~0 t:1 I tv 0\ 770 780 790 800 810 820 830 840 850 8621 870 880 8q21 9~11~ 910l 92~ 930 q40 950 9f,0 971i~ 9a0 990 PRINT PRI ~ T " PAR'T "fI ' FOR Ja1 TO 25 PRI~T "QUESTIUN ."1J, " O-eI-1l*25+J INPUT Yeo) TaT+V(O) IF O-Q THEN 8fcl0 NEXT J NEXT 1 FOR Ial TO Q V(I)aV(I)*100/T NEXT I GO TO 870 FOR 1-=1 TO Q V(I)a100/Q NEXT I PRINT PRINT AESTORE\FOA Ia~.C.(S+l)+~ TO 1 STEP -3\FOR J a l TO 1/3 READ 81,B2,B3\NEXT J\WRITE Bl,B2,83\RESTORE\NEXT I\WRITE C,Q,S FOR 1-1 TO 6*C.CS+l)+b\READ B\NEXT I\~OR 1.1 TO Q\WRITE K(I)\NEXT I FOR 1.1 TO Q\wRITE VCI)\NEXT I\FOR 1-1 TO S\W~ITE N(I'\NEXT I PRINT RESTOHE' CHAIN "EOTST3" IF Z+M.25*J THEN q90 PRINT "**********STUOENT NUMBER"IN(I)'" HAS INSUFFICIENT "' PRINT "MARKS ON CARD",J\MaM+25*J-Z RETURN Subroutine to match total marks against questions. 1P.100 R(0)a" 1010 FOR X-I TO 5 1020 B.B-R(X-l)*1~·(6-X) 1030 R(Xl-INT(B/1~·(5.X») 1~4e IF R(X)a0 T~EN 1010 10150 Z.Z.l 1060 NEXT X 1070 RETURN 108~ END This subroutine takes the 5 digit answer block and breaks it into five separate digits: Rio R 2 , R a, R", and R;;. It also checks for a zero digit (no mark) and increments Z for each good mark, tj I tv .......:J Lines 890 and 900 shift the entire data file up 3 spaces, and insert C, Q and S at the front. Lines 910 and 920 write the ·new data at the end of the data file. If Vi routines are deleted to gain space, each routine which reads the data file must be changed to reflect the absence in EduTest 2, 3, 4, and 5. EDTST3· Hl0 lHl 1?0 130 140 150 lbe 170 1813 O· I··, ~ 19V1 20~ 21 PI 22~ 23" 240 2'50 2~0 i70 28Q! 2q~ 300 310 3~0 REM "EOTST3" THIRD PHtiGRAM IN EOUlEST REM·COPYRIGHT 1972 OIGITAL EQuIPMENT CORPORATION REM MAYNARO, MASSACHUSETTS REM eOUSVSTEMS 30 AND 40 OIM C(35)r~(5~"R(5),T(35),V(50) FOR lal TO 65\PRINT ".",\NEXT t\PRINT REA[lC,Q,S FOR lal T06*C*(S+1)+b\READ 8\NEXT 1 FOR la1 TO Q\HEAO kC!)\NE~T !\FOR 1-1 TO Q\MEAb V(!)\NEXT I R£STORE\FOR I~t TO &-C+3\READ 8\NEXT I PRIN1\P.RtNT PRINT TA8(20);nSTUOENT RESPONSE MATRIX" PRINT PRINT " •••••••••• CORRECT RESPONSES, ARE INDICATED BY -" PRINT " •••••••••• INCORREC T RESPONSES ARE LISTED" pAINT ~ •••••••••• A NO-RESPONSE IS INDICATED BY *" FOR 1-1 TO C PRINT PRINT TA8(2b);"PAHT",I PRINT "STUOENT",TAB(25)'''QUESTION'',TA8C58),"NUMBER",TA8C66), P~tNT "CUM %"\PRINT "NUMBER"'T'BC2&)'~NUM8ER",TA8(58)'"RIGHT"' p~rNT TA8C&6)'"GRADE"\PRINT TAB(8), 'OR Jal TO 2S\PkINT CHRSCINTeJ/10)+48)'" ""NEXT J . 330 PRIN1\PRI~T TAB(8)' 34e, FOR TO 25\PRINT CHRSCJ-lNTCJ/10)*10+08)," "'\NEXT J J., 35'" PRINT 3M') PRINT 370 FOR Jiq TO S Dummy read to the teacher's key. Prints lf 000 2 1 2 3 ... ·5 38~ C(J):II~ READ N 4~~ PRINT NIT.R(7); 410 FOR 1<=1 TO 5 420 READ,B 430 GOSLJB 7q0 4"~ FOR L=1 TO 5 4S~ O-CI-l1*2S+(K-l)*5+L 3'H'l 4h0 IF R(L).~(O) fHEN 490 470 IF'Hella1 THEN 480\PHINT " "'C~RS(RCL)+b3)"GO TO 510 480 PRINT ~ *"'\GO TO 510 49et PRl-NT " 500 C(J)-CeJ)+1\T(J)_T(J)+V(D) 51~ IF OaW THEN 5J0 , 52~ NEXT l'~EXT K 530 FOR MaK+l TO ~\READ 8\NEXT M ~ 5a~ TSINT(T(J)w10+.S)/10 This set of code prints the student response matrix. _'I, 9 55~ N~INT(lOGCC(J)+.5)/LOG(10))+1\P.INT(LOG(T+,5)/LOG(10')+1 555 IF C(J)c>0 THEN Sb0\NaN+l\p.P+l Sb0 PRINT TAB(&1-~)'CCJ)'TAB(&8.P)'T 51V1 FOR Ma2 TO C 580 HEAD N,Bl,B2,~3,B4,85 5Q~ IF N<>-l THEN &10 &0~ IF laC THEN 7~0 &10 NEl(l H ,.?~ NEXT J &30 RESTORE\FOR .pat TO &*C+3\~EAD B\NEXT P ~40 FOR H=1 TO I &50 READ N,Bl,R2,b3,B4,B5 &&0 NEXT M &70 PRINT "KEY"JTAB(8)I &8~ FOR J=l TO 2S\L-CI-l)*2S+J\PRINT CMRS(K(L)+&3)I" ", How many digits? ' Dummy read to the next student's card. Rewind the data file and get ready for the next part. 6ge IF LC~ THEN 7~·~ NEXT 1 7~0\NEXT J\PRINT 7 1 ~., GOT 0 7 '" 0 7?~ 75~ 7,,~ 7~~ 7b~ PRINT "KEY"ITABCe)1 FOR J-CI-l'*2~+1 TO Q\PRINT CHRS(K(J'+63)," ",\NEXT J\PRINT PRINT\PRINT RESTO~E\FOH 1-1 TO 6*~*(S+1)+2*Q.S+9\REAO 8\NEXT I FOR I=1 TO S\WRITE TC!)\NEXT I 770 RESTOwe: 7Ae CHAIN "EOTST"'" 7Cjll- R(0)a0 8010 FOR X-I TO 5 R10 8.R~R(X·l)*10-(b·X) 8~0 R(X).INT(~/10-C~-X») U I !.;J o 830 NEXT X R"'~ RETURN A5e. END Note that line 500 calculates each student's score; If deleting. the Yi routines to gain room, replace the Yen) of line 500 with 100/Q. ~ Dummy read to end of file. Write new data. EDTST4 100 110 120 130 1~0 150 1~0 170 180 9 ~ . 190 200 210 220 230 240 250 2~0 270 280 290 300 310 320 330 3~0 350 360 370 REM "EOTST4" FOURTH PROGRAM IN EOUTEST REM COPYRIGHT 1972 DIGITAL EQUIPMENT CORPORATION REM MAYNARD, MASSACHUSETTS REM EOUSYSTEMS $0 AND 40 D(M K(S0),A(25,6) FOR 1-1 TO 65\PRINT ".",\NEXT I\PRINT\PRINT\PRINT READ C,Q,S FOR 1-1 TO ~*C*(S+1)+~\R!AD B\NEXT I FOR 1-1 TO Q\READ KCI)\NEXT I\RESTORE PRINT TA8(i0)1"lTEM ANALYSIS"\PRINT PRINT " ••••••• , •• NUMBERS SHOWN ARE TO THE NEAREST PERCENT" PRINT It • • • • • • • • • • CORRECT CHOICES ARE INDICATED BY *" FOR 1-1 TO C FOR J-1 TO 25 'ORK-1 TO ~\A(J,K'.0\NEXT ~ NEXT J PRINT\PRINT\PRINT T_8(26),npART"'I PRINT "QUE8TION", FOR J.l TO 5\PRINT TAB(J*7+S)'"ANSW~R"r\NEXT J PRINT TAB(49)1"NO" PRINT "NU~BER"JTA8(13)'"A(I)"'TAB(20)'"BCX)"'TABC27),MCCX)"' PRINT TAB(34)1"O(X)"JTA8(4t)'"£CI)",TA8(G6,,"RESPONSE" R~STO~E\READ C,Q,S"OR J-1 TO C\REAO N,Bi,Bi,B3,84,85\NEXT J FOR J.1 'TO I-l\READ N,Bl,B2,83,84,8S\NEXT J FOR J.l TO S\READ N FDA Ka1 TO 5 REAO B\GOSUB 640 FOR L-t TO S\X-L+S*CK-1) Zero the counters. This set of code counts the number of times each part of each question is chosen. 380 390 400 410 420 430 ,,,0 4~0 460 470 480 490 9 ~ FOR Ma1 TO 5 IF RCL)c~M+l THEN 400\A(X,M).A(X,M)+1\GO TO 410 NEXT M\A(X,&)aAeX,&)+l IF 25*CC-l)+X.Q THEN 450 NEXT L NEXT I( GO TO "h0 FOR L.K+l TO 5\READ B\NEXT L FOR La1 TO C-l\REAO N,81,B2,B3,B4,8S\NEXT L NEXT J FOR J~l TO 25 )(1I2\PRINT'J; FOR K.t TO &\Z.INTCA(J,~)/S*100+.5)\GOSUB 590 PRINT TA8((K+l)*1.D)'Z'~IF K.& TMEN Si0\GOSUB &20\NEXT K IF K(25*(I-l)+J)c2 THEN ~30\PRINT\GO TO 540 PRINT "*" IF 25*CI-1)+JIIQ THEN 580 500 510 520 5)'" 540 550 NEXT J 5b~ RESTORE\FOR J=l .TO &*C+3\REAO B\NEXT J 570 NEXT,I 580 PRINT\RESTORE\CHAIN "EOTST5 P 5913 .IF ZC~0 TMEN b00\O.1\GO TO 610 6~0 O.INT(LtiG(Z)/LOG(10»+1 610 RETURN &20 IF XC~K(25*(I-1)+J' THEN &30\PRINT "*"1 &30 X.X+1\RETURN &40 R(0).0 &50 FOR Vat TO 5 " Here these counts are converted to percentage points and printed. How many digits? Subroutine. Is this the correct answer? Subroutine. ~~0 8.B.R(V.l)*10-(~.Y) 610 RCV).!NT(B/10~(S.V)) fl80 NEXT Y 6q0 RETURN 7(11121 END t? ~ The A(25,6) dimensioned in line 140 is used to count the number of times each of the six possible marks (crossed out, A, B, C, D, E) is chosen for each of the twenty five questions in each part of the test. Line 500 is where the complete count is converted to a percentage point prior to printing. EDTST5 REM "EnTST~" FIFT~ PROGRAM IN EOUTEST REM COPV~IG~T 1972 DIGITAL EQUIPMENT CORPORATION 1?0 REM MAYNARD, MASSACIoIUSETTS 13FREM EOUSYSTEMS J0 AND 40 1~r, DIM E(50),F(~~),K(~0),T(35"V(50) 15~ FOR 1-1 to 65\PWINT ".",\NEXT l\PRINT 1 Hl' REA DC, fJ , S 170 FOR 1-1 TO 6*L.(S.1).~\REAO 8\NEXT I 180 FOR 1-1 TO Q\REAO K(I)\NEXT I 190 FOR !-1 TO Q\~EAD VCI)\NEXT I 2~0 FOR 1-1 TO S\k£AO B\NEXT I 21~ FOR 1-1 TO S\~EAD T(I)\NEXT I\RESTORE 2?~ PkINT TAB(23),"QUESTION ANALYSIS"\PRINT 230 PRINT "QUESTIUN"'TAB(13),UVALUEP'TAH(i0,,"PERCENT", 240 PRINT TA8(30);"T I M E S MIS S E 0" 250 FOR 1-1 TO b*C+J\REAn B\NEXT I 2~0 FOR Ial TO S\~OR J-l TO C\REAO N 270 FOR ~.1 TO 5\kEAO 8\GOSUB 700 ?be FOR La1 TO 5\U.(J-l)*25+(K-l)*5+L 2q0 IF R(L).K(D) THEN 31~\E(O).E(O)+1 3~e IF O.Q T~EN 3c0 310 .NEXT L\NExT K 32~ FOR M.K+l TQ5\READ 8\NEXT M 33e NEXT J\NEXT 1 3t.1Vi FOR r-l TO C 350 PRINT PPART"'I~TAB(20)'"CORRECT" lP~ 11~ 9 ~ ~ Count the number of times each question was missed. E i·=# misses on Ith question. 3~e FOR J~l TO 25 371i'1 O-CI-l)*2S+J 360 PRINT J'TA8(lj)'INT((V(O)+.0~5)~1~0)/100'TAB(20)' 390 PRI~T I~T«((S-E(O»/S+.0005)*1000)/10'TA6(30),E(O)' 401i'1 PRI~T 1A8(35)I"I"I 410 IF E(O)a0 THE~ ~50 420 FOR Kat 430 PRINT "40 NEX'T Print question number, value, percent correct, times missed, and bar chart of times missed. TO EtO) 11)(11, ~ 45121 PRINT 4&0 IF u-~ THEN 47~ NEXT J U I V-) VI 49~ '-I 8 V'! NEXT 1 490 PRINT\PIHNT 5~~ FOR 1-1 TO b5\PWINT ".",\NEXT I\PRINT\PRINT 51~ PRINT TAB(21)i"UISTRIHUTION OF SCORES" 52~ FOR Isl TG S 530 J.INT(T(I)+.~05)/5) '54~ F(J)-F(J)+l 5~0 TaT+T(I) St-0 NElt'T I 570 PRINT 580 PRINT "HANGE","NUMBER" 5q~ PRINT 1~0,FC2C',"I"' bli'lli'l FOR 1-1 TO F(20)\PRINT "X"'\N~XT I\PRINT bl~ FOR 1-95 TO 0 STEP -5 b20 PHINT 1'"TO"ll+LI.9Q,F(I/5),"I"I b]e FORJ-' TO FCl/5)\PRIhT "X"'\NEXT J\PRINT\NEXT 1 b41i'1 RESTORE\WRITE S,T\FOR t-l TO S\~RITE l(I)\NEXT I - ... b~0 FOR 1-1 TO b*C*(S+1)+2*Q+7-S\R~KU e\NtXf 1 b~1i'I FOR 1-1 TO S\~EAO T(I)\NEXT I\RESTORE b7~ FOR 1=1 TO S+2\REAO 8\NEXT 1 . Set F(O)=# scores between 0 and 4.99 F(1) =# scores between 5 and 9.99, etc. T=total of all scores Print the bar chart for the distribution of scores. 680 FOR 1-1 TO S\wRITE TCI)\NEXT I\RESTORE hQ0 CH.1N 7re R(0)a0 71~ FOR "~DTST6" Y~l TO 5 720 S-B-R(Y-ll*10-Cb-Y) 73~ 7al2l RCy)apJl(B/10-(S"Yl) NEXl Y 750 RETURN END 7H'I tj I W 0\ EDTST6 / ~EDTST6" $IXTH PROGRAM IN fDUTEST REM COPYRIGHT 197i DIGITAL EQUIPMENT CORPORATION REM· MAYNARD, MASSACHUSETTS REM EDUSYSTEMS J0 AND 40 DIM NC&0),TC&0),Z(&0) FOR 1-1 TO &5\PRINT "."I\NEXT I\PRINT\PRINT READ S\READ 1. FOR 1-1 TO S\kfAD TCI)\NfXT I FOR Iel TO S\RfAD NCI)\NEXT I 100 REM 110 120 130 140 150 1&0 170 180 190 PRINT 200 PRI~T 2~0 FOR 1-1 TO S\leX)aTCI)\NEXT I TAB(24),"STATISTICAL MEASURES- 21121 PRINT 2221 MaTIS 230 PRINT " •••••••••• THE MEAN (AVERAGE) SCORE IS",M This set of code sets the dummy Zi=Ti . Sorts the Z! into as_ cending order and renumbers the sub, script i accordingly. 250 FOR Ial TO S\FOR JaI TO S 2b~' IF Z(l)c.ZCJ) THEN 28121 270 O-ZeI)\ZeI)aZlJ)\ZCJ)aO it80 tJ I ~ NEXTJ\NEXT·I 290 IF INTCS/2).S/2 THEN 310 - - - - - - - - - - - - - - - - - , 300 M2aZ((S-1)/2+1)\GO TO 32121 310 M2·(Z(S/l)+Z(S/i.1»/2 '------ The median score is 32121 ~2aINTe(M2+.0005)*1000)/1000 then the middle Score 330 PRINT " •••••••••• THE MEDIAN C~IDOLE) SCORE IS",M2 340 FOR t-l TO S----------------------------------------------, 35121 VaV+CM-TCI"'"'i:! NEX" I 370 VaV/S 3b0 38121 39121 400 410 42121 43121 u40 450 4&121 w.,~ 48121 49121 51210 P~INT " •••• , •••• ,THE STANDARD DEVIATION IS",SQR(V) PRINT\PRINT '.OR 1-1 TO &5 PRINT "."' NEXT I PRINT\PAINT\PRINT PAINT "00 YOU WISH TO SPECIFY GRADES CV OR N)?"; IN"UT SA\PAINT IF ' •• V TH!N 4~0\IF Ac~'N TMEN 44121 F~INT\FRINt "THIS IS THE END D~THE fOUTEST RUN.~ PRINT "THANK YOU."\STOP PRINT\PRINT I'A FOR THOSE SCORES EQUAL TO OR GREATER THAN"' INPUT G(1)\FO~ Gla2 TO 4 if S is odd, or half, way.between the two . mnermost scores If S is even. .. V =variance, i.e. u:!=~ (u-x):l x~ S Begin letter grading 510 PRINT CMRSCG1+6~),n FOR PEMAINING SCOPES EQUAL TO OR GREATER TMAN"' 520 INPUT G(Gl)\NEXT Gl\LET G(5)-0 530 PRINT\PRINT\FOR 1.1 TO S\FCI).0\NEXT I Sets F( J ) =# A grades 5"0 FOR 1-1 TO S F(2) =# B grades 550 FOR (;181 TO 5 5&0 IF T(I)cG(Gl) TMEN 580 etC. 570 F(G1).F(G1)+1\GO TO 590 58~ NEXT Gl 59121 NExT r M~0 PRINT\PRINT "~RADE",nNUMRE~"\PRINT Prints bar chart for 6UJ FOR l-l TO 5 ,c ~20 Gl-64+1\IF lc~ TMEN 630\G1-70 distribution. of letter . &30 PRINT" "'CH~S(Gl)," ",f(I),"I"' grades. f,~~ FOR J-t TO F(l)\PRINT "X"I\NEXT J &50 PRINT\PRINT\NEXT I o &60 PRINT\PRINT W ~&7e' PRINT "DO VOU WISH TO RESPECIFY TME GRAOES (Y OR N)?"I oc .&8121. INPUT 'A\PRINT &40 IF A•• ' THEN 49121\IF Ac~.N THEN 67121 7~~ PRINT\P~INT 710 FOR Gi:r1 TO '5 72~ 73~ 7,,0 75C 7&0 770 IF G1<5 THE~ 130\PRINT "F",\GO TO PRINT CHRSCG1+b~)' PRINT" GRADES AR~:" FOR 1:11 TO 5 IF T(I)
Source Exif Data:File Type : PDF File Type Extension : pdf MIME Type : application/pdf PDF Version : 1.3 Linearized : No XMP Toolkit : Adobe XMP Core 4.2.1-c041 52.342996, 2008/05/07-21:37:19 Create Date : 2002:04:01 18:44:14Z Creator Tool : g4pdf Modify Date : 2016:11:05 09:13:21-07:00 Metadata Date : 2016:11:05 09:13:21-07:00 Producer : Adobe Acrobat 9.0 Paper Capture Plug-in Format : application/pdf Document ID : uuid:ce5c3c14-fae3-8241-8516-2d9c42359d6d Instance ID : uuid:47e2bddc-a77d-1441-b052-c14dc26602be Page Mode : UseOutlines Page Count : 638 Creator : g4pdfEXIF Metadata provided by EXIF.tools