Digital PDFs
Documents
Guest
Register
Log In
DEC-S8-OSIBA-A-D
December 2000
172 pages
Original
6.2MB
view
download
Document:
dec-s8-osiba-a-d
Order Number:
DEC-S8-OSIBA-A-D
Revision:
Pages:
172
Original Filename:
https://svn.so-much-stuff.com/svn/trunk/pdp8/src/dec/dec-s8-osiba/dec-s8-osiba-a-d.pdf
OCR Text
0 industrial n 0 3 3 3 3 3 3 3 3 3 3 3 # 3 B digital equipment corporation # OS/8 Industrial BASIC F o r additional c o p i e s , order N o . DEC- S8-OSIBA-A-D from Software D i s t r i b u t i o n Center, D i g i t a l Equipment Corporation, Maynard, Mass. digital equipment corporation maynard. massachusetts Printed October, 1973 Reprinted July, 1974 The information in this document is subject to change without notice and should not be construed as a commitment by Digital Equipment Corporation. Digital Equipment Corporation assumes no responsibility for any errors that may appear in this manual. The software described in this document is furnished to the purchaser under a license for use on a single computer system and can be copied (with inclusion of DIGITAL'S copyright notice) only for use in such system, except as may otherwise be provided in writing by DIGITAL. Digital Equipment Corporation assumes no responsibility for the use or reliability of its software on equipment that is not supplied by DIGITAL. Copyright 0 1973, 1974 by Digital Equipment Corporation The HOW TO OBTAIN SOFTWARE INFORMATION page, located at the back of this document, explains the various services available to DIGITAL software users. The postage prepaid READER'S COMMENTS form on the last page of this document requests the user's critical evaluation to assist us in preparing future documentation. The following are trademarks of Digital Equipment Corporation: CDP DIGITAL COMPUTER LAB COMSYST COMTEX DDT DEC DECCOMM DECTAPE DIBOL DNC EDGRIN EDUSYSTEM FLIP CHIP FOCAL GLC-8 IDAC IDACS INDAC KA10 PS/8 LAB-8 LAB-8/e LAB-K OMNIBUS OS/8 PDP PHA RAD-8 RSTS RSX RTM RT-11 SABR TYPESET 8 UNIBUS QU ICKPOINT CONTENTS Page CHAPTER 1 INTRODUCTION TO O S / 8 INDUSTRIAL B A S I C 1-1 1.1 1.2 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 HARDWARE REQUIREMENT 1-1 1-2 1-2 1-2 1-2 1-2 1-2 1.3 LOADING AND RUNNING OS/8 INDUSTRIAL BAS I C G a i n i n g A c c e s s t o BASIC E n t e r i n g t h e New Program E x e c u t i n g the P r o g r a m C o r r e c t i n g t h e Program I n t e r r u p t i n g E x e c u t i n g of t h e Program Leaving t h e C o m p u t e r E x a m p l e of O S / 8 I n d u s t r i a l B A S I C R u n 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.4 1.4.1 1.4.2 CHAPTER 2 2.1 2.2 2.3 2.3.1 2.3.2 2.3.3 2.3.4 CHAPTER 3 3.1 3.2 3.3 3.3.1 3.3.2 3.4 3.5 3.5.1 3.5.2 DOCUMENTATION CONVENTIONS Underlining Carriage Return B l a n k Spaces C o n t r o l and S h i f t C h a r a c t e r s Terminals O S / 8 INDUSTRIAL B A S I C OVERVIEW G e n e r a l System D e s c r i p t i o n O S / 8 I n d u s t r i a l B A S I C Statements and Commands 1-2 1-3 1-3 1-4 1-4 1- 4 1-5 1-5 1-6 1-6 1-6 O S / 8 INDUSTRIAL B A S I C ARITHMETIC 2-1 NUMBERS 2-1 2- 2 2-2 2-3 2-3 2- 4 2-5 VARIABLES ARITHMETIC OPERATIONS P r i o r i t y of A r i t h m e t i c O p e r a t i o n s Parentheses Relational Operators R u l e s for E x p o n e n t i a t i o n OS/8 INDUSTRIAL B A S I C STATEMENTS STATEMENT NUMBERS REMARK -- THE COMMENTING STATEMENT STATEMENTS FOR TERMINATING A PROGRAM END STOP LET -- THE ASSIGNMENT STATEMENT INPUT/OUTPUT STATEMENTS AND FUNCTIONS T h e INPUT S t a t e m e n t T h e PRINT S t a t e m e n t iii 3-1 3-2 3-3 3- 4 3-4 3-4 3-4 3-5 3- 5 3-6 Page 3.5.2.1 3.5.2.2 3.5.2.3 3.5.2.4 3.5.3 3.5.4 3.6 3.7 3.8 3.8.1 3.8.2 CHAPTER 4 General Format Control C h a r a c t e r s P r i n t i n g Numbers PRINT Used w i t h INPUT The T A B ( X ) Function The PNT(X) Function THE READ AND DATA STATEMENTS RESTORE CONTROL STATEMENTS 3-6 3-7 3-8 3-9 3-10 3-10 3-11 3-12 3-13 3-13 3-14 GOT0 IF-THEN and IF-GOT0 LOOPS 4-1 4.1 FOR AND NEXT STATEMENTS 4-1 4.2 NESTING LOOPS 4-2 LISTS AND TABLES 5-1 SUBSCRIPTED VARIABLES THE D I M STATEMENT 5-1 5-2 OS/8 INDUSTRIAL BASIC FUNCTIONS AND S UBROUT INES G- 1 CHAPTER 5 5.1 5.2 CHAPTER 6 6.1 6.2 6.2.1 6.2.1.1 6.2.2 6.2.3 6.2.4 6.2.5 6.3 6.3.1 6.3.2 6.3.3 6.3.4 6.3.5 6.4 6.4.1 604.2 6.5 GENERAL INFORMATION ON OS/8 INDUSTRIAL BAS I C FUNCTIONS ARITHMETIC FUNCTIONS The Random Number Function FWD(X) The RANDOMIZE Statement The S i g n Function SGN(X) INT(X) The I n t e g e r Function The Absolute Value Function ABS(X) The Square Root Function SQR(X) TRANSCENDENTAL FUNCTIONS The S i n e Function SIN(X) The Cosine Function COS(X) ATN(X) The A r c t a n Function The Exponential Function EXP(X) The N a t u r a l Logarithm Function LOG(X) USER DEFINED FUNCTIONS The FNA(X) Function and the__DEFStatement The UDEF Function C a l l and t h e USE Statement -- -- -- -- -- ---- -- -- THE PEBUGGING FUNCTION iv -- TRC(X) -- 6-1 6-2 6-2 6-4 6-4 6-5 6-5 6-6 6-6 6-6 6-6 6-7 6-7 6-7 6-8 6-8 6-8 6-9 Page 6.6 6.6.1 6.6.2 CHAPTER 7 7.1 7.1.1 7.1.2 7.1.3 7.1.4 7.1.5 7.2 7.2.1 7.2.2 7.2.3 7.2.4 7.2.5 7.2.6 CHAPTER 8 8.1 8.2 8.2.1 8.2.2 8.2.3 8.2.4 8.3 8.3.1 8.3.2 8.3.3 8.3.4 8.3.5 8.3.6 8.3.7 8.3.8 8.4 8.4.1 8.4.2 8.4.3 8.5 8.6 CHAPTER 9 9.1 9.1.1 9.1.2 SUBROUT INES GOSUB and RETURN Nesting Subroutines 6-11 6-11 6-12 ALPHANUMERIC INFORMATION (STRINGS) 7-1 STRING CONVENTIONS Constants and Variables Dimensioning Strings Inputing String Data Strings in LET and IF-THEN Statements String Concatenation STRING HANDLING FUNCTIONS The LEN Function The ASC and CHR$ Functions The VAL and STR$ Functions The POS Function The SEG$ Function The DAT$ Function 7-1 7-1 7-1 7-2 7-3 7-4 7-4 7-4 7-5 7-6 7-6 7-7 7-7 REAL TIME OPERATIONS 8-1 GENERAL DESCRIPTION REAL TIME BASIC STATEMENTS TIMER COUNTER CONTACT DISMISS EXTENDED FUNCTIONS FOR INPUT OR OUTPUT The Clock Function CLK(X) Analog Input Function ANI (C,G) Analog Output Function AN0 (C,V) Read Digital Input RDI (P,N) Send Digital Output SDO (P,N,V) Read Digital Output RDO (P,N) Counter Input CN1 (P) Counter Output CNO (P,V) UPIR IDENTIFICATION FUNCTIONS Line LNE (x) State STA(X) Count CNT(X) EXAMPLE CONTROL PROGRAM POWER FAIL RESTART 8-1 8-1 8-1 8-2 8-3 8-3 8-3 8-4 8-5 8-5 8-5 8-5 8-6 8-6 8-6 8-6 8-6 8-7 8-7 8-7 8-8 EDITING AND CONTROL COMMANDS 9-1 CORRECTING PROGRAMS 9-1 -- ---- ------- -- ---- -- Erasing Characters and Lines The RESEQ Program V 9-1 9-2 Page 9.2 THE L I S T AND LISTNH COMMANDS 9-5 9.3 THE SCRATCH COMMAND 9-5 9.4 THE NEW COMMAND 9-6 9.5 THE OLD COMMAND 9-6 9.6 THE NAME COMMAND 9-7 9.7 THE SAVE COMMAND 9-7 9.8 THE RUN AND RUNNH COMMANDS 9-8 9.9 THE BYE COMMAND 9-8 FILES, 10-1 CHAPTER 10 10.1 10.1.1 10.1.2 1 0 .1.2.1 1 0 -1.2.2 10.1.2.3 10.1.2.4 F I L E STATEMENTS AND CHAINING GENERAL INFORMATION ON OS/8 BASIC F I L E S R e s i d e n t Devices F i l e Descriptions Fixed L e n g t h F i l e s V a r i a b l e L e n g t h Files INDUSTRIAL 10-1 10-1 10-1 Numeric F i l e s 10-1 10-1 10-2 ASCII F i l e s 10-2 10.2 10.2.1 10.2.2 10.2.3 10.2.4 10.2.5 10.2.6 F I L E STATEMENTS T h e F I L E # Statement T h e PRINT# S t a t e m e n t T h e INPUT# S t a t e m e n t T h e RESTORE# S t a t e m e n t T h e CLOSE# Statement T h e I F END# S t a t e m e n t 10-2 10-2 10-3 10-4 10-5 10-5 10-6 10.3 THE CHAIN STATEMENT 10-6 CREATING ASSEMBLY LANGUAGE FUNCTIONS 11-1 11.1 INTRODUCTION 11-1 11.2 THE OS/8 INDUSTRIAL BASIC SYSTEM 11-1 11.3 11.3.1 11.3.2 11.3.3 THE OS/8 INDUSTRIAL BASIC RUNTIME SYSTEM INBRTS C o r e L a y o u t INBRTS O v e r l a y s INBRTS S y m b o l T a b l e s 11-2 11-2 11-3 11-4 11.4 11.4.1 11.4.2 11.4.3 11.4.4 DATA FORMATS Variables 11-4 11-4 11-5 11-6 11-7 11.5 11.5.1 11.5.2 11.5.3 11.5.4 INBRTS SYMBOL TABLE STRUCTURE T h e Scalar T a b l e T h e A r r a y Symbol T a b l e The String Symbol T a b l e The String A r r a y T a b l e CHAPTER 11 Strings Incore DATA L i s t The String Accumulator vi 11-7 11-7 11-7 11-8 11-9 11.6 11.6.1 11.6.2 11.6.3 FLOATING-POINT PACKAGE F l o a t i n g - p o i n t Accumulator F l o a t i n g - p o i n t Routines Floating-point Operations INBRTS SUBROUTINES S u b r o u t i n e ARGPRE S u b r o u t i n e XPUTCH S u b r o u t i n e PSWAP S u b r o u t i n e UNSFIX S u b r o u t i n e STFIND S u b r o u t i n e BSW S u b r o u t i n e MPY S u b r o u t i n e DLFCZAD S u b r o u t i n e ABSVAL PASSING ARGUMENTS TO THE USER FUNCTION I n t e r f a c i n g FIELD 1 Code w i t h FIELD fl Subroutines Using t h e USE S t a t e m e n t INBRTS I / O Terminal I / O INBRTS F i l e Formats INBRTS B u f f e r Space INBRTS Device Driver Space The INBRTS I / O Table INTERFACING THE ASSEMBLY LANGUAGE TO INBRTS GENERAL CONSIDERATIONS AND HINTS Routines Unusable by Assembly Language Functions Using OS/8 Page fl usage ASSEMBLY LANGUAGE FUNCTION EXAMPLE L I N K I N G I N T O THE INTERRUPT SKIP CHAIN 11-25 11-27 11-27 11-27 11-29 OS/8 BASIC STATEMENT, COMMAND, AND FUNCTION SUMMARY A- 1 APPENDIX B COMPILE-TIME DIAGNOSTICS B-1 APPENDIX C RUNTIME DIAGNOSTICS c-1 APPENDIX D ASCII CONVERSION TABLE D- 1 APPENDIX E OS/8 INDUSTRIAL BASIC SYSTEM BUILD INSTRUCTIONS E-1 APPENDIX F INDUSTRIAL BASIC SYSTEM GENERATION F- 1 APPENDIX G OPTIMIZING SYSTEM PERFORMANCE G- 1 APPENDIX H SYMBOL TABLE H- 1 11.7 11.7.1 11.7.2 11.7.3 11.7.4 11.7.5 11.7.6 11.7.7 11.7.8 11.7.9 11.8 11.8.1 11.8.2 11.9 11.9.1 11.9.2 11.9.3 11.9.4 11.9.5 11.10 11.11 11.11.1 11.11.2 11.11.3 11.12 11.13 APPENDIX A v ii 11-10 11-10 11-11 11-14 11-14 11-14 11-15 11-15 11-16 11-16 11-17 11-17 11-17 11-18 11-18 11-19 11-20 11-21 11-21 11-21 11-22 11-22 11-22 11-23 11-25 CHAPTER 1 INTRODUCTION TO OS/8 INDUSTRIAL BASIC NOTE BASIC I S A REGISTERED TRADEMARK OF THE TRUSTEES OF DARTMOUTH COLLEGE. BASIC i s an i n t e r a c t i v e programming language f o r a v a r i e t y o f It i s used i n s c i e n t i f i c and b u s i n e s s environments t o applications. s o l v e both simple and complex mathematical problems w i t h a minimum of programming e f f o r t . I t is used by e d u c a t o r s and s t u d e n t s as a problem-solving t o o l and as an a i d t o l e a r n i n g through programmed i n s t r u c t i o n and simulation. I n many r e s p e c t s t h e BASIC language i s similar t o o t h e r programming languages (such as FOCAL and FORTRAN), b u t BASIC i s aimed a t f a c i l i t a t i n g communication between t h e u s e r and t h e computer. The BASIC u s e r t y p e s i n t h e computational procedure as a series of numbered s t a t e m e n t s , making use of common English words and f a m i l i a r mathematical n o t a t i o n s . Because of t h e small number of commands n e c e s s a r y and i t s e a s y a p p l i c a t i o n i n s o l v i n g problems, BASIC i s one of t h e s i m p l e s t computer languages t o l e a r n . W i t h e x p e r i e n c e , t h e u s e r can add t h e advanced techniques a v a i l a b l e i n t h e language t o perform more i n t r i c a t e manipulations or e x p r e s s a problem more e f f i c i e n t l y and c o n c i s e l y . OS/8 I n d u s t r i a l BASIC has such f e a t u r e s as chaining, string manipulation, and f i l e - o r i e n t e d input/output. OS/8 I n d u s t r i a l BASIC h a s added f e a t u r e s for s u p p o r t of t i m e based, and e x t e r n a l e v e n t d r i v e n segments, coded i n BASIC, t o s e r v i c e t h e u s e r ' s real t i m e data c o l l e c t i o n and response v i a DEC's UNIVERSAL DIGITAL CONTROLLER (UDC). 1.1 HARDWARE REQUIREMENT The s t a n d a r d requirements f o r an OS/8 system must b e m e t . t h e only d e v i c e s supported w i l l be: 1. TD8-E w i t h e i t h e r ROM o r 1 2 K UDC w i t h n o t more than 16 words I / O DK8-EC c r y s t a l clock jumpered f o r 50 hz 2. RK8-E and DECtape UDC w i t h n o t more t h a n 16 words I / O DK8-EC c r y s t a l clock jumpered for 50 hz 1-1 In addition 1.2 DOCUMENTATION CONVENTIONS . 1.2 1 Underlining Where c l a r i f i c a t i o n i s r e q u i r e d i n t h e programming examples used i n t h i s manual, u n d e r l i n e d copy denotes u s e r i n p u t . Copy n o t u n d e r l i n e d i n d i c a t e s e n t r i e s typed by O S / 8 I n d u s t r i a l BASIC. . 1.2 2 Carriage return r e t u r n is always typeL a t t h e end o f a l i n e t o i n d i c a t e t h e l i n e i s complete. The c a r r i a g e r e t u r n n o t a t i o n used i n t h i s manual is t h e symbol J A carriage . that 1.2.3 Blank s p a c e s Blank s p a c e s are denoted by required. 1.2.4 the symbol u where clarification is C o n t r o l and s h i f t c h a r a c t e r s C o n t r o l c h a r a c t e r s such as CTRL/O are typed by h o l d i n g down t h e CTRL key and p r e s s i n g t h e letter 0. S h i f t c h a r a c t e r s such as SHIFT/L are typed by h o l d i n g down t h e SHIFT key and p r e s s i n g t h e l e t t e r L. . 1.2 5 Terminals The use of t h e DECwriter, 1.3 word "terminal" throughout this manual implies a an ASR-33 T e l e t y p e , or an e q u i v a l e n t i n t e r a c t i v e device. LOADING AND RUNNING O S / 8 INDUSTRIAL BASIC The f o l l o w i n g d i s c u s s i o n assumes t h a t t h e O S / 8 o p e r a t i n g system f o r t h e u s e r ' s hardware c o n f i g u r a t i o n i s on l i n e . The O S / 8 o p e r a t i n g The system is d e s c r i b e d i n t h e O S / 8 SYSTEM REFERENCE MANUAL. f o l l o w i n g paragraphs are a condensation of t h e e d i t i n g and c o n t r o l commands d e s c r i b e d i n Chapter 9 o f t h i s manual. 1-2 1.3.1 Gaining Access t o BASIC Once t h e Keyboard Monitor has responded w i t h a p e r i o d t o i n d i c a t e t h a t it i s ready t o r e c e i v e a monitor command, t h e user types t h e f o l l o w i n g command : ~. .R INBSIC BASIC responds w i t h t h e following: NEW OR OLD -- The u s e r t y p e s i n : NEW FILE.EX i f t h e user is going t o create a new program, where FILE.EX is t h e I f t h e u s e r w a n t s t o work w i t h name and e x t e n s i o n of t h e new program. a p r e v i o u s l y c r e a t e d program t h a t he saved on a s t o r a g e d e v i c e , he t y p e s i n t h e following: OLD DEV:FILE.EX where DEV: is t h e name o f t h e OS/8 d e v i c e h i s o l d f i l e i s s t o r e d on. For example: . OLD DTA6 :SAMPLE BA -- This response t o NEW OR OLD retrieves t h e f i l e named SAMPLE from DECtape and r e p l a c e s t h e c u r r e n t c o n t e n t s of u s e r core w i t h t h e f i l e SAMPLE. I f you s p e c i f y a d e v i c e t h a t does n o t e x i s t o r t h a t is n o t a v a i l a b l e f o r your use, INDUSTRIAL BASIC r e t u r n s an error message. For f u r t h e r information regarding OS/8 f i l e s and d e v i c e s , r e f e r Chapter 9 o f t h i s manual and t o t h e OS/8 SYSTEM REFERENCE MANUAL. 1.3.2 to E n t e r i n g t h e New Program A f t e r t h e u s e r t y p e s i n h i s filename, OS/8 w i t h t h e followingr Industrial BASIC responds READY The user can begin t o t y p e i n h i s new program or make changes t o h i s o l d program. When t h e new program i s b e i n g typed, t h e u s e r must make s u r e t h a t each l i n e b e g i n s w i t h a l i n e number c o n t a i n i n g no more t h a n f i v e d i g i t s and c o n t a i n i n g no spaces o r n o n d i g i t c h a r a c t e r s . The RETURN key must be p r e s s e d a t t h e completion of each l i n e . I f , i n the p r o c e s s o f t y p i n g a s t a t e m e n t , t h e u s e r makes a t y p i n g error and n o t i c e s it b e f o r e h e terminates t h e l i n e , he can correct it by p r e s s i n g t h e RUBOUT key or SHIFT/O keys once f o r each c h a r a c t e r t o b e e r a s e d , going backward u n t i l the c h a r a c t e r i n error i s reached. Then he may c o n t i n u e t y p i n g , beginning w i t h t h e c h a r a c t e r i n error. Using t h e RUBOUT key o r SHIFT/O keys echoes a backarrow (4) f o r each character deleted. The f o l l o w i n g i s an example of t h i s c o r r e c t i n g p r o c e s s ( n o t e t h a t a c i s typed f o r s p a c e s as w e l l as c h a r a c t e r s ) : 2@ L)EN F b - e F FNA(XaY)=Xt2+3*Y 1-3 corrected v e r s i o n of t h e above subsequent l i s t i n g of t h e program as: The 2M example would appear on a DEF FNA(XaY)=Xt2+3*Y Program l i s t i n g s can be g e n e r a t e d u s i n g t h e LIST or LISTNH commands. 1.3.3 Executing t h e Program A f t e r t y p i n g the complete program (do n o t forget t o end w i t h an END s t a t e m e n t ) , t h e u s e r t y p e s RUN or RUNNH, followed by t h e RETURN key. OS/8 I n d u s t r i a l BASIC t y p e s t h e name of t h e program, t h e v e r s i o n of OS/8 I n d u s t r i a l BASIC, t h e c u r r e n t date ( u n l e s s RU"H i s s p e c i f i e d ) , and then it a n a l y z e s t h e program, I f t h e program can b e run, OS/8 I n d u s t r i a l BASIC e x e c u t e s it and, v i a PRINT s t a t e m e n t s , t y p e s o u t any r e s u l t s t h a t were requested. The t y p e o u t of r e s u l t s does n o t g u a r a n t e e t h a t t h e program is correct ( t h e r e s u l t s could be wrong), b u t i t does i n d i c a t e t h a t no s y n t a c t i c a l errors e x i s t (e.g., missing l i n e numbers, misspelled words, or i l l e g a l s y n t a x ) . I f errors of t h i s t y p e do e x i s t , OS/8 I n d u s t r i a l BASIC t y p e s a message (or s e v e r a l messages) to t h e u s e r . A l i s t of these d i a g n o s t i c messages, w i t h their meanings, i s given i n Appendices B and C. NOTE RUN and RUNNH are c o n t r o l commands, and l i k e a l l other OS/8 I n d u s t r i a l BASIC e d i t and c o n t r o l commands, t h e y do n o t r e q u i r e a l i n e number preceding t h e command. 1.3.4 C o r r e c t i n g t h e Program I f the u s e r r e c e i v e s an error message t y p e o u t informing h i m , for example, t h a t l i n e 6 0 is i n error, t h e l i n e can be corrected by t y p i n g I f t h e s t a t e m e n t on i n a new l i n e 60 t o r e p l a c e t h e e r r o n e o u s one. l i n e 1 1 0 i s t o be deleted from your program, it i s accomplished by t y p i n g t h e following: 1103 I f he wishes t o i n s e r t a s t a t e m e n t between l i n e s 60 and 70, t h e u s e r t y p e s a l i n e number between 60 and 70 (e.g., 6 5 1 , followed by t h e statement. 1.3.5 I n t e r r u p t i n g Execution of t h e Program If the r e s u l t s b e i n g typed o u t seem t o be i n c o r r e c t and he wants t o of h i s program, t h e u s e r t y p e s CTRL/C which i s echoed by + e . The OS/8 I n d u s t r i a l BASIC e d i t o r responds w i t h t h e READY stop execution 1-4 message whereupon t h e u s e r can modify or add s t a t e m e n t s and r e r u n h i s program. 1.3.6 Leaving the Computer When t h e u s e r ' s program i s f i n i s h e d and he no l o n g e r r e q u i r e s t h e u s e Of OS/8 I n d u s t r i a l BASIC, he t y p e s t h e BYE command (or CTRL/C t o r e t u r n c o n t r o l t o t h e Keyboard Monitor. 1.3.7 Example of OS/8 I n d u s t r i a l BASIC Run The f o l l o w i n g i s a simple example of t h e u s e of OS/8 I n d u s t r i a l BASIC. I n s t r u c t monitor to bring i n t o core and s t a r t i t s execution .R ILJBSIC BASIC NEW OR OLD--NEW SAMPLE-BA BASIC a s k s whether new or program i s t o b e run READY BASIC is now ready t o old receive statements 10 FOR N = l TO 7 28 PRINT N s S Q R < N ) 30 NEXT N Type i n s t a t e m e n t s 44 PRINT "DONE" 56 END RUN SAMPLE Run program BA 1 .o 22-SEP-73 1 1 2 1e41421 3 1073205 2 2.23687 2.44949 2.64575 4 5 6 7 DONE READY 1-5 Program heading and r e s u l t s of program are p r i n t e d . 1.4 OS/8 I N D U S T R I A L BASIC OVERVIEW The e x p e r i e n c e d BASIC p r o g r a m e r may elect t o s k i p Chapters 2 and 4 through 6 of t h i s manual s i n c e t h e y are r a t h e r fundamental. However, he should f a m i l i a r i z e himself w i t h t h e remaining c h a p t e r s and appendices as they provide i n f o r m a t i o n s p e c i f i c a l l y related t o OS/8 I n d u s t r i a l BASIC. General System D e s c r i p t i o n 1.4.1 The OS/8 I n d u s t r i a l BASIC system i s d i v i d e d i n t o f i v e discrete p a r t s : 1. Editor 2. Compiler 3. Loader 4. Runtime System 5. Runtime System Overlays The OS/8 I n d u s t r i a l BASIC E d i t o r i s used t o create and e d i t t h e s o u r c e program. On r e c e i p t o f a RUN command, t h e E d i t o r stores t h e program i n a temporary f i l e and c h a i n s t o t h e Compiler. The Compiler compiles t h e program i n t o p s e u d o - i n s t r u c t i o n s which are then loaded i n t o core w i t h t h e Runtime System by t h e Loader. The Runtime System i n t e r p r e t s each p s e u d o - i n s t r u c t i o n , c a l l i n g each of t h e Overlays i n t o core as needed. On completion o f t h e program, t h e Runtime System c h a i n s back t o the Editor. An OS/8 I n d u s t r i a l BASIC program c o n s i s t s of a m a i n l i n e segment and u s e r p r o c e s s i n t e r r u p t r o u t i n e s . U s e r process i n t e r r u p t r o u t i n e s are executed i n response t o e x t e r n a l e v e n t s . A more complete d e s c r i p t i o n of t h e OS/8 I n d u s t r i a l BASIC System is provided i n Chapter 11 o f t h i s manual. 1.4.2 OS/8 I n d u s t r i a l BASIC Statements and Commands I n d u s t r i a l BASIC c o n s i s t s of program s t a t e m e n t s and system c o n t r o l commands which are needed t o w r i t e programs. A number of t h e elementary OS/8 I n d u s t r i a l BASIC s t a t e m e n t s and commands are: OS/8 O S / 8 INDUSTRIAL BASIC STATEMENTS LET Assign a v a l u e t o a variable. PRINT P r i n t o u t t h e i n d i c a t e d information. READ I n i t i a l i z e variables t o v a l u e s from t h e list. 1-6 data DATA Provide i n i t i a l data f o r a program. GOTO Change order of program e x e c u t i o n . I F GOTO I F THEN Conditionally execution. change order of program FOR TO STEP S e t up a program loop. NEXT End a program loop. GOSUB Go t o a subroutine. RETURN Return from a s u b r o u t i n e . INPUT G e t i n i t i a l v a l u e s from t h e t e r m i n a l . RFIM I n s e r t a program comment. RESTORE Restore t h e data l i s t . DEF Define a f u n c t i o n . STOP S t o p program e x e c u t i o n . END End a program. DIM Define s u b s c r i p t e d v a r i a b l e s . UDEF Define user-coded TIMER CONTACT COUNTER Associate i n t e r r u p t s e r v i c e r o u t i n e With e x t e r n a l event. DISMISS Return from i n t e r r u p t s e r v i c e r o u t i n e . OS/8 function. INDUSTRIAL BASIC EDIT AND CONTROL COMMANDS LIST L i s t a l l stored program statements. RUN Run t h e c u r r e n t l y stored program. SCRATCH Delete t h e c u r r e n t l y stored program. SAVE Save t h e c u r r e n t l y stored program. OLD R e t r i e v e t h e old program. NEW P r e p a r e f o r a new program. NAME Rename t h e c u r r e n t l y stored program. BYE Exit f r o m BASIC. 1-7 OS/8 I n d u s t r i a l BASIC may e x e c u t e BASIC s t a t e m e n t s i n either of t w o modes, mainline or u s e r process i n t e r r u p t . Mainline Mode i s s t a n d a r d BASIC sequence. User Process I n t e r r u p t Mode i s used t o e x e c u t e r o u t i n e s , s i m i l a r t o BASIC s u b r o u t i n e s , t h a t service e x t e r n a l e v e n t s . These s t a t e m e n t s and commands are explained i n detail w i t h a c t u a l computer o u t p u t i n this manual. For t h e convenience of t h e u s e r , a detailed O S / 8 I n d u s t r i a l BASIC Statement, Command and Function Swnmary is i n c l u d e d i n Appendix A. 1-8 CHAPTER 2 OS/8 2.1 INDUSTRIAL BASIC ARITHMETIC NUMBERS An OS/8 I n d u s t r i a l BASIC number may be any number i n t h e r a n g e of 10-6 1 6 < N < 1 O 6 l 6 . OS/8 I n d u s t r i a l BASIC t r e a t s a l l numbers as decimal numbers t h a t i s , it a c c e p t s any number c o n t a i n i n g a decimal, and assumes a decimal p o i n t a f t e r an integer. The advantage of t r e a t i n g a l l numbers as decimal numbers i s t h a t t h e programmer can use any number o r symbol i n any mathematical e x p r e s s i o n w i t h o u t r e g a r d t o i t s type -- I n a d d i t i o n t o i n t e g e r and decimal f o r m a t s , a t h i r d format i s r e c o g n i z e d and accepted by OS/8 I n d u s t r i a l BASIC and i s used t o e x p r e s s numbers o u t s i d e t h e range .OOOOl<x<999999. T h i s format is c a l l e d e x p o n e n t i a l or E-type n o t a t i o n and i n t h i s format, a number i s e x p r e s s e d as a decimal number times some power of 1 0 . The form is: xxEn where E r e p r e s e n t s " t i m e s 1 0 t o t h e power of", t h u s read: "xx times 1 0 t o t h e power o f n." For example: the number is Data may be i n p u t i n any one or a l l t h r e e of t h e s e forms. R e s u l t s o f computations are o u t p u t as decimals i f t h e y are w i t h i n t h e r a n g e p r e v i o u s l y s t a t e d ; o t h e r w i s e , t h e y are o u t p u t i n E format. OS/8 I n d u s t r i a l BASIC h a n d l e s s i x s i g n i f i c a n t d i g i t s i n normal o p e r a t i o n and i n p u t / o u t p u t , as i l l u s t r a t e d below: Value Typed In Value Output By OS/8 I n d u s t r i a l BASIC .Ol ,0099 999999 1000000 .0000009 0.0099999 0.0099 999999 .100000E+007 .899999E-O06 OS/8 I n d u s t r i a l BASIC a u t o m a t i c a l l y s u p p r e s s e s t h e p r i n t i n g of l e a d i n g and t r a i l i n g zeros i n i n t e g e r numbers and a l l b u t one l e a d i n g zero i n decimal numbers. A s can be s e e n from t h e p r e c e d i n g examples, OS/8 I n d u s t r i a l BASIC formats a l l e x p o n e n t i a l numbers i n t h e form: s i g n .xxxxxxE (+or-)n where x r e p r e s e n t s t h e number c a r r i e d t o s i x decimal p l a c e s , E s t a n d s f o r "times 10 t o t h e power o f , " and n r e p r e s e n t s t h e e x p o n e n t i a l value. For example: -.3470213+009 ,7260003-003 i s e q u a l t o -347,021,000 is equal to 0 . 0 0 0 7 2 6 2-1 2.2 VARIABLES I n d u s t r i a l BASIC i s an algebraic symbol r e p r e s e n t i n g a number, and i s formed by a s i n g l e l e t t e r o r a l e t t e r followed by a d i g i t . For example: A simple v a r i a b l e i n OS/8 Unacceptable Variables Accept abl e V a r i abl e s I 2C B3 AB - av adr iiagbi lte cannot begin a - cannot two or more letters form a variable X The u s e r may a s s i g n v a l u e s t o v a r i a b l e s e i t h e r by i n d i c a t i n g v a l u e s i n a LET s t a t e m e n t , o r by i n p u t t i n g t h e v a l u e s as d a t a . the 10 LET 1-53721 20 LET B3.5456.9 30 LET X=2OE9 40 INPUT Q These o p e r a t i o n s , as w e l l as s u b s c r i p t e d v a r i a b l e s , are d i s c u s s e d i n d e t a i l i n Chapter 5. A d i s c u s s i o n o f s u b s c r i p t e d and u n s u b s c r i p t e d s t r i n g variables i s provided i n Chapter 7. The meaning of t h e = s i g n should b e c l a r i f i e d . In algebraic However, i n OS/8 notation, t h e formula X=X+1 i s meaningless. I n d u s t r i a l BASIC (and m o s t computer l a n g u a g e s ) , t h e e q u a l s i g n d e s i g n a t e s replacement rather t h a n e q u a l i t y . Thus, t h i s formula i s a c t u a l l y t r a n s l a t e d "add one t o t h e c u r r e n t value of X and store t h e new r e s u l t back i n t h e same v a r i a b l e X". Whatever v a l u e s had p r e v i o u s l y been a s s i g n e d t o X w i l l be combined w i t h t h e v a l u e 1. An e x p r e s s i o n such as A=B+C i n s t r u c t s t h e computer t o add t h e v a l u e s of B and C and store t h e r e s u l t i n a t h i r d v a r i a b l e A. The v a r i a b l e A i s n o t b e i n g e v a l u a t e d i n terms of any p r e v i o u s l y a s s i g n e d v a l u e , b u t o n l y i n terms of B and C. Therefore, i f A has been assigned any v a l u e prior t o i t s u s e i n t h i s s t a t e m e n t , the o l d v a l u e i s l o s t ; it is i n s t e a d r e p l a c e d by t h e v a l u e of B+C. 2.3 ARITHMETIC OPERATIONS I n d u s t r i a l BASIC performs a d d i t i o n , s u b t r a c t i o n , m u l t i p l i c a t i o n , as w e l l as more complicated o p e r a t i o n s d i v i s i o n and e x p o n e n t i a t i o n , e x p l a i n e d i n d e t a i l l a t e r i n t h e manual. The f i v e operators used i n w r i t i n g most formulas are: OS/8 2-2 Symbol Operator Meaning Example Addition A + B Subtraction A - B Multiplication A * B Division A / B Exponentiation A t B o r (A**B) (Raise A t o t h e B Power) 2.3.1 P r i o r i t y of A r i t h m e t i c Operations I n any given mathematical formula, O S / 8 I n d u s t r i a l BASIC performs a r i t h m e t i c o p e r a t i o n s i n t h e following o r d e r : the 1. Parentheses receive t o p p r i o r i t y . Any e x p r e s s i o n w i t h i n is evaluated before an unparenthesized parentheses expression. 2. I n absence of p a r e n t h e s e s , t h e o r d e r of p r i o r i t y i s : 3. a. Exponentiation b. M u l t i p l i c a t i o n and Division (of e q u a l p r i o r i t y ) C. Addition and S u b t r a c t i o n (of e q u a l p r i o r i t y ) I f e i t h e r 1 or 2 above does not c l e a r l y d e s i g n a t e t h e o r d e r of p r i o r i t y , then t h e e v a l u a t i o n of e x p r e s s i o n s proceeds from l e f t t o right. The e x p r e s s i o n A/B*C i s e v a l u a t e d from l e f t t o r i g h t as follows: 2.3.2 1. A/B = step 1 2. ( r e s u l t of s t e p l ) * C = answer Parentheses P a r e n t h e s e s may be used by t h e programmer t o change t h e o r d e r of p r i o r i t y (as l i s t e d i n r u l e 2 above), because e x p r e s s i o n s w i t h i n p a r e n t h e s e s are always e v a l u a t e d first. Thus, by enclosing e x p r e s s i o n s a p p r o p r i a t e l y , t h e programmer can c o n t r o l t h e o r d e r of evaluation. Parentheses may be n e s t e d , o r enclosed by a second s e t (or more) o f parentheses. I n t h i s case, t h e e x p r e s s i o n w i t h i n t h e innermost p a r e n t h e s e s i s e v a l u a t e d f i r s t , and then t h e n e x t innermost, and so on, u n t i l a l l have been e v a l u a t e d , Consider t h e following example: 2- 3 A=7* ( ( B t 2 + 4 ) /X) The o r d e r of p r i o r i t y is: 1. Bt2 = step 1 2. ( r e s u l t of s t e p 1 ) + 4 = step 2 3. ( r e s u l t of s-tep 2 ) / X = step 3 4. ( r e s u l t o f s t e p 3)*7 = A P a r e n t h e s e s also p r e v e n t expression is evaluated. any confusion For example : or doubt as to how the A*Bt2/7+B/C+Df2 ((A*Bt2)/7) + ( (B/C) + D t 2 ) Both of these formulas w i l l be executed i n t h e same way. However, t h e i n e x p e r i e n c e d p r o g r a m e r o r s t u d e n t may f i n d t h a t t h e second i s easier t o understand. Spaces may also be used t o i n c r e a s e r e a d a b i l i t y . Since t h e I n d u s t r i a l BASIC compiler i g n o r e s s p a c e s , t h e t w o s t a t e m e n t s : OS/8 10 LET B = D t 2 + 1 10 LETB=Dt2+1 are i d e n t i c a l , b u t s p a c e s i n reading. 2.3.3 the first statement provide ease in R e l a t i o n a l Operators a t some p o i n t t o d i s c o v e r t h e i r r e l a t i o n t o one another. To accomplish t h i s , OS/8 I n d u s t r i a l BASIC makes use o f the f o l l o w i n g r e l a t i o n a l o p e r a t o r s : A program may r e q u i r e t h a t two values be compared = equal t o < less t h a n > greater t h a n =< o r <= less t h a n or e q u a l t o => o r >= g r e a t e r t h a n o r e q u a l t o >< o r <> n o t e q u a l t o Depending upon t h e r e s u l t o f t h e comparison, control of program e x e c u t i o n may be d i r e c t e d t o a n o t h e r p a r t of t h e program. Relational operators are used i n c o n j u n c t i o n w i t h t h e IF-THEN s t a t e m e n t which i s d i s c u s s e d i n Chapter 3. 2-4 2.3.4 Rules f o r Exponentiation The following r u l e s apply i n e v a l u a t i n g t h e e x p r e s s i o n AtB. Rule - Example 1. If B=O, then A + B = l 3t O = l 2. If A=O and B>O, then A+B=O 0+2=0 3. I f Ax0 and B<D, then AtB=O and a DV error message i s p r i n t e d (See Appendix C ) . 0 +-2=0 4. I f B i s an i n t e g e r > 0 , then AfB=A *A *A ...*A where n-B. 3+5=3*3*3*3*3=243 5. If B is an i n t e g e r <O t h e n A t B = l / ( A *A *A A ) where n=B 3+-5=1/243 6. I f B is a decimal (non-integer) and A>O, then AtB=EXP(B*LOG(A)) 2+3.6=12.1257 7. I f B i s a p o s i t i v e or n e g a t i v e decimal (non-integer) and A<O program aborts due t o f a t a l error. -3t2.6 i s i l l e g a l . F a t a l error message EM p r i n t e d . , ...* , , 2-5 CHAPTER 3 OS/8 INDUSTRIAL BASIC STATEMENTS Example Program i s i n c l u d e d a t t h i s p o i n t as an i l l u s t r a t i o n o f t h e format of an OS/8 I n d u s t r i a l BASIC program, t h e ease i n running it, and t h e t y p e of o u t p u t t h a t may be produced. T h i s program and i t s r e s u l t s are f o r t h e m o s t p a r t s e l f - e x p l a n a t o r y . Following s e c t i o n s and c h a p t e r s c o v e r t h e program s t a t e m e n t s and system commands used i n OS/8 I n d u s t r i a l BASIC programming. The f o l l o w i n g - 10 RE# PROGRAM TO TAKE AVERAGE OF 15 REN STUDEiVT GRADES A U D CLASS GHADES 20 P R I N T "HOW RIIAt'JY STUDE'JTS, .(OW YAW GRADES PER STUDEYT"; 30 I ~ U P U T A i B 40 L E T 1 = 0 50 FOR J=I TO A-1 55 L E T V=O 60 P R I N T "STUDEYT NUMBER = " t J 7 5 P R I N T "EYTER GRADES" 76 L E T D=J 80 FOR K = D TO D + < 8 - 1 ) 8 1 I'VPUT G 82 LET V=V+G 8 5 NEXT K 9 0 L E T V=V/B 9 5 PRIiVT "AVERAGE GRADE = * ' J V 9 6 PRINT 99 L E T Q=Q+V 100 NEXT J 101 P R I N T 102 P R I N T 103 P R I N T "CLASS AVERAGE =";Q/A 104 STOP 105 END READY RUNYH HOW 1vlAs4Y GRADES PER STUDEt'JT?5,4 HOW YANY S T U D W T S , STUDENT dUMBER W T E R GRADES = 0 ? 78 ?8 6 ?88 ?74 AVERAGE GRADE = 8 1 5 STUDENT NUMBER = EPJTER GRADES 1 ? 59 ?8 6 ?70 ?87 AVERAGE GRADE = 75.5 3-1 STUDENT s\)UHBER = EVTER GRADES 2 ?58 ? 64 ?75 ?8 0 AVERAGE GRADE = 6 9 - 2 5 STUDENT VUMBER ENTER GRADES = 3 ?88 ?9 2 ?8 5 ?79 AVERAGE GRADE = 8 6 STUDENT NUHBER = EVTER GRADES ? 60 ?78 4 ?8 5 ?4 0 AVERAGE GRADE = 7 5 . 7 5 CLASS AVERAGE = 7 - 7 - 6 3.1 STATEMENT NUMBERS A program i s made up o f s t a t e m e n t s . Each l i n e of t h e program b e g i n s w i t h a l i n e number of 1 t o 5 d i g i t s t h a t s e r v e s to i d e n t i f y t h e l i n e as a s t a t e m e n t . The l a r g e s t allowable l i n e number i s 99999. Line numbers s e r v e t o s p e c i f y t h e order i n which t h e s e s t a t e m e n t s are t o b e performed. Before t h e program i s r u n , OS/8 I n d u s t r i a l BASIC s o r t s o u t and edits t h e program, p u t t i n g t h e s t a t e m e n t s i n t o t h e order s p e c i f i e d by their l i n e numbers; t h u s , the program s t a t e m e n t s can b e t y p e d i n any order, as long as each s t a t e m e n t i s p r e f i x e d w i t h a l i n e number i n d i c a t i n g i t s p r o p e r sequence i n t h e order o f e x e c u t i o n . Each s t a t e m e n t starts a f t e r i t s l i n e number w i t h an E n g l i s h word ( e x c e p t t h e LET s t a t e m e n t where 'LET' i s o p t i o n a l ) which d e n o t e s t h e t y p e o f statement. Unlike program s t a t e m e n t s , system commands are n o t preceded by l i n e numbers and are e x e c u t e d immediately a f t e r t h e y are ( R e f e r t o Chapter 9 f o r a f u r t h e r d e s c r i p t i o n o f commands.) typed i n . Spaces have no s i g n i f i c a n c e i n BASIC programs or commands, e x c e p t i n messages or literal s t r i n g s which are p r i n t e d out, and i n line numbers. Thus, s p a c e s may be used t o modify a program and make it more readable. A common programming p r a c t i c e i s t o number l i n e s by f i v e s or t e n s , so t h a t a d d i t i o n a l l i n e s may be i n s e r t e d i n a program w i t h o u t t h e n e c e s s i t y o f renumbering l i n e s a l r e a d y p r e s e n t . Renumbering a program can be accomplished by u s i n g the RESEQ program described i n Chapter 9 , s e c t i o n 9.1.2. 3-2 M u l t i p l e s t a t e m e n t s may be placed on a s i n g l e l i n e by s e p a r a t i n g each s t a t e m e n t from t h e preceding s t a t e m e n t w i t h a b a c k s l a s h (SHIFT/L). For example: 10 A=5\B=. 2\C=3\PRINT "ENTER DATA" All of the s t a t e m e n t s i n l i n e 1 0 w i l l be executed before BASIC continues to t h e next line. Only one s t a t e m e n t number a t t h e beginning of t h e e n t i r e l i n e i s necessary. However, it should be remembered t h a t program c o n t r o l cannot b e t r a n s f e r r e d t o a s t a t e m e n t w i t h i n a l i n e , b u t o n l y t o t h e f i r s t s t a t e m e n t of t h e l i n e i n which it i s contained. NOTE U s e r process i n t e r r u p t r o u t i n e s only Le. when w i l l be e n t e r e d the mainline e n c o u n t e r s a l i n e number. loo FOR 1-1 TO ~ O O O O \ N E X T I does n o t allow u s e r process i n t e r r u p t r o u t i n e s t o be e n t e r e d w h i l e e x e c u t i n g t h i s l i n e because t h e e n t i r e loop does n o t c o n t a i n l i n e numbers. 100 105 FOR 1-1 TO 10000 NEXT I w i l l allow u s e r process i n t e r r u p t r o u t i n e s executed w h i l e p r o c e s s i n g t h e loop. 3.2 REMARK -- to be THE COMMENTING STATEMENT The REM or REMARK s t a t e m e n t allows t h e programmer t o i n s e r t comments remarks i n t o a program without t h e s e comments a f f e c t i n g execution. The OS/8 I n d u s t r i a l BASIC compiler i g n o r e s e v e r y t h i n g between REM and the end of t h e l i n e . The form is: or ( l i n e number) REM (message) I n t h e Example Program, l i n e s 1 0 and 15 are REMARK s t a t e m e n t s I t is o f t e n u s e f u l t o p u t t h e name d e s c r i b i n g what t h e program does. of the program and information r e l a t i n g t o i t s use a t the beginning where it i s a v a i l a b l e for f u t u r e r e f e r e n c e . R e m a r k s throughout the body of a long program w i l l h e l p subsequent debugging by e x p l a i n i n g t h e purpose of each s t a t e m e n t w i t h i n t h e program. 3- 3 3.3 3.3.1 STATEMENTS FOR TERMINATING A PROGRAM END The END s t a t e m e n t ( l i n e 140 i n t h e Example Program) should be t h e l a s t s t a t e m e n t of t h e e n t i r e program. The form is: ( l i n e number) END NOTE END statement must be t h e last s t a t e m e n t i n t h e program. A program i s t e r m i n a t e d when an END s t a t e m e n t is executed, I n real t i m e o p e r a t i o n s a program should never e x e c u t e e i t h e r an END or a STOP. An 3.3.2 STOP The STOP s t a t e m e n t is used synonymously w i t h t h e END s t a t e m e n t t o t e r m i n a t e e x e c u t i o n ; b u t while END o c c u r s o n l y once a t t h e end of a program, STOP may occur any number of t i m e s . The format o f t h e STOP s t a t e m e n t is: ( l i n e number) STOP This s t a t e m e n t s i g n a l s t h a t e x e c u t i o n i s t o be p o i n t i n t h e program where it i s encountered. 3.4 LET terminated at that -- THE ASSIGNMENT STATEMENT The Assignment (mT) s t a t e m e n t i s probably t h e m o s t commonly used OS/8 I n d u s t r i a l BASIC s t a t e m e n t and is used whenever a v a l u e i s t o be assigned t o a variable. I t i s of t h e form: ( l i n e number) LET x = e x p r e s s i o n where x r e p r e s e n t s a v a r i a b l e , and t h e e x p r e s s i o n i s e i t h e r a number, a n o t h e r v a r i a b l e , or an a r i t h m e t i c e x p r e s s i o n . The word " U T " i s o p t i o n a l ; t h u s t h e f o l l o w i n g s t a t e m e n t s are treated t h e same: 100 LET A=AfB+10 110 LET L=L+1 100 A=AfB+10 110 L=L+1 The LET s t a t e m e n t is n o t s t r i c t l y an e q u a l i t y . LET means " e v a l u a t e t h e e x p r e s s i o n t o t h e r i g h t of t h e e q u a l s i g n and a s s i g n t h i s v a l u e t o t h e v a r i a b l e on t h e left." Thus, t h e s t a t e m e n t L=L+l means "set L e q u a l t o a value one g r e a t e r t h a n it w a s before." 3-4 3.5 INPUT/OUTPUT STATEMENTS AND FUNCTIONS Input/output s t a t e m e n t s allow t h e u s e r t o b r i n g data i n t o and o u t p u t r e s u l t s o r data a t any t i m e d u r i n g execution. 3.5.1 a program The INPUT Statement The INPUT s t a t e m e n t i s used when d a t a i s t o be s u p p l i e d by t h e u s e r f r o m t h e t e r m i n a l keyboard while a program i s e x e c u t i n g and i s of t h e form: ( l i n e number) INPUT x l , x2,...,xn where x l through xn r e p r e s e n t v a r i a b l e names. 25 For example: INPUT A When t h i s s t a t e m e n t o c c u r s i n Mainline Mode, t h e u s e r w i l l be prompted w i t h a q u e s t i o n mark and while w a i t i n g f o r i n p u t , u s e r p r o c e s s i n t e r r u p t s e r v i c e r o u t i n e s may execute. I f it o c c u r s i n t h e u s e r p r o c e s s i n t e r r u p t service r o u t i n e , t h e u s e r w i l l be prompted w i t h an exclamation mark followed by a q u e s t i o n mark and t h e system w i l l w a i t for i n p u t completion b e f o r e p r o c e s s i n g any o t h e r u s e r p r o c e s s i n t e r r u p t routine. NOTE I f an i n p u t statement o c c u r s i n t h e u s e r p r o c e s s interrupt s e r v i c e r o u t i n e w h i l e t h e u s e r is e n t e r i n g i n p u t i n t h e Mainline Mode, t h e t e x t i s lost t o the l a s t terminator. After t h e request is f u l f i l l e d f o r t h e u s e r process i n t e r r u p t s e r v i c e r o u t i n e t h e mainline r e q u e s t w i l l be r e i s s u e d . The following r u l e s apply t o t h e u s e of t h e I N P U T statement. Rule 1. The following c h a r a c t e r s are recognized i n p u t t i n g numeric data: as acceptable when + or - s i g n d i g i t s 0 through 9 the letter E l e a d i n g spaces (ignored) ( f i r s t decimal p o i n t ) . Terminators are c a r r i a g e r e t u r n or coma. A l l o t h e r c h a r a c t e r s cause t h e remaining f i e l d t o be ignored. 10 .. INPUT A,B,C,D,E 3-5 characters in the RU"H ?10,32A16,8 ?5,6 READY 1 I n t h e above example, A=10, B-32, C=8, -5, and E = 6 . i n p u t t i n g numeric d a t a , t w o t e r m i n a t o r s read in succession imply t h a t t h e d a t a between t h e terminators i s 0. When 2. .. . 10 INPUT AIBIC,D,E RU"H ?5,10,,12,15 READY I n t h e above example A=5, B=lO, C=O, OC12, and E=15. 3. I n response t o an INPUT s t a t e m e n t t h e user can p r o v i d e more d a t a than i s r e q u e s t e d by t h e I N P U T statement. The remaining or unused d a t a i s saved f o r subsequent u s e by t h e n e x t INPUT statement. The q u e s t i o n mark ( ? ) i s n o t p r i n t e d u n t i l t h e program i s out of d a t a . 4. When inputting string data, all characters, except are recognized as part o f the s t r i n g . See Chapter 7 f o r f u r t h e r i n f o r m a t i o n r e l a t i n g t o s t r i n g s . terminators, - l i n e f e e d i s recognized as p a r t of t h e t h e r e f o r e is s t o r e d i n t h e t e x t b u f f e r . 5. 3.5.2 A s t r i n g d a t a , and The PRINT Statement .. 3.5 2 1 General The PRINT comments, terminal. statement is used t o o u t p u t r e s u l t s values of variables, or p l o t p o i n t s The format is: of computations, o f a graph on the (line number) PRINT expression When used w i t h o u t an e x p r e s s i o n , a blank l i n e w i l l b e o u t p u t on t h e terminal. For more complicated uses, t h e t y p e o f e x p r e s s i o n and t h e t y p e o f format c o n t r o l c h a r a c t e r s (comma or semicolon) f o l l o w i n g t h e word PRINT determines which formats w i l l b e c r e a t e d . In order to have the computer print out the r e s u l t s of a computation, or t h e value o f a variable a t any p o i n t i n t h e program, t h e u s e r t y p e s 3-6 t h e l i n e number, PRINT, and t h e v a r i a b l e name(s) s e p a r a t e d by a format control c h a r a c t e r , i n t h i s case, commas: 5 10 15 A=16\B=5\C=4 PRINT A,C+B,SQR(A) END The PRINT s t a t e m e n t may a l s o be used t o o u t p u t a message or l i n e of text. The d e s i r e d message i s simply placed i n q u o t a t i o n marks i n t h e PRINT s t a t e m e n t as follows: PRINT "THIS IS A TEST" 10 When l i n e 10 i s encountered d u r i n g e x e c u t i o n , t h e printed : following will be or a THIS IS A TEST A message may be combined with the result a of calculation v a r i a b l e as follows : PRINT "AMOUNT PER PAYMENT =";R 80 Assuming R=344.961 when l i n e 80 i s encountered d u r i n g e x e c u t i o n , w i l l be o u t p u t as: this AMOUNT PER PAYMENT = 344.961 THE PRINT s t a t e m e n t can also cause a c o n s t a n t t o console For example : . be printed on the P R I N T 1.234,SQR(10014) 10 w i l l cause t h e following t o be o u t p u t a t e x e c u t i o n t i m e : 1.234 100.07 Any a l g e b r a i c e x p r e s s i o n i n a PRINT s t a t e m e n t w i l l be e v a l u a t e d u s i n g Numbers w i l l be p r i n t e d according t h e c u r r e n t value of t h e v a r i a b l e s . t o t h e format s p e c i f i e d i n Chapter 2 and i n paragraph 3.5.2.3. 3.5.2.2 Format Control C h a r a c t e r s I n O S / 8 I n d u s t r i a l BASIC, a t e r m i n a l l i n e i s formatted i n t o f i v e f i x e d zones ( c a l l e d p r i n t zones) of 14 columns each. A program such a s : 5 10 15 A=2.3\B=21\C=156.75\D=l.l34\E=23.4 PRINT A,B,C,D,E END where t h e c o n t r o l c h a r a c t e r comma (,) i s used t o v a r i a b l e s i n t h e P R I N T s t a t e m e n t , w i l l cause t h e v a r i a b l e s t o be p r i n t e d using a l l f i v e zones. RU"H 2.3 21 156.75 3-7 1.134 separate the v a l u e s of t h e 23.4 14 column+ 14 columnsk 14 columns+ 14 column+ 14 columns READY I t i s n o t n e c e s s a r y t o use t h e s t a n d a r d f i v e zone format f o r output. c a u s e s t h e t e x t o r d a t a t o be The c o n t r o l character semicolon (;) o u t p u t immediately a f t e r t h e l a s t c h a r a c t e r p r i n t e d . The f o l l o w i n g example program i l l u s t r a t e s c h a r a c t e r s i n PRINT s t a t e m e n t s the use of the control 10 READ A0 B> C 20 P R I N T A D B D C D A ~ ~ D B ~ ~ J C ~ ~ 30 P R I N T 40 P R I N T Af B; Cf A t 23 B t 2; C t 2 50 DATA 4,506 60 Et’lD READY RWVH 5 4 25 16 6 36 4 5 6 16 25 36 READY A s t h i s example i l l u s t r a t e s , when more t h a n f i v e v a r i a b l e s are l i s t e d i n t h e PRINT s t a t e m e n t , OS/8 I n d u s t r i a l BASIC a u t o m a t i c a l l y moves t h e s i x t h number t o t h e beginning of t h e n e x t l i n e . 3.5.2.3 P r i n t i n g Numbers For any format ( i n t e g e r , decimal, or p r i n t s numbers i n t h e form: E-type) OS/8 Industrial BASIC s i g n number space where s i g n is e i t h e r minus (-1 always t r a i l s t h e number. or blank ( f o r p l u s ) and a READY 10 A= 6 4 \ B = 32\C=72 20 P R I N T A l B i C 2 1 E,AD RUWH 64 - 3 2 7 2 - 3-8 blank space 3.5.2.4 PRINT Used With INPUT Another use o f t h e PRINT statement i s t o combine it w i t h an s t a t e m e n t so a s t o i d e n t i f y t h e d a t a expected t o be e n t e r e d . example, c o n s i d e r t h e following program: READY - 10 REY PROGRAM TO C W P U T E I N T E R E S T PAYYEVTS 20 P R I N T "I NTEREST I N PERCEiVT"; 25 INPUT J 26 LET J = J / 1 0 0 30 P R I N T "AMOU'JT OF LOA,Vs'3 35 IVPUT A 40 P R I N T "NUMBER OF YEARS"; 45 1"JPUT N 50 P R I N T "NUMBER OF PAYgENTS PER YEAH"; 55 INPUT 60 L E T N=N*M 6 5 L E T I=J/M 70 LET B=l+I 7 5 L E T R=A*I / C 1- l / B t N ) 78 P R I N T 8 0 P R I N T "AMOUNT PER PAY;VIEiVT ="SR 8 5 P R I N T "TOTAL I N T E R E S T =*'; H*N-A 9 0 LET B=A 9 5 PRINT " INTEREST APP T O P R I N BALANCE" 100 L E T L=B*I 1 1 0 L E T P=R-L 120 L E T B=B-P 130 PRI INT L DPDB 140 I F B>=R G O TO 1 0 0 150 P R I N T B*IDR-B*I 160 P R I N T "LAST PAYMEVT =";B*I+B 200 END READY RUNNH INTEREST I N PERCENT?9 AMOUNT OF LOAN?2500 NUMBER OF YEARS?P NUMBER OF PAYMENTS PER YEAR?4 AMOUNT PER PAYMENT = 344.965 TOTAL I N T E R E S T = 259.724 INTEREST APP TO PRIN BALAVCE 56.25 288 7 1 5 2211.28 49.7539 29 5.2 1 2 19 16.07 43.1116 301.8 54 1614.22 36.3199 308.645 1385.57 29. 37 54 31 5. 59 989 e982 22.2746 322.69 1 667. 29 1 150 0141 329 9 5 1 337.34 70 59015 337.37 5 LAST PAYMENT = 3 4 4 . 9 3 READY 3-9 INPUT As an As can be n o t i c e d i n t h i s example, t h e q u e s t i o n mark i s grammatically u s e f u l i n a program i n which s e v e r a l v a l u e s are t o be i n p u t by allowing t h e programmer t o formulate a v e r b a l q u e s t i o n which t h e i n p u t v a l u e w i l l answer. 3.5.3 The TAB(X) Function The TAB f u n c t i o n , which may o n l y be used i n a PRINT s t a t e m e n t , allows t h e u s e r t o p o s i t i o n t h e p r i n t i n g of c h a r a c t e r s anywhere on t h e t e r m i n a l l i n e ( o r o t h e r p r i n t i n g d e v i c e l i n e when used w i t h PRINT#, see Chapter 1 0 ) . P r i n t p o s i t i o n s can be thought of as b e i n g numbered The form of t h i s from 1 t o 72 across t h e t e r m i n a l from l e f t t o r i g h t . f u n c t i o n is: TAB ( X ) where t h e argument X r e p r e s e n t s t h e p o s i t i o n (from 1 t o 7 2 columns a v a i l a b l e on t h e t e r m i n a l ) i n which t h e n e x t character w i l l be typed. Each t i m e t h e TAB f u n c t i o n i s used i n a PRINT s t a t e m e n t , p o s i t i o n s are counted from t h e beginning of t h e l i n e , n o t from t h e c u r r e n t p o s i t i o n of t h e p r i n t i n g head. F o r example, t h e TAB f u n c t i o n i n t h e f o l l o w i n g program c a u s e s t h e c h a r a c t e r "/" t o be p r i n t e d a t 24 e q u a l l y spaced p o s i t i o n s along t h e l i n e . 10 20 30 40 FOR K=3 TO 72 STEP 3 PRINT TAB(K) in/"; NEXT K END I f t h e argument X i n t h e TAB f u n c t i o n i s less t h a n t h e c u r r e n t p o s i t i o n of t h e p r i n t i n g head, p r i n t i n g i s started a t t h e c u r r e n t position. I f t h e argument X i s g r e a t e r t h a n 7 2 ( t h e number o f columns a v a i l a b l e i n an o u t p u t l i n e ) , a carriage r e t u r n - l i n e feed is e x e c u t e d and p r i n t i n g resumes a t p o s i t i o n 1. 3.5.4 The P N T ( X ) Function an a d d i t i o n a l f u n c t i o n , P N T ( X ) , to i n c r e a s e i n p u t / o u t p u t f l e x i b i l i t y . The f u n c t i o n i s p r i m a r i l y used f o r o u t p u t t i n g non-printing c h a r a c t e r s such as t h e " b e l l " , b u t can be used f o r m o r e s o p h i s t i c a t e d a p p l i c a t i o n s . The P N T ( X ) f u n c t i o n , l i k e t h e TAB(X) f u n c t i o n , may o n l y be used i n either a PRINT or PRINT# statement. The form of t h e f u n c t i o n is: OS/8 I n d u s t r i a l BASIC provides PNT ( X ) where t h e argument X r e p r e s e n t s t h e decimal v a l u e of t h e c h a r a c t e r t o be output. For example, t h e statement: 10 PRINT "X=";3.14159;PNT(13) ;TAB(14) ;"/" 3-10 7-bit ASCII w i l l p r i n t t h e s l a s h (/) on t o p of t h e e q u a l s i g n a f t e r e x e c u t i n g c a r r i a g e r e t u r n (CR=13 1 and a TAB t o column 2 as shown below: a X 9,3.14159 Notice t h a t a TAB(14) i s r e q u i r e d s i n c e O S / 8 I n d u s t r i a l BASIC remembers the p r i n t head t o be a t column 1 2 a f t e r t h e carriage r e t u r n (11 columns f o r X= 3.14159 and 1 column for t h e PNT f u n c t i o n ) . A tab t o column 2 a f t e r t h e carriage r e t u r n p r o v i d e s a t o t a l of 1 4 columns. The PNT(13) carriage r e t u r n does n o t z e r o t h e column count b u t , i n f a c t , adds t o t h e column count, (This example may n o t work on some t e r m i n a l s . ) 3.6 THE READ AND DATA STATEMENTS READ and DATA s t a t e m e n t s are used t o provide data t o a program. One s t a t e m e n t is never used without t h e other. T h e form of t h e READ s t a t e m e n t is: . ( l i n e number) READ xl,x2,. , ,xn where x l through xn r e p r e s e n t v a r i a b l e names. 10 For example: READ A,B,C A, B, and C are v a r i a b l e s t o which v a l u e s w i l l be assigned. Variables i n a READ s t a t e m e n t must be separated by commas. FtEAD s t a t e m e n t s are g e n e r a l l y placed a t the beginning of a program, b u t must a t least l o g i c a l l y occur before t h a t p o i n t i n t h e program where t h e v a l u e i s r e q u i r e d f o r some computation. Values which w i l l be assigned t o t h e v a r i a b l e s i n a READ s t a t e m e n t are s u p p l i e d i n a DATA s t a t e m e n t o f t h e form: .. ( l i n e number) DATA x1,x2, , ,xn where x l through xn r e p r e s e n t values. The v a l u e s must be separated by commas and occur i n the same order as t h e v a r i a b l e s which are l i s t e d i n t h e corresponding READ statement. A DATA s t a t e m e n t a p p r o p r i a t e for t h e preceding READ s t a t e m e n t is: 70 DATA 1,2,3 Thus, a t e x e c u t i o n t i m e A = l , B-2, and C=3. The DATA s t a t e m e n t is u s u a l l y placed a t t h e end of a program (before t h e END s t a t e m e n t ) where i t i s e a s i l y a c c e s s i b l e t o t h e programmer s h o u l d he wish t o change the v a l u e s , A READ s t a t e m e n t may have more or f e w e r variables t h a n there are v a l u e s i n any one DATA statement. The READ s t a t e m e n t c a u s e s OS/8 I n d u s t r i a l BASIC t o search a l l a v a i l a b l e DATA s t a t e m e n t s i n the order their l i n e numbers u n t i l v a l u e s are found f o r each v a r i a b l e i n t h e A second READ s t a t e m e n t w i l l begin r e a d i n g v a l u e s where t h e first stopped. I f a t some p o i n t i n the program an a t t e m p t i s made t o read data which is n o t p r e s e n t , OS/8 I n d u s t r i a l BASIC w i l l s t o p and of READ. 3-11 p r i n t t h e f o l l o w i n g message a t t h e console: DA AT LINE YYYYY where YYYYY i n d i c a t e s t h e l i n e which caused t h e error. 3.7 RESTORE If it is desired t o use t h e same data more t h a n once i n a program, t h e s t a t e m e n t w i l l make it p o s s i b l e t o r e c y c l e through t h e DATA l i s t beginning w i t h t h e f i r s t DATA statement. The RESTORE s t a t e m e n t is of t h e form: RESTORE ( l i n e number) RESTORE An example of i t s use follows: 15 READ B,C,D 55 60 RESTORE READ E,F,G . 80 . 100 DATA 6,3,4,7,9,2 END The READ s t a t e m e n t s i n l i n e s 15 and 60 w i l l both read t h e f i r s t three data v a l u e s provided i n l i n e 80, ( I f t h e RESTORE s t a t e m e n t had n o t been i n s e r t e d b e f o r e l i n e 60, then t h e second READ would pick up data i n l i n e 80 s t a r t i n g w i t h t h e f o u r t h v a l u e , ) The programmer may, i f h e chooses t o do so, use t h e same v a r i a b l e t h e second t i m e through t h e data, s i n c e t h e v a l u e s are b e i n g read as though f o r t h e f i r s t t i m e . I n order t o s k i p unwanted v a l u e s , t h e programmer may i n s e r t replacement, or dummy v a r i a b l e s . Consider: names - 1 REN PROGRAM T O I L L U S T R A T E USE OF RESTORE 20 READ N 25 P R I N T "VALUES OF X ARE:" 30 FOR L = l TO N 40 READ X 50 P R I N T X 0 60 NEXT I 7 0 RESTORE 185 P R I N T 190 P R I N T "SECOND L I S T OF X VALUES" 200 P R I N T "FOLLOWING RESTORE STATEMENT: " 210 FOR 1 = 1 TO N 3-12 220 R E A D X 230 P R I N T X, 240 NEXT I 250 DATA 4,1, 2 251 D A T A 3,4 300 F 3 D READY RUVNH V A L U E S OF X ARE: 1 2 3 SECOND L I S T OF X V A L U E S F O L L O W I N G R E S T O R E STATEMENT: 4 1 2 READY 4 3 The second t i m e t h e data values are read, t h e f i r s t X p i c k s up t h e v a l u e o r i g i n a l l y assigned t o N i n l i n e 20, and as a r e s u l t , OS/8 I n d u s t r i a l BASIC p r i n t s : 4 2 1 3 To circumvent t h i s , t h e programmer could i n s e r t a dummy v a r i a b l e which would p i c k up and store t h e f i r s t v a l u e , b u t would n o t be r e p r e s e n t e d i n t h e PRINT s t a t e m e n t , i n which c a s e t h e o u t p u t would be t h e same each t i m e through the list. 3.8 CONTROL STATEMENTS C e r t a i n c o n t r o l s t a t e m e n t s cause t h e e x e c u t i o n of a program t o jump t o a d i f f e r e n t l i n e either u n c o n d i t i o n a l l y o r depending upon some c o n d i t i o n w i t h i n the program. The following s t a t e m e n t s g i v e t h e programmer c a p a b i l i t i e s i n t h i s area. 3.8.1 GOTO The GOTO (or GO TO) s t a t e m e n t i s an u n c o n d i t i o n a l s t a t e m e n t used t o direct program c o n t r o l either forward o r backward i n a program. The form of t h e GOTO s t a t e m e n t is: ( l i n e number) GOTO n where n r e p r e s e n t s a s t a t e m e n t number. When t h e l o g i c of t h e program reaches t h e GOTO s t a t e m e n t , t h e s t a t e m e n t ( s ) immediately following w i l l n o t be executed; i n s t e a d e x e c u t i o n is t r a n s f e r r e d t o t h e s t a t e m e n t beginning w i t h t h e l i n e number i n d i c a t e d . The following program never reaches t h e END s t a t e m e n t ; it does a READ, p r i n t s something, and jumps back t o t h e READ v i a a GOTO statement. It attempts t o do t h i s o v e r and over u n t i l it runs o u t of d a t a , which i s sometimes an a c c e p t a b l e , though n o t a d v i s a b l e , way t o end a program. 3-13 READY - PROGRAN ENDING WITH ERROR 1 1 REM MESSAGE WHEN OUT OF DATA 20 READ X 10 REM - 25 PRINT "X="3X,"Xt2="3Xt2 30 G O TO 20 35 DATA 1 D 5~ 1 0 ~ 1 SD20r 25 40 EVD READY RUNNH x= 1 x= 5 x= 10 x- 1s x= 20 X= Xt2= 1 Xt2= 25 Xt2= 100 X t 2 = 225 Xt2= 400 Xt2= 625 25 DA AT L I N E 00020 READY 3.8.2 IF-THEN and IF-GOT0 I f a program r e q u i r e s t h a t t w o v a l u e s be compared a t some p o i n t , c o n t r o l of program e x e c u t i o n may be d i r e c t e d t o d i f f e r e n t procedures depending upon t h e r e s u l t of t h e comparison. I n computing, v a l u e s are l o g i c a l l y tested t o see whether t h e y are e q u a l t o , g r e a t e r t h a n , or less t h a n a n o t h e r v a l u e , or p o s s i b l y a combination of t h e t h r e e . T h i s i s accomplished by u s e of t h e r e l a t i o n a l o p e r a t o r s d i s c u s s e d i n Chapter 2. IF-THEN and IF-GOT0 s t a t e m e n t s a l l o w t h e programmer t o t e s t t h e relationship between two variables, numbers, or e x p r e s s i o n s . Providing t h e r e l a t i o n s h i p d e s c r i b e d i n t h e I F s t a t e m e n t is t r u e a t the p o i n t it is tested, c o n t r o l w i l l t r a n s f e r t o t h e l i n e number specified. I f t h e r e l a t i o n s h i p described i n t h e I F s t a t e m e n t i s n o t t r u e a t the p o i n t it is tested, c o n t r o l w i l l t r a n s f e r t o t h e l i n e f o l l o w i n g the I F s t a t e m e n t . The s t a t e m e n t s are of t h e form: GOTO ( l i n e number)IF v l < r e l a t i o n > v2 or X THEN where v l and v2 r e p r e s e n t v a r i a b l e names, numbers, or e x p r e s s i o n s , and x r e p r e s e n t s a l i n e number. The u s e of e i t h e r THEN or GOTO i s acceptable. I f t h e f o l l o w i n g example, t h e v a l u e o f t h e v a r i a b l e A remains t h e same depending on A's r e l a t i o n t o B. 100 110 I F A>B THEN 120 A=AtB-1 120 C=A/D 3-14 is changed or NOTE ' When using non-integer arithmetic in the IF-THEN statement, the test for equality may not always be appropriate due to the nature of the floating-point arithmetic used by the computer. To avoid this problem, the programmer should either avoid using non-integer arithmetic in fractional values less than the tolerance desired. IF-THEN statements that test the running variable in FOR-NEXT loops (see Chapter 4 ) are particularly sensitive to this problem. For example: TO 5 STEP .1 10 FOR A=-5 20 30 40 50 IF A=O THEN 50 60 NEXT A STOP PRINT "EQUAL TO ZERO" END The above margin will never go to line 50. 3-15 CHAPTER 4 LOOPS Frequently programmers are i n t e r e s t e d i n w r i t i n g a program i n which one o r more p o r t i o n s are executed a number of t i m e s , u s u a l l y w i t h To w r i t e t h e s i m p l e s t program i n which s l i g h t v a r i a t i o n s each t i m e . t h e p o r t i o n of t h e program t o be r e p e a t e d i s w r i t t e n j u s t once, a loop is used. A loop i s a block of i n s t r u c t i o n s t h a t t h e computer e x e c u t e s repeatedly u n t i l a specified terminal condition is m e t . OS/8 I n d u s t r i a l BASIC provides t w o s t a t e m e n t s t o s p e c i f y a loop: FOR and NEXT. 4.1 FOR AND NEXT STATEMENTS The FOR s t a t e m e n t i s o f t h e form: ( l i n e number) FOR v=xl TO x2 STEP x3 where v r e p r e s e n t s a v a r i a b l e name, and x l , x2, and x3 a l l r e p r e s e n t expressions ( a numerical v a l u e , v a r i a b l e name, o r mathematical expression). v i s termed t h e index, x l t h e i n i t i a l v a l u e , x2 t h e For example: t e r m i n a l value, and x3 t h e incremental value. 15 FOR K=2 TO 20 STEP 2 This means t h a t t h e loop w i l l be r e p e a t e d as long as K i s less t h a n or e q u a l t o 20. Each t i m e through t h e loop, K i s incremented by 2 , so t h e loop w i l l be executed a t o t a l of 10 t i m e s . variable used as an index i n a FOR s t a t e m e n t must n o t be subscripted, although a common u s e of loops i s t o deal w i t h s u b s c r i p t e d v a r i a b l e s , using t h e value of t h e index as t h e s u b s c r i p t of a p r e v i o u s l y d e f i n e d v a r i a b l e ( t h i s i s i l l u s t r a t e d i n Chapter 5 , s e c t i o n 5.1 concerning S u b s c r i p t e d Variables) A . The NEXT s t a t e m e n t is of t h e form: ( l i n e number) NEXT v and s i g n a l s t h e end of the loop. When e x e c u t i o n of t h e loop r e a c h e s t h e NEXT s t a t e m e n t , t h e computer adds t h e STEP v a l u e t o t h e index and checks t o see i f t h e index i s less than or e q u a l t o t h e t e r m i n a l I f t h e value o f t h e index value. I f so, t h e loop i s executed again. exceeds t h e t e r m i n a l v a l u e , c o n t r o l f a l l s through t h e loop t o t h e s t a t e m e n t following t h e NEXT s t a t e m e n t , w i t h t h e v a l u e of t h e i n d e x e q u a l l i n g t h e value it w a s assigned t h e f i n a l t i m e through t h e loop. If t h e STEP value i s omitted, a value of +1 is assumed. Since +1 i s t h e u s u a l STEP value, t h a t p o r t i o n of t h e s t a t e m e n t is f r e q u e n t l y omitted. The STEP value may a l s o be a n e g a t i v e number. The following example i l l u s t r a t e s t h e u s e executed of loops. This loop is 10 t i m e s : the value of I i s 1 0 when control leaves t h e loop. +1i s t h e assumed STEP value. 4-1 READY 10 FOR 1 = 1 T O 10 20 NEXT I 30 P R I N T I 40 END RUNNH 10 READY I f l i n e 1 0 had been: 1 0 FOR 1110 TO 1 STEP -1 t h e v a l u e p r i n t e d by t h e computer would be 1. As i n d i c a t e d earlier, the numbers used i n the FOR s t a t e m e n t are expressions: t h e s e e x p r e s s i o n s are e v a l u a t e d upon first e n c o u n t e r i n g t h e loop. While the index, i n i t i a l , t e r m i n a l , and STEP v a l u e s may be changed w i t h i n t h e loop, t h e v a l u e a s s i g n e d t o t h e i n i t i a l e x p r e s s i o n remains as o r i g i n a l l y d e f i n e d u n t i l t h e t e r m i n a l c o n d i t i o n i s reached. T o i l l u s t r a t e this p o i n t , c o n s i d e r the l a s t example program. The v a l u e of I ( i n l i n e 1 0 ) can be s u c c e s s f u l l y changed as follows: 10 15 FOR 1-1 TO 10 LET I=10 20 NEXT I The loop w i l l be executed o n l y once s i n c e t h e v a l u e 1 0 has been reached by t h e v a r i a b l e I and t h e t e r m i n a l c o n d i t i o n i s s a t i s f i e d . I f t h e value of the c o u n t e r variable i s o r i g i n a l l y set e q u a l t o t h e t e r m i n a l v a l u e , the loop w i l l e x e c u t e once, r e g a r d l e s s of t h e STEP value. I f t h e s t a r t i n g v a l u e i s beyond t h e - t e r m i n a l v a l u e , t h e loop w i l l n e v e r e x e c u t e because an i n i t i a l check is made of t h e s t a r t i n g The f o l l o w i n g and t e r m i n a l v a l u e s b e f o r e t h e loop i s executed. s t a t e m e n t is executed b u t t h e loop it d e s c r i b e s would n e v e r be executed : 1 0 FOR I s 1 0 TO 20 STEP -2 I t is possible t o e x i t from a FOR-NEXT loop w i t h o u t t h e index r e a c h i n g C o n t r o l may o n l y t r a n s f e r t h e t e r m i n a l value v i a an I F statement. i n t o a loop which h a s been l e f t e a r l i e r w i t h o u t b e i n g completed, e n s u r i n g t h a t the t e r m i n a l and STEP v a l u e s are assigned. 4.2 NESTING LOOPS I t is o f t e n u s e f u l t o have one or more loops w i t h i n a loop. This t e c h n i q u e i s called n e s t i n g , and i s allowed as long as t h e f i e l d of one loop ( t h e numbered l i n e s from t h e FOR s t a t e m e n t to the corresponding NEXT s t a t e m e n t , i n c l u s i v e ) does n o t cross t h e f i e l d of 4-2 another loop. procedures : The following diagram illustrates acceptable UNACCEPTABLE NESTING TECHNIQUES ACCEPTABLE NESTING TECHNIQUES Two Level Nestin3 (ET FOR NEXT G E T Ec:o*: NEXT Three Level Nestinq FOR FOR FOR NEXT NEXT NEXT NEXT NEXT 4-3 nesting CHAPTER 5 LISTS AND TABLES 5.1 SUBSCRIPTED VARIABLES I n a d d i t i o n t o s i n g l e v a r i a b l e names, O S / 8 I n d u s t r i a l BASIC a c c e p t s another class of v a r i a b l e s called S u b s c r i p t e d V a r i a b l e s . Subscripted the programmer with additional computing variables provide c a p a b i l i t i e s f o r handling l i s t s , tables, matrices, or any set of related variables. Variables are allowed one or t w o s u b s c r i p t s . A s i n g l e l e t t e r or a letter followed by a d i g i t forms t h e name of t h e v a r i a b l e ; t h i s is followed by one o r t w o i n t e g e r s i n p a r e n t h e s e s and s e p a r a t e d by commas, i n d i c a t i n g t h e p l a c e of t h a t v a r i a b l e i n t h e list. U p t o 31 a r r a y s are p o s s i b l e i n any program, s u b j e c t o n l y t o the amount of core space a v a i l a b l e f o r data storage. For example, a l i s t might be described as A ( 1 ) where I goes from 1 t o 5 , as follows: This allows the p r o g r a m e r t o r e f e r e n c e each of t h e f i v e elements i n the l i s t A. A t w o dimensional m a t r i x A ( 1 , J ) can be d e f i n e d i n a similar manner, b u t t h e s u b s c r i p t e d v a r i a b l e A can be used o n l y once (i.e., A ( 1 ) and A ( 1 , J ) cannot be used i n t h e same program). It i s p o s s i b l e , however, t o use t h e same v a r i a b l e name as both a s u b s c r i p t e d and an unsubscripted v a r i a b l e . Both A and A ( 1 ) are v a l i d v a r i a b l e names and can be used i n t h e same program. S u b s c r i p t e d v a r i a b l e s a l l o w data t o be i n p u t q u i c k l y and e a s i l y , as i l l u s t r a t e d i n t h e following program ( t h e index of t h e FOR s t a t e m e n t i n l i n e s 20, 42, and 44 i s used as t h e s u b s c r i p t ) : - 10 REM PROGRAM DEMONSTARTING READING 1 1 REM OF SUBSCRI PTED VARIABLES 15 DIM A < S ) r B ( 2 r 3 ) 18 P R I N T "AC1) WHERE A= 1 TO 5: " 20 FOR 1 = 1 TO 5 25 READ AC1) 30 P R I N T A C 1 ) ; 35 NEXT I 38 P R I N T 39 P R I N T 40 P R I N T " B C I , J ) WHERE I = l TO 2:" 4 1 P R I N T '* A N D J = 1 TO 3:*' 42 FOR 1 = 1 TO 2 43 P R I N T 44 FOR J = l TO 3 48 READ B ( 1 , J ) 50 P R I N T B C I I J ) ~ 55 NEXT J 5 6 NEXT I 68 DATA l a 2,3,4,5, ~ 7 , a 61 DATA 8,7r 6,5r 4, 3 s 2 , l - 65 END 5-1 READY RWNH ACL) WHERE A = l TO 5: 1 2 3 4 s WHERE I = 1 TO 2: BCIJJ) AND 3 = 1 T O 3: 6 7 8 8 7 6 READY 5.2 THE D I M STATEMENT From t h e preceding example, i t can be s e e n t h a t t h e use o f s u b s c r i p t s r e q u i r e s a dimension (DIM) s t a t e m e n t t o d e f i n e t h e maximum number of elements i n t h e a r r a y . The DIM s t a t e m e n t i s o f t h e form: ( l i n e number) D I M v ( n 1 , v (n ,m where v i n d i c a t e s an a r r a y v a r i a b l e name and n and m are i n t e g e r numbers i n d i c a t i n g t h e l a r g e s t s u b s c r i p t v a l u e r e q u i r e d d u r i n g t h e program. For example: 15 D I M A(6,lO) The f i r s t element of e v e r y a r r a y i s a u t o m a t i c a l l y assumed t o have a s u b s c r i p t o f zero. Dimensioning A ( 6 , l Q ) sets up room f o r an a r r a y w i t h 7 rows and 11 columns. T h i s m a t r i x can b e thought of as e x i s t i n g i n t h e following form: A %,% A 6,8 A %,I A 6,l . A %,lP A6,18 and i s i l l u s t r a t e d i n the f o l l o w i n g program: - 1 0 REM MATRIX CHECK PROGRAM 1 5 DIM A ( 6 ~ 1 0 ) 20 FOR 1 = 0 T O 6 22 L E T A C I r 0 ) = 1 25 FOR J = 0 TO f B 5-2 28 LET A < 0 r J ) = J 30 P R I N T ACI*J)J 35 NEXT J 40 PRINT 45 NEXT I 50 END READY RU"H 0 1 1 0 2 0 3 0 4 0 5 0 6 0 2 3 4 5 6 7 8 9 1 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 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 0 0 0 READY Notice that a v a r i a b l e assumes a value of z e r o u n t i l a n o t h e r v a l u e has been assigned. I f t h e u s e r wishes t o conserve core space by n o t making use of t h e e x t r a v a r i a b l e s set up w i t h i n t h e a r r a y , he should set h i s D I M s t a t e m e n t t o one less t h a n n e c e s s a r y , D I M A ( 5 , 9 ) . This results i n a 6 by 1 0 a r r a y which may then be r e f e r e n c e d b e g i n n i n g w i t h t h e A(0,O) element. More t h a n one a r r a y can be d e f i n e d i n a s i n g l e DIM statement: This dimensions both t h e l i s t A and t h e m a t r i x B. t o d e f i n e t h e m a x i m u m s i z e of t h e a r r a y . A v a r i a b l e i n s i d e t h e p a r e n t h e s e s i s n o t a c c e p t a b l e and w i l l r e s u l t i n an error message by BASIC a t compile t i m e . The amount of u s e r core not f i l l e d by t h e program w i l l determine t h e amount o f data t h e computer can a c c e p t as i n p u t t o t h e program a t any one t i m e . I n some programs a TB error ( t o o b i g ) may occur, i n d i c a t i n g t h a t core w i l l n o t hold an a r r a y of t h e s i z e requested. I n t h a t e v e n t , t h e u s e r should change h i s program t o process p a r t of t h e data i n one run and t h e rest A number must be used later. NOTE I f a subscripted variable i s not defined by a D I M s t a t e m e n t , t h e v a r i a b l e i s assigned an a r r a y s i z e of t e n . 5- 3 CHAPTER 6 OS/8 6.1 INDUSTRIAL BASIC FUNCTIONS AND SUBROUTINES GENERAL INFORMATION ON OS/8 I N D U S T R I A L BASIC FUNCTIONS I n d u s t r i a l BASIC provides a number of f u n c t i o n s , as p a r t of t h e language, which perform c a l c u l a t i o n s . The use of t h e s e f u n c t i o n s e l i m i n a t e s t h e need f o r w r i t i n g s m a l l programs t o perform t h e c a l c u l a t i o n s . Functions have a t h r e e l e t t e r c a l l name, followed by an argument, X, which can be a number, v a r i a b l e , e x p r e s s i o n o r a n o t h e r function. Generally, f u n c t i o n s may be used anywhere a number or a v a r i a b l e is l e g a l i n a mathematical expression. OS/8 The following OS/8 chapter. I n d u s t r i a l BASIC f u n c t i o n s are discussed in this Function waning S I N (X) S i n e of X ( X i s expressed i n r a d i a n s ) cos ( X ) Cosine of X ( X i s expressed i n r a d i a n s ) ATN ( X I Arctangent of X ( r e s u l t expressed i n r a d i a n s ) EXP (XI ex (e = 2.718282) LOG(X) N a t u r a l l o g of X (logex) RND(X) Random number ABS ( X ) Absolute v a l u e of INT (XI I n t e g e r value of X SGN ( X I Sign of X positive, negative SQR (XI Square root of FNA ( X ) User-def ined f u n c t i o n TRC ( X ) Trace f u n c t i o n Used f o r I n d u s t r i a l BASIC programs. x (1x1) -0a s si ifg n Xa vi sa l u ez e r oof, +1 i f X is o r -1 i f X is x (fl) - debugging OS/8 I n a d d i t i o n , t h e r e are a number of other f u n c t i o n s provided by OS/8 I n d u s t r i a l BASIC, which i n c l u d e p r i n t i n g f u n c t i o n s , s t r i n g h a n d l i n g f u n c t i o n s , and UDC f u n c t i o n s . These f u n c t i o n s are d e s c r i b e d i n o t h e r p a r t s of t h i s manual as i n d i c a t e d below. PRINTING FUNCTIONS Refer t o Paragraph PNT ( X ) 3.5.4 TAB (XI 3.5.3 6-1 7.2.1 7.2.2 7.2.2 7.2.3 7.2.3 7.2.4 7.2.5 7.2.6 REAL TIME FUNCTIONS 8.3.2 A N I (X,Y) 8.3.3 8.3.4 8.3.5 8.3.6 8.3.7 8.3.8 8.3.1 8.4.1 8.4.2 8.4.3 6.2 6.2.1 ARITHMETIC FUNCTIONS The Random Number Function - RND(XI The RND(X) f u n c t i o n produces pseudo-random numbers between and 1. write the 0 The argument X i s a dummy argument and can be any number. If t h e u s e r wants t h e f i r s t 20 random numbers, he program shown below and get 2 0 s i x - d i g i t decimals. READY 10 FOR L-1 TO 20 20 P R I N T F N D < X ) r 30 NEXT L 40 END 6-2 can RU"H 0.361 572 0.53979 5 0.125244 0.440186 0.3327 64 0.8 479 B* 389 404 0 9 7 09 47 0.633057 0.026123 0.9 748 53 0.28 5889 0.350342 0054126 0.51 6357 0.867432 0. 6701 66 0.934326 0.465088 0. 178467 READY A second RUN g i v e s e x a c t l y t h e same sequence of numbers as RUN; t h i s i s done t o f a c i l i t a t e t h e debugging of programs. RWNH 0.361 572 0.53979 5 0.125244 0.44018 6 0.3327 64 0.8479 0.389 404 0 9 7 09 47 0.633057 0.026123 0.974853 0.28 5889 the 0.350342 0.54126 0.51 6357 0.8 67432 first 0. 6701 66 0.9 3 4 3 2 6 0.465088 0.178467 READY If t h e u s e r wants 20 random o n e - d i g i t i n t e g e r s , h e can change l i n e 20 t o read as follows: 20 P R I N T l N T C 10*RND<X))s RWNH The r e s u l t s w i l l be as follows: 3 8 3 9 3 5 1 4 6 0 9 2 3 6 5 9 5 4 1 8 To v a r y t h e type of random numbers ( 2 0 random numbers r a n g i n g t o 9, i n c l u s i v e ) , t h e u s e r can change l i n e 20 as f o l l o w s : 20 1 PRINT INT (9*RND (X)+1); To o b t a i n random numbers which are i n t e g e r s from 5 t o t h e u s e r can change l i n e 20 t o t h e f o l l o w i n g : 20 from 24, inclusive, PRINT INT(20*FND(X)+5) ; . If random numbers are t o be chosen from the A i n t e g e r s o f which the smallest, the u s e r can c a l l for INT.(A*RND(X)+B) 6-3 B is 6.2.1.1 The RANDOMIZE Statement t h e same numbers i n t h e same o r d e r r e s u l t e d both t i m e s t h e program w a s run. However, a d i f f e r e n t set w i l l be produced w i t h t h e RANDOMIZE s t a t e m e n t , as i n t h e f o l l o w i n g program: As n o t e d i n t h e f i r s t program i n paragraph 6.2.1, 5 RANDOMIZE 10 FOR L= 1 TO 20 20 PRINT I N T < 10*RNDCX) 1; 30 NEXT L 4 0 END READY RU"H 3 3 READY RUNNH 0 1 READY 6 3 6 5 8 0 5 9 1 3 9 5 4 4 9 2 8 1 9 7 9 5 3 9 1 1 4 5 4 6 2 8 9 3 7 6 RANDOMIZE resets t h e numbers based on e l a p s e d t i m e s p e n t w a i t i n g f o r t e r m i n a l I/O. For example, i f RANDOMIZE a p p e a r s a f t e r a P R I N T or INPUT i n s t r u c t i o n b u t b e f o r e a s t a t e m e n t w i t h t h e RND(X) function, I f the t h e n r e p e a t e d RUNS o f t h e program produce d i f f e r e n t r e s u l t s . i n s t r u c t i o n i s a b s e n t , t h e o f f i c i a l l i s t o f random numbers i s o b t a i n e d i n the u s u a l order. It i s suggested t h a t a s i m u l a t e d model should be debugged w i t h o u t t h i s i n s t r u c t i o n so t h a t one always o b t a i n s t h e same random numbers i n t e s t runs. A f t e r t h e program i s debugged, and b e f o r e s t a r t i n g p r o d u c t i o n runs, t h e u s e r i n s e r t s t h e following: ( l i n e number) RANDOMIZE a t t h e a p p r o p r i a t e place i n t h e program. 6.2.2 The Sign Function - SGN(X) The SGN f u n c t i o n i s one which a s s i g n s t h e v a l u e 1 i f t h e argument i s any p o s i t i v e number, 0 i f z e r o , and -1 if any n e g a t i v e number. Thus, SGN(7.23) = 1, S G N ( 0 ) = 0, and SGN(-.2387) = -1. For example, the following statement : 25 LET X=SQR(At2+2*B*C)*SGN(A) a s s i g n s t h e s q u a r e root of t h e s i n e of A t o X. 6-4 6.2.3 The I n t e g e r Function - INT(X) The i n t e g e r f u n c t i o n r e t u r n s t h e v a l u e of t h e nearest i n t e g e r not X. For example, INT(34.67) = 34. By s p e c i f y i n g greater than INT(X+.5) t h e INT f u n c t i o n can be used t o round numbers t o t h e n e a r e s t INT can a l s o be used t o round i n t e g e r : t h u s , INT(34.67+.5) = 35. numbers t o any given decimal p l a c e by s p e c i f y i n g : INT ( X * l O t D+ .5) /10 t D where D i s t h e number o f program i l l u s t r a t e s t h i s t y p i n g a CTRL/C: decimal p l a c e s d e s i r e d . f u n c t i o n ; e x e c u t i o n has The f o l l o w i n g been stopped by - 10 REM I N T FUNCTICN EXAMPLE 20 P R I N T ssNUMBER T O BE R O l h V D E D s s ~ 30 I N P U T A 40 P R I N T "NO. O F DECIMAL PLACES:"s 50 I N P U T D 60 LET B = I N T C A * l 0 t D + . S ) / l 0 t D 7 0 P R I N T "A R O U N D E D =";B 80 G O T O 20 9 0 END READY RUNNH NUMBER TO B E R O U N D E D ? 5 5 . 6 5 3 4 2 NO. O F D E C I M A L P L A C E S : ? 2 A ROUNDED = 55.65 NUMBER T O B E R O U N D E D ? I S . 375 NO. OF D E C I M A L P L A C E S : ? - 2 A ROUNDED = 100 NUMBER T O B E R O U N D E D ? 6 7 . 8 9 NO. O F D E C I M A L P L A C E S : ?- 1 A ROUNDED = 70 NUMBER TO BE R O U N D E D ? t C READY If t h e argument i s a n e g a t i v e number, t h e value returned is t h e l a r g e s t n e g a t i v e i n t e g e r (rounded t o t h e h i g h e r v a l u e ) c o n t a i n e d i n t h e number. For example, INT(-23) = -23 b u t INT(-14.39) = -15. 6.2.4 The Absolute Value Function - ABS(X1 The a b s o l u t e value f u n c t i o n i s used t o o b t a i n t h e a b s o l u t e v a l u e of an expression. For example: READY 5 PRINT ABS<-66) 10 END RWNH 66 6- 5 (positive) 6.2.5 The Square R o o t Function - SQR(X) The s q u a r e root f u n c t i o n is used t o compute expression. For example: the square root of an value of 5 LET B=4\A=2* 5\C=. 5 1 0 P R I N T SQR<B* 2- 4* A* C) 20 END RWNH 3.31 662 READY If t h e argument of the SQR(X) f u n c t i o n is < O , t h e t h e argument i s used, 6.3 6.3.1 absolute TRANSCENDENTAL FUNCTIONS The Sine Function - SIN(X) The s i n e f u n c t i o n is used t o c a l c u l a t e t h e s i n e of an a n g l e i n radians. For example: specified - 5 REM CALCULATE S I N E 30 DEGREES 1 0 LET P = 3 * 1 4 1 5 9 20 P R I N T S I N < 3 0 * P / 1 8 0 ) 25 END RWNH 0.5 READY READY 6.3.2 The The Cosine Function cosine function specified i n radians, - COS(X) is used t o c a l c u l a t e the c o s i n e of F o r example: - 5 REM CALCULATE THE C O S I N E OF 45 DEGREES 1 0 PRINT COS<45*3. 1 4 1 5 9 / 1 8 0 ) 20 END READY RWNH 0.707108 6-6 an angle 6.3.3 The A r c t a n Function - ATN(X) This f u n c t i o n calculates t h e angle ( i n r a d i a n s ) whose t a n g e n t is given as t h e argument of t h e f u n c t i o n . For example: - READY 5 REM CALCULATE ATNC.57735) 10 PRINT ATN(057735) 2 0 END RUNNH 0.523598 6.3.4 The Exponential Function - EXP(X) The E X P ( X ) f u n c t i o n calculates t h e v a l u e of e r a i s e d t o t h e For example: where e i s e q u a l t o 2.71828. 5 REM power, X - CALCULATE EXPONWTIAL VALUE OF 1.5 10 PRINT EXP( 1.5) 20 END READY RWNH 4-48 168 6.3.5 The Natural Logarithm Function The LOG(X) f u n c t i o n example : calculates the - - LOG(X) natural 5 REM CALCULATE THE L O G OF 9 5 9 10 PRINT L O G ( 9 5 9 ) 20 END RUNNH 6.8 6589 READY 6-7 logarithm of X. For 6.4 USER DEFINED FUNCTIONS 6.4.1 The FNA(X) Function and t h e DEF Statement I n a d d i t i o n t o t h e s t a n d a r d f u n c t i o n s OS/8 I n d u s t r i a l BASIC p r o v i d e s , t h e u s e r may d e f i n e up t o 26 f u n c t i o n s of h i s own w i t h t h e DEF statement. The name of t h e d e f i n e d f u n c t i o n must be t h r e e l e t t e r s , the f i r s t two of which are F N , i.e., FNA, FNB,...,FNZ. Each DEF s t a t e m e n t i n t r o d u c e s a s i n g l e f u n c t i o n and i s of t h e form: ( l i n e number) DEF FNA(X) =expression (X) where A may be any l e t t e r and X is a dummy v a r i a b l e , b u t must be t h e same on each side of t h e e q u a l s i g n . The DEF s t a t e m e n t may appear anywhere i n t h e program so long as it a p p e a r s b e f o r e . t h e f i r s t use o f t h e f u n c t i o n it d e f i n e s . The f u n c t i o n i t s e l f can be d e f i n e d i n terms of numbers, s e v e r a l variables, o t h e r f u n c t i o n s , or mathematical exp e s s i o n s . For example, i f t h e u s e r r e p e a t e d l y u s e s t h e f u n c t i o n e-' 5 +5, h e can i n t r o d u c e t h e f u n c t i o n by t h e following: 30 DEF FNE ( X ) =EXP (-Xt2) +5 , and c a l l f o r v a r i o u s v a l u e s of t h e f u n c t i o n by FNE( .1), FNE(3.45) etc. T h i s s t a t e m e n t s a v e s a great d e a l of t i m e when t h e u s e r needs v a l u e s of t h e f u n c t i o n f o r a number o f d i f f e r e n t v a l u e s o f the variable. FNE(A+2), The s t a t e m e n t : DEF FNA(S) = S t 2 w i l l cause t h e later statement: 20 LET F+FNA(4)+1 t o be e v a l u a t e d as -17. The user-defined as shown below: 25 f u n c t i o n can be a f u n c t i o n o f more t h a n one v a r i a b l e , DEF FNL (X,Y ,2 ) =SQR(X a + Y t 2+Z+ 2 ) later s t a t e m e n t i n a program c o n t a i n i n g appear as follows: A 55 the above function might LET B=FNL(D,L,R) where D , L, and R have been d e f i n e d i n t h e program. 6.4.2 The UDEF Function C a l l and t h e USE Statement OS/8 I n d u s t r i a l BASIC h a s t h e c a p a b i l i t y f o r adding one or more user-coded assembly language f u n c t i o n s . The u s e r f u n c t i o n s may u s e f o u r numeric and t w o s t r i n g arguments, and once p r o p e r l y i n t e r f a c e d t o OS/8 I n d u s t r i a l BASIC, t h e y can b e used as any o t h e r OS/8 I n d u s t r i a l BASIC f u n c t i o n . Complete i n s t r u c t i o n s f o r w r i t i n g and i n t e r f a c i n g 6-8 such f u n c t i o n s are provided i n Chapter 11 o f t h i s manual. A user-coded f u n c t i o n , i f p r e s e n t , i s s p e c i f i e d i n an OS/8 I n d u s t r i a l BASIC program as: ( l i n e number) UDEF f u n c t i o n name (argument) For example: 10 15 20 25 30 35 40 LET R=4 LET B=6 LET e 1 0 UDEF PLT(X,Y,Z) LET DrPLT(R,B,O) PRINT 4*D END Line 25 i n t r o d u c e s t h e f u n c t i o n PLT t o OS/8 I n d u s t r i a l BASIC and i n d i c a t e s t h e number and t y p e of arguments a s s o c i a t e d w i t h t h e function. I n l i n e 30 t h e f u n c t i o n i s used as any o t h e r s t a n d a r d I f the f u n c t i o n might be used i n an OS/8 I n d u s t r i a l BASIC program. f u n c t i o n r e q u i r e s t h e use of an a r r a y , a USE s t a t e m e n t i d e n t i f y i n g t h e a r r a y must precede t h e s t a t e m e n t t h a t c a l l s t h e f u n c t i o n . .. 10 D I M S(15,5) 20 22 LET Q=10 USE S UDEF PLT(X,Y,Z) 25 NOTE A UDEF f u n c t i o n name may c o n s i s t o f a l p h a b e t i c characters only and must have a t l e a s t one argument ( a dummy argument i f n e c e s s a r y ) . 6.5 THE DEBUGGING FUNCTION - TRC(X) The TRC(X) f u n c t i o n i s used by t h e programmer t o follow t h e p r o g r e s s of a program and i s , t h e r e f o r e , a u s e f u l debugging aid. The form of t h i s f u n c t i o n is: ( l i n e number) vl=TRC ( X ) where v l i s a dummy v a r i a b l e , X = l t u r n s t h e f u n c t i o n on and X=O t u r n s the function off. When T R C ( 1 ) i s encountered i n a program, OS/8 I n d u s t r i a l BASIC p r i n t s t h e l i n e number of each l i n e i n t h e program as it is executed. The l i n e numbers are p r i n t e d between a p a i r of p e r c e n t s i g n s so as t o be d i s t i n g u i s h a b l e from o t h e r material t h a t i s p r i n t e d by t h e program. Program e x e c u t i o n t i m e i s slowed down considerably t o accommodate the function and the e x t r a p r i n t i n g it causes. When TRC(0) i s encountered by t h e program t h e f u n c t i o n i s turned o f f and normal program o p e r a t i o n resumes. 6-9 The f o l l o w i n g example shows t h e effect of using t h e TRC(X) f u n c t i o n i n a program t o check the operation of a loop. The same program with t h e TRC(X) f u n c t i o n removed from t h e program, i s also shown. 5 REM - BASIC 6 REM FACTORIAL PROGRAM 10 FOR J=1 TO 5 20 GOSUB 60 30 NEXT J 40 STOP 60 L E T S=1 62 T=TRC< 1) 65 FOR K = l TO J 70 LET S=S*K 75 NEXT K 77 T = T R C < 0 ) 80 PRINT JIS 8 5 RETURN 9 0 GiD - RUVNH X 65 X X 70 X X 77 x 1 2 2 2 3 4 5 READY X 65 X X 70 X % 70 X X 70 X x 77 x 6 3 READY RU"H 1 1 X 65 X X 70 % X 70 X x 77 x X 65 X 70 X 70 X 70 X 70 2 77 4 X 65 X 70 X 70 X 70 X 70 X 70 X 77 5 -- 5 HEM BASIC 6 REM FACTORIAL PROGRAM 10 FOR J = l T O 5 20 GOSU6 60 30 NEXT J 40 STOP 60 L E T S= 1 65 FOR K = l TO J 70 L E T S=S*K 7 5 NEXT K 88 PRINT JIS 8 5 RETURN 9 0 END % X X 2 X x 24 X X X X X X X 120 6-10 1 2 6 24 120 NOTE OS/8 I n d u s t r i a l BASIC idles on i n p u t Therefore, a trace should statements. n o t be on when i n p u t i s requested. 6.6 SUBROUTINES i s a p a r t of t h e program performing some o p e r a t i o n t h a t i s r e q u i r e d a t more than one p o i n t i n t h e program. Subroutines are g e n e r a l l y placed p h y s i c a l l y a t t h e end of a program, u s u a l l y b e f o r e DATA s t a t e m e n t s , i f any, and always before t h e END statement. A subroutine 6.6.1 GOSUB and RETURN Two s t a t e m e n t s are used e x c l u s i v e l y i n OS/8 I n d u s t r i a l BASIC t o handle s u b r o u t i n e ; t h e s e are t h e GOSUB and RETURN s t a t e m e n t s . When a program encounters a GOSUB s t a t e m e n t o f t h e form: ( l i n e number) GOSUB x where x r e p r e s e n t s t h e f i r s t l i n e number of then t r a n s f e r s t o t h a t l i n e . For example: ... 50 the subroutine, control GOSUB 200 When program e x e c u t i o n reaches l i n e 5 0 , c o n t r o l t r a n s f e r s t o l i n e 200: the s u b r o u t i n e i s processed u n t i l e x e c u t i o n e n c o u n t e r s a RETURN s t a t e m e n t of the form: ( l i n e number) RETURN which causes c o n t r o l t o r e t u r n t o t h e s t a t e m e n t following t h e GOSUB statement. Before t r a n s f e r r i n g t o t h e s u b r o u t i n e , OS/8 I n d u s t r i a l BASIC i n t e r n a l l y r e c o r d s t h e n e x t s t a t e m e n t t o be processed a f t e r t h e GOSUB statement: t h u s t h e RETURN s t a t e m e n t i s a s i g n a l t o t r a n s f e r c o n t r o l t o t h i s statement. I n t h i s way, no matter how many d i f f e r e n t s u b r o u t i n e s are called, or how many times t h e y are used, OS/8 I n d u s t r i a l BASIC always knows where t o go next. The f o l l o w i n g program demonstrates a s i m p l e s u b r o u t i n e : - 1 REM T H I S PROGRAW I L L U S T R A T E S GOSUB AND RETURV 10 DEF F N A C X ) = A B S C I N T C X ) ) 20 I N P U T A I B ~ C 30 GOSUB 100 4 8 L E T A-FMACA) 50 L E T B=FNACB) 60 LET C-FNACC) 6-11 70 PRINT 8 0 GOSUB 1 0 0 9 0 STOP 1 0 0 REM T H I S SUBROUTINE P R I N T S OUT THE S O L U T I O N S 1 1 0 REM OF THE EQUATION A < X t 2 ) + B < X ) + C = 0 1 2 0 P R I N T "THE EQUATI ON I S'r A3 s s * X t 2 + * 1 rB; ***%+"3 C 1 3 0 L E T D=B*B-4*A*C 1 4 0 I F D<,0 THEN 1 7 0 1 5 0 P R I N T "ONLY ONE SOLUTION. *.X=";-B/<2*A) 1 6 0 RETUW 170 I F D c 0 THEN 200 1 8 0 P R I N T "TWO SOLUTI ONS. * X = ' * i 18 5 P R I N T (-B+SQR<D) 1 /( 2*A) ;"AND X= "3 ( 9- SQR< D) > / < 2 * A ) 1 9 0 RETURN 200 P R I N T "IMAGINARY SOLUTI WS. . X = ( " i 205 P R I N T - B / < 2 * A ) 3 " r " i SBR<-D)/(2*A);") AND ("3 I' 207 PRI N T -B/( 2 * A ) 3 " J "3 - S Q R ( -D) /( 2*A) 3 ''> 2 1 0 RETURrV 900 END -- - READY RUNNH ?1,. 5,-0 5 THE EQUATION I S 1 * X ? 2 + 0.5 * X + - 0 . 5 TWO S O L U T I O N S . . * X = 0 . 5 AiiD X = - 1 THE EQUATIOV I S 1 * X t 2 + 0 *X+ IMAGINARY S O L U T I O N S * * * X = < 0 J 1 1 1 AND < 0 J-1 ) Line 100 b e g i n s t h e s u b r o u t i n e . There are s e v e r a l p l a c e s i n which c o n t r o l may r e t u r n t o t h e main program, depending upon a c e r t a i n condition being s a t i s f i e d . The s u b r o u t i n e i s executed from l i n e 30 and a g a i n from l i n e 80. When c o n t r o l r e t u r n s t o l i n e 9 0 , t h e program e n c o u n t e r s t h e STOP s t a t e m e n t and e x e c u t i o n i s terminated. I t i s important t o remember t h a t s u b r o u t i n e s should g e n e r a l l y be k e p t The l a s t s t a t e m e n t i n t h e main d i s t i n c t from the main program. program should be a STOP o r GOT0 s t a t e m e n t , and s u b r o u t i n e s are normally placed f o l l o w i n g t h i s s t a t e m e n t , More t h a n one s u b r o u t i n e may be used i n a s i n g l e program i n which case t h e s e can be p l a c e d one a f t e r a n o t h e r a t t h e end o f t h e program ( i n l i n e number sequence). A u s e f u l p r a c t i c e i s t o a s s i g n d i s t i n c t i v e For example, i f t h e main program i s l i n e numbers t o s u b r o u t i n e s . numbered w i t h l i n e numbers up t o 1998 200 and 300 could be used as t h e f i r s t numbers of two s u b r o u t i n e s . 6.6.2 N e s t i n g Subroutines N e s t i n g of s u b r o u t i n e s o c c u r s when one s u b r o u t i n e c a l l s a n o t h e r subroutine. I f a RETURN s t a t e m e n t i s encountered d u r i n g e x e c u t i o n of a s u b r o u t i n e , c o n t r o l r e t u r n s t o t h e s t a t e m e n t f o l l o w i n g t h e GOSUB which called it. From t h i s p o i n t , it i s possible t o t r a n s f e r t o t h e b e g i n n i n g or any p a r t of a s u b r o u t i n e , even back t o t h e c a l l i n g 6-12 L ubroutine. Multiple entry b r o u t i n e s more v e r s a t i l e . points and RETURN statements make The m a x i m u m l e v e l of GOSUB n e s t i n g i s t e n l e v e l s , which should prove more than adequate f o r a l l normal uses. Exceeding t h i s l i m i t r e s u l t s i n t h e message: GS AT LINE YYYYY where YYYYY r e p r e s e n t s t h e l i n e number where t h e error occurred. An example of GOSUB n e s t i n g follows (execution has been stopped by t y p i n g a CTRL/C, as the program would o t h e r w i s e c o n t i n u e i n an i n f i n i t e loop) 0 - 10 REM FACTORIAL P R O G R W U S I N G GOSUB T O 15 RE# RECURSIVELY COMPUTE T 4 E S E FACTORS 40 I N P U T N 50 1 F N>20 THEN 120 60 X = l 70 K=l 80 GOSUB 200 9 0 P R I N T "FACTORI AL ";N; *'='*; X 110 GO T O 40 120 P R I N T "MUST BE 20 OR LESS" 130 GO T O 40 200 X = X * K 210 K = K + 1 220 I F K<=M THEN 200 230 RETURN 240 END - READY RUNNH ?2 FACTORIAL 2 2 ?4 FACTORIAL 4 = 24 ?S FACTORIAL 5 120 ?21 MUST BE 20 OR L E S S ?6 FACTORI AL 6 = 720 ?f c READY 6-13 CHAPTER 7 ALPHANUMERIC INFORMATION (STRINGS) I n p r e v i o u s c h a p t e r s w e have dealt o n l y w i t h numerical information. OS/8 I n d u s t r i a l BASIC also p r o c e s s e s , o r manipulates, However, alphanumeric information called s t r i n g s . A s t r i n g i s a sequence of characters, each of which i s a l e t t e r , a d i g i t , a space, or some c h a r a c t e r o t h e r than a s t a t e m e n t t e r m i n a t o r ( b a c k s l a s h or c a r r i a g e return) . 7.1 7.1.1 STRING CONVENTIONS Constants and Variables S t r i n g s may appear as c o n s t a n t s or v a r i a b l e s j u s t as numerics may. we have a l r e a d y used s t r i n g c o n s t a n t s i n PRINT s t a t e m e n t s . For example: 100 PRINT "THIS IS A STRING CONSTANT" where the alphanumerics enclosed i n q u o t e s are t h e s t r i n g c o n s t a n t . It Naming a s t r i n g v a r i a b l e is similar t o naming a numeric v a r i a b l e . c o n s i s t s of a l e t t e r followed by a d o l l a r s i g n ($1 or a l e t t e r and a s i n g l e d i g i t followed by $. A$ and Al$ are b o t h l e g i t i m a t e s t r i n g v a r i a b l e names; 2AS and AAS are n o t legitimate s t r i n g variable names. 7.1.2 Dimensioning S t r i n g s OS/8 I n d u s t r i a l BASIC assumes t h a t a s t r i n g l e n g t h i s 8 c h a r a c t e r s less u n l e s s a s t r i n g has been dimensioned i n t h e form: 10 or D I M A$ (I) where I is the l e n g t h of s t r i n g v a r i a b l e AS. I cannot exceed 72. S t r i n g lists ( e q u i v a l e n t t o s i n g l e s u b s c r i p t e d numeric v a r i a b l e s ) are permitted i n OS/8 I n d u s t r i a l BASIC and must be dimensioned i n t h e form: 20 D I M A$(K,L) where K is t h e number of s t r i n g s i n t h e l i s t and L i s each s t r i n g . the When r e f e r e n c i n g a s u b s c r i p t e d s t r i n g v a r i a b l e i n s t a t e m e n t , f o r example : LET 25 a length or of IF-THEN LET B$(I) = "YES" the e x p r e s s i o n I r e p r e s e n t s t h e place of t h a t s t r i n g v a r i a b l e l i s t BS. 7-1 in the Double s u b s c r i p t e d s t r i n g v a r i a b l e s ( s t r i n g tables) are n o t i n O S / 8 I n d u s t r i a l BASIC. 7.1.3 permitted I n p u t t i n g S t r i n g Data S t r i n g d a t a may be i n c l u d e d i n a DATA l i s t b u t must always be e n c l o s e d by q u o t a t i o n marks. I n f a c t , any s t r i n g w r i t t e n i n t o a program must be e n c l o s e d by q u o t a t i o n marks t o be recognized by t h e OS/8 I n d u s t r i a l BASIC Compiler. 10 20 25 30 FtEAD A$,B$,C$ PRINT C$;B$:A$ DATA "NG" " R I " ,"ST" END , The program above p r i n t s STRING. Quotation marks may be i n c l u d e d i n s t r i n g s by i n d i c a t i n g t w o q u o t a t i o n marks i n succession. For example t h e s t r i n g A"B would appear i n a program as: 10 LET A$ = "A""B" Both s t r i n g data and numeric data may be i n t e r m i x e d i n a DATA l i s t b u t t h e burden f a l l s on t h e programmer t o assemble t h e l i s t i n t h e correct sequence, s i n c e a l l READ s t a t e m e n t s f o r both s t r i n g and numeric data remove d a t a s e r i a l l y from t h e DATA l i s t . I f h e does n o t , t h e r e s u l t s of t h e READ s t a t e m e n t are u n p r e d i c t a b l e . The INPUT s t a t e m e n t may a l s o be used f o r i n p u t t i n g s t r i n g data t o a program. Q u o t a t i o n marks are n o t n e c e s s a r y when i n p u t t i n g s t r i n g data i n response t o t h e q u e s t i o n mark ( ? ) g e n e r a t e d by t h e I N P U T s t a t e m e n t u n l e s s t h e q u o t a t i o n marks are d e l i b e r a t e l y meant t o be p a r t of the string. .. 330 340 350 360 370 380 390 400 410 . PRINT "DO YOU W I S H TO CONTINUE?" INPUT A$ I F A$="YES" THEN 410 PRINT "ARE YOb SURE?" INPUT B$ I F B$="NO" THEN 410 PRINT "PROGRAM STOPPED" STOP PRINT "LET'S CONTINUE" . . 490 END Each s t r i n g l i t e r a l r e q u e s t e d by an INPUT s t a t e m e n t must be t e r m i n a t e d by a c a r r i a g e r e t u r n or comma which acts as t h e data delimiter. T h i s i s n e c e s s a r y s i n c e a l l c h a r a c t e r s , e x c e p t f o r t h e carriage r e t u r n o r comma, are recognized as p a r t of t h e d a t a s t r i n g . 7-2 READY ... I N P U T A$,B$,C$ 10 RU"H ?ABCD ?EFGH ?IJ I n t h e above example A$="ABCD", B$="EFGH" and C$="IF". 7.1.4 S t r i n g s i n LET and IF-THEN Statements S t r i n g s may be used i n both LET and IF-THEN s t a t e m e n t s as a l r e a d y i n d i c a t e d by some of t h e previous examples. Any o f t h e r e l a t i o n a l may be used i n an IF-THEN o p e r a t o r s d e c r i b e d i n paragraph 2.3.3 s t a t e m e n t t o compare s t r i n g s . S t r i n g s are compared on t h e b a s i s of t h e A S C I I numeric value of each c h a r a c t e r i n t h e s t r i n g (see Appendix D f o r numeric v a l u e s of A S C I I c h a r a c t e r s ) . When comparing s t r i n g s i n an IF-THEN statement, operators have t h e following s i g n i f i c a n c e : the relational Operator Meaning < e a r l i e r i n A S C I I numeric order than > l a t e r i n A S C I I numeric order t h a n =< 01: <= same A S C I I numeric order A S C I I numeric o r d e r t h a n - same A S C I I numeric order as or earlier in >< or <> d i f f e r e n t A S C I I numeric order from => 01: >= same A S C I I numeric order as or l a t e r i n A S C I I numeric order than For example: 10 . 20 . 50 I F "ABCD"<"ABC@" STOP THEN 50 LET A$="ABCD" Each c h a r a c t e r i n s t r i n g ABCD i s compared, l e f t - t o - r i g h t , w i t h the A, B, and C match b u t D and @ do From Appendix D, t h e c h a r a c t e r @ h a s a lower numeric v a l u e t h a n respective c h a r a c t e r i n s t r i n g AB@. not. 7- 3 t h e character D. Therefore t h e s t r i n g ABCD i s n o t e a r l i e r i n A S C I I numeric sequence t h a n ABC@ and the program s t o p s a t l i n e 20. I f t h e s t r i n g s i n an IF-THEN comparison are o f unequal l e n g t h , t h e n I n d u s t r i a l BASIC l e n g t h e n s t h e shorter s t r i n g t o make it e q u a l i n l e n g t h t o the l o n g e r s t r i n g by appending an a p p r o p r i a t e number o f A S C I I space c h a r a c t e r s . I n t h e f o l l o w i n g example OS/8 10 20 I F "ABCD"6"AB" STOP 50 LET A$="ABCD" . THEN 50 s t r i n g "AB" i s treated as "ABuu". Since t h e c h a r a c t e r C i n A S C I I numeric order t h a n t h e character "space", s t a t e m e n t i s t r u e and c o n t r o l i s t r a n s f e r r e d t o l i n e 50. 7.1.5 i s earlier t h e IF-THEN S t r i n g Concatenation S t r i n g s can be concatenated by means of t h e operator ampersand ( & ) . The ampersand can be used t o c o n c a t e n a t e s t r i n g e x p r e s s i o n s wherever a s t r i n g e x p r e s s i o n is legal, w i t h t h e e x c e p t i o n t h a t i n f o r m a t i o n cannot be stored by means of a LET s t a t e m e n t i n concatenated s t r i n g variables. That i s , concatenated s t r i n g v a r i a b l e s cannot appear t o t h e l e f t of the e q u a l s i g n i n a LET s t a t e m e n t . For example, LET A$=B$&C$ i s l e g a l , b u t U T A$&B$=C$ is not. An example of s t r i n g c o n c a t e n a t i o n is: 10 20 25 30 READ A$,B$,C$ PRINT C$&B$&A$ DATA "NG","RI","ST" END Running t h i s program (a m o d i f i c a t i o n 7.1.3) c a u s e s S T R I N G t o be p r i n t e d . . 7 2 of the program in paragraph STRING HANDLING FUNCTIONS of f u n c t i o n s have been implemented t h a t perform manipulations on s t r i n g s . These f u n c t i o n s are LEN, ASC, CHR$, VAL, STR$, Pas, SEG$, and DAT$. Functions t h a t r e t u r n s t r i n g s have names t h a t end i n a dollar s i g n ( $ 1 ; those f u n c t i o n s t h a t r e t u r n numbers have names t h a t do n o t end i n a d o l l a r sign. A number 7.2.1 The LEN Function The LEN f u n c t i o n r e t u r n s t h e number of characters i n a s t r i n g . t h e form: 7- 4 I t has Example : 5 DIM B$( 10) 10 READ A B s B S 20 P R I N T LEN( A$&B$&"AROUND") 38 DATA "UPS DOWNS AND " 48 END READY RWNH 20 READY 7.2.2 The ASC and CHR$ Functions The ASC and CHR$ f u n c t i o n s perform conversion from and t o A S C I I , respectively. T h e ASC f u n c t i o n c o n v e r t s a one-character s t r i n g t o i t s A S C I I decimal e q u i v a l e n t , and t h e CHR$ f u n c t i o n c o n v e r t s a decimal number t o i t s e q u i v a l e n t A S C I I character. The ASC f u n c t i o n has t h e form: ASC (argument) The argument i s a one c h a r a c t e r s t r i n g . ASC returns the equivalent A S C I I decimal number for t h e character. T h e CHR$ f u n c t i o n has t h e form: CHR$ (numeric e x p r e s s i o n ) The value of t h e numeric e x p r e s s i o n i s t r u n c a t e d t o an i n t e g e r t h a t i s i n the range 0 t o 63. I n t e g e r s greater t h a n 63 are treated modulo 6 4 . That i s , they are d i v i d e d by 64 and t h e remainder- becomes t h e new integer. This i n t e g e r i s then i n t e r p r e t e d as an A S C I I decimal number t h a t i s converted t o i t s e q u i v a l e n t c h a r a c t e r ( r e f e r t o Appendix D f o r t h e A S C I I decimal numbers and t h e e q u i v a l e n t c h a r a c t e r s ) . An example of t h e ASC and CHR$ f u n c t i o n s follows: 5 FOR T=ASC ("A") TO ASC ("A") +3 7 NEXTT 1 0 P R I N T "THIS I S TEST "&CHR$(T) T h i s i s t h e beginning of a FOR loop t h a t s u c c e s s i v e l y p r i n t s : THIS IS TEST A . THIS I S TEST B T H I S I S TEST C h 7-5 ' . THIS IS TEST D 7.2 . 3 The VAL and STR$ Functions The VAL and STR$ f u n c t i o n s perform conversions from s t r i n g s t o numbers and numbers t o s t r i n g s . The form o f t h e VAL f u n c t i o n is: VAL ( s t r i n g e x p r e s s i o n ) The s t r i n g e x p r e s s i o n must look l i k e any number which may be l e g a l l y typed i n response t o an INPUT s t a t e m e n t . VAL r e t u r n s t h e a c t u a l number t h a t the s t r i n g r e p r e s e n t s . The VAL f u n c t i o n does n o t r e t u r n the ASCII value of the number t h a t t h e s t r i n g r e p r e s e n t s , i t r e t u r n s The 25 t h e number. For example, VAL ( “ 2 5 ” ) r e t u r n s t h e number 25. t h a t i s t h e argument t o VAL i s a s t r i n g , t h e 25 t h a t VAL r e t u r n s i s a number . Example : READY 10 INPUT A$ 20 PRINT VAL(A$) *2 100 END ... RUNNH ?2 4 6 1 1 1 4.92222 READY The STR$ f u n c t i o n r e t u r n s t h e s t r i n g r e p r e s e n t a t i o n (as a i t s argument. The form o f STR$ is: number) of STR$ (numeric e x p r e s s i o n ) The s t r i n q t h a t i s r e t u r n e d is i n t h e form i n which numbers are o u t p u t i n BASIC; For example, PRINT STRS(1.76111124) p r i n t s t h e s t r i n g 1.76111. 7.2.4 The POS Function The PoS f u n c t i o n i s of t h e form: POS(XS,Y$,Z) The f u n c t i o n r e t u r n s t h e l o c a t i o n i n s t r i n g XS of t h e f i r s t o c c u r r e n c e of s t r i n g Y$ s t a r t i n g w i t h Zth c h a r a c t e r i n s t r i n g X$. For example: 7-6 20 25 LET X$="MONDAY" LET X=POS (X$ ,"DAY" ,1) A f t e r l i n e 25, X w i l l be e q u a l t o 4 . The arguments f u n c t i o n may be c o n s t a n t s , variables, o r expressions. of the POS The following r u l e s apply i n e v a l u a t i n g t h e POS(X$,Y$,Z) f u n c t i o n . 1. I f Y$ i s a n u l l s t r i n g (no c h a r a c t e r s ) then POS(X$,Y$,Z)=l 2. I f X$ i s a n u l l s t r i n g (no c h a r a c t e r s ) t h e n POS ( X$ ,Y $ ,2) =o 3. I f Z < O , a f a t a l error (PA) i s d e t e c t e d and program e x e c u t i o n stops I f Y$ is n o t found, then 4. , POS (XS ,Y$ 2) =o THE SEG$ Function 7.2.5 This f u n c t i o n i s o f t h e form: SEG$(X$,Y,Z) The f u n c t i o n r e t u r n s t h e s u b s t r i n g o f X$ which i s between p o s i t i o n s and 2 i n c l u s i v e l y . For example: 20 25 30 Y LET X$="MONDAY" LET B=6 LET A$=SEG$ (X$ ,2*B/3 , B ) A f t e r l i n e 30, A$ i s e q u a l t o "DAY". The arguments f u n c t i o n may be variables, c o n s t a n t s , or expressions. of the SEG$ The following r u l e s apply i n e v a l u a t i n g t h e SEG$(X$,Y,Z) f u n c t i o n . 7.2.6 1. I f Y < O , Y is set e q u a l t o 1 2. I f Y> l e n g t h characters) 3. I f Z,O, 4. I f 2 > l e n g t h X$, then 2 i s set e q u a l t o l e n g t h o f X$ 5. I f Z,Y, X$, then SEG$(X$,Y,Z) = n u l l string then SEG$(X$,Y,Z)= n u l l s t r i n g t h e n SEG$(X$,Y,Z) = n u l l s t r i n g The DAT$ Function The DAT$ f u n c t i o n is o f t h e form: DAT$ ( X I 7-7 (no The f u n c t i o n r e t u r n s an e i g h t c h a r a c t e r s t r i n g g i v i n g the c u r r e n t date i n t h e form MM/DD/YY, For example: SCRATCH READY 20 30 PRINT DATS(X) END RU”H 7/ 1/73 The use of DAT$ f u n c t i o n assumes the u s e r has specified t h e date i n monitor command “DATE”. I f t h e DATE command w a s n o t used, t h e OS/8 the DAT$ f u n c t i o n o u t p u t s a n u l l s t r i n g (no c h a r a c t e r s ) . If t h e I n d u s t r i a l BASIC clock i s s e t , and t h e n exceeds One day, t h e n e x t c a l l to t h e DAT$ f u n c t i o n w i l l r e t u r n t h e n e x t day and update t h e OS/8 date, 7- 8 CHAPTER 8 REAL TIME OPERATIONS 8.1 GENERAL DESCRIPTION This c h a p t e r c o n t a i n s t h e s t a t e m e n t s and f u n c t i o n s which g i v e t h e u s e r t h e f a c i l i t y t o s u p p o r t asynchronous o p e r a t i o n , and c o n t r o l and monitor e x t e r n a l devices. The following BASIC Statements are used t o with e x t e r n a l events : TIMER COUNTER CONTACT DISMISS associate BASIC routines -t i m ecbased oper a t i o n s ounter operations -UDC -UDC c o n t a c t o p e r a t i o n s -termination of s e r v i c e routines These s t a t e m e n t s are e x p l a i n e d i n d e t a i l l a t e r i n t h i s c h a p t e r . The following f u n c t i o n c a l l s are used t o access, synchronously, Real Time d e v i c e s : AN0 -Analog I n p u t -Analog Output RDI RDO -Read d i g i t a l i n p u t -Read d i g i t a l o u t p u t SDO -Send d i g i t a l o u t p u t -Set counter -Read c o u n t e r -Set or read clock -Information r e g a r d i n g asynchronous o p e r a t i o n s ANI CN1 CNO CLK CNT LNE STA . These f u n c t i o n c a l l s are chapter 8.2 8.2.1 also explained in detail later in this REAL TIME BASIC STATEMENTS TIMER TIMER V THEN X where X i s the l i n e number of t h e f i r s t s t a t e m e n t of the U s e r Process I n t e r r u p t Service Routine ( U P I R ) , and V i s t h e t i m e i n t e r v a l i n seconds. When the t i m e i n t e r v a l has e l a p s e d the u s e r service r o u t i n e i s scheduled for e x e c u t i o n and t h e t i m e r i s restarted. Time i n t e r v a l s of less than .1 second may have s i g n i f i c a n t i n a c c u r a c i e s i n timing. Time i n t e r v a l s which are z e r o o r n e g a t i v e d e a c t i v a t e a l l the t i m e r s associated w i t h the specified l i n e number. This a l l o w s the user t o change t h e elapsed t i m e i n t e r v a l s o r s t o p t h e t i m e r s e n t i r e l y . A maximum of 4 timers may be a c t i v e a t any t i m e . 8-1 Examples of TIMER S t a t e m e n t s : 200 TIMER 10 THEN 400 Every 1 0 seconds, t h e UPIR b e g i n n i n g a t l i n e 400 w i l l b e executed. L) 300 TIMER 0 THEN 400 T h i s s t a t e m e n t w i l l cause a l l timers a s s o c i a t e d w i t h l i n e 4 0 0 U P I R t o be d e a c t i v a t e d . of the 1 0 0 TIMER 7 THEN 400 110 TIMER 3 THEN 400 These statements cause 2 t i m e r s t o start: a 7-second t i m e r t h a t w i l l cause t h e U P I R a t l i n e 400 t o b e s c h e d u l e d f o r execution every 7 seconds, and a 3-second t i m e r t h a t w i l l cause t h e U P I R a t l i n e 400 t o b e scheduled f o r e x e c u t i o n e v e r y 3 seconds. N o t e t h a t a t 21-second i n t e r v a l s t h e U P I R w i l l b e scheduled t w i c e . The f o l l o w i n g i s an example of a t i m e based o p e r a t i o n : 10 20 25 30 400 4 10 500 510 600 TIMER 1 0 THEN 400 TIMER 15 THEN 500 LET Y = 0 GOT0 25 PRINT "SEGMENT 400" DISMISS PRINT "SEGMENT 500" DISMISS END t h i s example w i l l p r i n t "SEGMENT 400" e v e r y 1 0 seconds, 500" every 15 seconds u n t i l t e r m i n a t e d w i t h a CTRL/C. 8.2.2 and "SEGMENT COUNTER COUNTER V THEN X where X i s t h e l i n e number of t h e f i r s t s t a t e m e n t o f t h e U P I R and V i s t h e c o u n t e r module t o a s s o c i a t e w i t h t h e given l i n e number. There i s a maximum of 4 c o u n t e r modules supported. As w i t h t i m e r s , when t h e c o u n t e r number i s zero o r n e g a t i v e a l l c o u n t e r s a s s o c i a t e d w i t h t h e l i n e number are d i s a b l e d . Counter modules s h o u l d b e loaded v i a t h e CNO f u n c t i o n f o r c o u n t i n g a d d i t i o n a l information on Counter Modules refer t o UNIVERSAL D I G I T A L CONTROL SUBSYSTEM MAINTENANCE MANUAL, operations, For t h e UDC8 DEC-0 8-HZDC-D. Example of a C o u n t e r Statement: 200 COUNTER 1 THEN 1000 When Counter 1 c o u n t s t o z e r o t h e U P I R a t l i n e 1 0 0 0 w i l l be scheduled. 8-2 The f o l l o w i n g i s an example of a program t o l o a d a c o u n t e r number of i t e m s t o count and l o g t h e completion of t h e count: 10 20 25 30 35 100 8.2.3 with a COUNTER 1 THEN 100 REM NOW LOAD COUNTER LET A = CN0(1,100) LETA-0 GOT0 30 PRINT "COUNT CYCLE COMPLETE" 110 DISMISS 200 END CONTACT CONTACT V THEN X where X is t h e l i n e number a s s o c i a t e d w i t h t h e s p e c i f i e d CONTACT. The value V i s t h e CONTACT number. The maximum number of CONTACTS i s 36, i n t h e range 1 t o 36. I f zero is s p e c i f i e d as a CONTACT number a l l active CONTACT u s e r i n t e r r u p t service r o u t i n e s a s s o c i a t e d w i t h t h e l i n e number i n t h e CONTACT s t a t e m e n t are d e a c t i v a t e d . Example of a CONTACT s t a t e m e n t : 200 CONTACT 1 THEN 600 300 CONTACT 2 THEN 600 400 CONTACT 3 THEN 700 A f t e r t h e s e statements are executed a change of s t a t e i n CONTACT 1 or 2 w i l l cause t h e U P I R a t l i n e 600 t o b e scheduled. A change of s t a t e i n CONTACT 3 w i l l s c h e d u l e t h e U P I R a t l i n e 700. 8.2.4 DISMISS terminate a u s e r i n t e r r u p t service T h i s causes t h e m a i n l i n e code t o resume execution. If a n o t h e r u s e r p r o c e s s i n t e r r u p t r o u t i n e w a s s c h e d u l e d , it w i l l receive control a t t h i s p o i n t . DISMISS performs an action s i m i l a r t o t h a t o f RETURN. A DISMISS s t a t e m e n t i s used t o routine. 8.3 EXTENDED FUNCTIONS FOR INPUT OR OUTPUT The Extended I/O Functions allow t h e user t o t u r n a d i g i t a l o u t p u t "on" or " o f f " , r e a d a s w i t c h p o s i t i o n , set an a n a l o g v o l t a g e , or r e a d a n a l o g voltage v i a t h e UDC. An added f u n c t i o n allows r e a d i n g o r s e t t i n g of t h e system clock. Each class of f u n c t i o n a l I/O module ( a n a l o g i n p u t , analog o u t p u t , d i g i t a l i n p u t , d i g i t a l o u t p u t ) operates on a c o n t i n u o u s r a n g e of logical addresses. The mapping between the logical address and the c o r r e s p o n d i n g p h y s i c a l a d d r e s s of t h e UDC module and subchannel i s performed w i t h i n t h e system, based on tables which d e f i n e t h e UDC c o n f i g u r a t i o n and which t h e u s e r g e n e r a t e s d u r i n g "SYSTEM GENERATION". 8- 3 Thus, analog i n p u t p o i n t one (1) is d i f f e r e n t from a n a l o g o u t p u t p o i n t (1). This p r e v e n t s t h e u s e r from s p e c i f y i n g meaningless o p e r a t i o n s ( a t t e m p t i n g t o s e t a b i t "on" i n an i n p u t module). I n a d d i t i o n , UDC r e c o n f i g u r a t i o n s w i l l r e q u i r e o n l y a new table g e n e r a t i o n and no BASIC l e v e l programming changes. The logical a d d r e s s i n g s i m p l i f i e s t h e u s e NEXT loops. of FOR - I n g e n e r a l , a l l arguments t o t h e I n d u s t r i a l Functions must t h e range: 0 argument be within 4095 Negative arguments w i l l g e n e r a t e a f a t a l error, FM; arguments t h a t are o u t of range g e n e r a t e a FO. 8.3.1 The Clock Function - CLK(X) This f u n c t i o n h a s t w o o p e r a t i o n s : 1. I f X i s p o s i t i v e , t h e system c l o c k i s set t o t h e v a l u e o f X i n seconds. The v a l u e of X must be less t h a n 86400 ( t h e number o f seconds i n 24 h o u r s ) . 2. I f X i s z e r o o r n e g a t i v e , t h e v a l u e ( i n seconds) of t h e clock is returned. Example : 1. S e t t h e system clock t o 12:OO:OO 100 LET T = 12*3600 200 LET X = CLK(T) 300 END 2. Read the system clock 100 LET T = CLK(0) 3. Set t h e system clock t o the v a l u e e n t e r e d on t h e t e r m i n a l 50 75 100 GOT0 100 145 150 PRINT "INVALID TIME" PRINT "ENTER PRESENT TIME AS HH:MM:SS"; INPUT A,B,C I F A < 0 THEN 75 I F A > 23 THEN 75 IF B 0 THEN 75 IF B > 59 THEN 75 IF C < 0 THEN 75 I F C > 59 THEN 75 LET T = CLK(A*3600+B*60+C) 900 END 110 120 125 130 135 1 40 .. . 8-4 system Analog I n p u t Function 8.3.2 - ANI(C,G) This f u n c t i o n r e t u r n s t h e r e s u l t s , i n v o l t s , of reading channel (C) a t gain (G) The valid gains for the ADUOl are : 1000,200,100,50,20,10,2,1. Example : . Read analog i n p u t channel 6 a t a g a i n volts of 10, input voltage is .5 100 LET V= ANI (6,101 200 PRINT V t h e v a l u e p r i n t e d w i l l be 5. 8.3.3' Analog Output Function - ?NO(C,V) The AN0 f u n c t i o n sets t h e analog o u t p u t channel (C) t o t h e v a l u e (V). The a c t u a l o u t p u t generated is a f u n c t i o n of t h e modules used. However, f u l l scale o u t p u t w i l l be generated by a v a l u e (V) of 1 0 2 3 , and minimum o u t p u t w i l l be generated by a value o f zero. Values g r e a t e r than 1023 or less than z e r o are i l l e g a l . Example of f u l l scale o u t p u t on channel 3: 100 LET A = AN0 (3,1023) 8.3.4 Read D i g i t a l I n p u t - RDI (P,N) This f u n c t i o n r e t u r n s t h e value of t h e d i g i t a l i n p u t p o i n t s s t a r t i n g a t p o i n t P f o r N number of p o i n t s . The read may n o t cross a boundary between modules ( p o i n t s d i v i s i b l e by twelve, i.e., 1 2 , 2 4 etc.) . Example : 100 LET A = RDI (25,4) 200 LET B = RDI (1,l) Line 100 reads 4 p o i n t s (25-28) and r e t u r n s t h e v a l u e as A, t h i s is u s e f u l f o r BCD i n p u t devices. Line 200 reads t h e value o f p o i n t 1 and r e t u r n s a 1 i f t h e p o i n t i s "on", and a z e r o i f i t i s "off". 8.3.5 Send D i g i t a l Output - SDO (P,N,V) The SDO f u n c t i o n sets t h e d i g i t a l o u t p u t p o i n t ( s ) s p e c i f i e d by P and N t o t h e value V. The value must be a p o s i t i v e , and able t o be r e p r e s e n t e d w i t h i n the range of N. The d e f i n i t i o n of P and N i s t h e same as i n t h e RDI function. The value of V, i n b i n a r y n o t a t i o n , i s s e n t r i g h t - j u s t i f i e d i n t o t h e range s t a t e d . Example : 100 LET A = SDO ( 4 , 1 , 1 ) 200 LET A = SDO ( 1 , 4 , 1 0 ) 8- 5 Line 1 0 0 w i l l t u r n p o i n t 4 on, w h i l e l i n e 200 w i l l t u r n and 3. 8.3.6 Read D i g i t a l Output on points 1 - RDO (P,N) . T h i s f u n c t i o n i s i d e n t i c a l t o t h e R D I f u n c t i o n e x c e p t t h a t t h e "read" i s of t h e d i g i t a l o u t p u t channel (s) The data r e t u r n i s r e a d from a table, n o t t h e a c t u a l p h y s i c a l channels. T h e r e f o r e , o u t p u t modules t h a t a l t e r s t a t e independently of computer o p e r a t i o n s ( s i n g l e s h o t o u t p u t ) may be "on" i n the o u t p u t table b u t " o f f " p h y s i c a l l y . 8.3.7 Counter I n p u t - CN1 (P) This f u n c t i o n r e t u r n s t h e number of c o u n t s remaining module. in the counter Example : 100 LET A = C N 1 (3) A i s assigned t h e value of counted i n c o u n t e r 3. 8.3.8 Counter Output the number of events remaining to be - CNO ( P , V ) Counter o u t p u t is used t o s e t a c o u n t e r module. P i s t h e channel of t h e c o u n t e r module, and V i s t h e v a l u e o f t h e number of i t e m s t o c o u n t b e f o r e g e n e r a t i n g an i n t e r r u p t . Example : 100 LET A = CNO (2,300) T h i s w i l l set c o u n t e r 2 t o c o u n t 300 e v e n t s . 8.4 UPIR IDENTIFICATION FUNCTIONS The f o l l o w i n g f u n c t i o n s p r o v i d e t h e u s e r w i t h a means o f i d e n t i f y i n g t h e channel ( M E ) and s t a t e (STA) of t h e device t h a t caused t h e interrupt. T h i s w i l l a l l o w t h e u s e r t o have more t h a n one U P I R f o r several modules of t h e same type. 8.4.1 Line - LNE (XI The LNE f u n c t i o n r e t u r n s t h e channel number o f t h e module t h a t t h e i n t e r r u p t . The LNE f u n c t i o n h a s meaning o n l y i n a U P I R . caused Example : 1 0 0 LET A = LNE ( 0 ) Upon e n t r y t o t h e U P I R a t l i n e 100, A i s a s s i g n e d t h e t h a t caused t h e U P I R t o be invoked. 8-6 channel number 8.4.2 State - STA (X) The STA f u n c t i o n i s used t o f i n d t h e s t a t e of contact a s s o c i a t e d t h e channel t h a t scheduled t h e U P I R . with Example : 1 0 0 LET A = STA (LNE (0)) A is a s s i g n e d t h e state o f t h e that changed to cause the T h i s f u n c t i o n r e t u r n s t h e number o f i d e n t i c a l t h e same UPIR. schedule requests for contact interrupt. 8.4.3 8.5 Count - CNT (X) EXAMPLE CONTROL PROGRAM The example c o n t r o l program d e m o n s t r a t e s t h e m a i n t a i n i n g of a c o n s t a n t t e m p e r a t u r e b a t h v i a t h e f o l l o w i n g operations: 1. Open t h e h o t and c o l d water valves. 2. Open t h e d r a i n and t u r n t h e "BATH OK" lamp o f f . 3. Measure t h e b a t h t e m p e r a t u r e ; i f i t i s n o t 68 +or- .5 d e g r e e s t u r n t h e "BATH OK" lamp o f f and a d j u s t t h e h o t water valve. I f t h e b a t h t e m p e r a t u r e is 68 +or- .5 d e g r e e s t u r n t h e "BATH OK" lamp on. 4. C l o s e t h e h o t and c o l d water valves, and open t h e t h e s w i t c h i s c l o s e d t o s h u t down t h e p r o c e s s . The hardware i n t e r f a c e s are as f o l l o w s : ELEMENT TYPE POINT HOT VALVE COLD VALVE DRAIN VALVE BATH OK LAMP TEMP. SENSOR SHUT-DOWN SWITCH UDC/DAC UDC/DAC UDC/DO UDC/DO UDC/ADUO 1 UDC/CI 1 2 1 3 4 2 The I n d u s t r i a l BASIC program would be: 100 R E M CONTACT 2 SHUTS DOWN ENTIRE RUN 120 CONTACT 2 THEN 960 140 REM SCAN FOR TEMPERATURE EVERY 5 SECONDS 160 TIMER 5 THEN 500 180 REM SET SOFTWARE SWITCH FOR RESTART 200 LET S-1 220 REM OPEN DRAIN VALVE 240 LET A=SDO(1,1,1) 260 REM OPEN HOT AND COLD VALVES 50% 8-7 drain when 280 300 320 340 360 380 400 420 440 460 480 500 520 540 560 580 LET H-1023". 5 0 LET C=1023*. 5 0 LET A=ANO ( 1,H) LET A=AN0(2 ,C) RF,M SHUT BATH OK LAMP O F F LET A = S D O ( 3 , 1 , 0 ) REM NOW IDDLE LET A=O I F S=O GOTO 1 4 0 GOT0 4 2 0 REM LET WAN1 ( 4 , 2 0 0 ) GOSUB 6 8 0 R E M CONVERTS VOLTS TO DEGREES TEMPERATURE I F T > 6 8 . 5 THEN 7 4 0 I F T < 6 7 . 5 THEN 8 0 0 REM TEMPERATURE OR TURN BATH OK LAMP ON LET B = S D 0 ( 3 , 1 , 1 ) DISMISS REM mM SUBROUTINE TO CONVERT VOLTS TO DEGREES RETURN 600 620 640 660 680 700 7 2 0 RF,M 7 4 0 LET H=H*.95 7 6 0 LET C=C*1.05 7 8 0 GOTO 8 6 0 8 0 0 LET H=H*l.OS 8 2 0 LET C=C*.95 8 4 0 REM STEP VALVE AND TURN OFF BATH OK LAMP 8 6 0 LET B=ANO(l,H) 8 8 0 LET B=ANO( 2 ,C) 9 0 0 LET B = S D O ( 3 , 1 , 0 ) 9 2 0 GOTO 6 4 0 9 4 0 REM 9 6 0 LET S=STA(LNE ( 0 ) ) 98 0 IF S=O THEN 1 1 4 0 1 0 0 0 REM SHUT BATH DOWN 1020 LET B=ANO(l,O) 1 0 4 0 LET B=ANO(Z,O) 1 0 6 0 LET B = S D O ( 3 , 1 , 0 ) 1 08 0 LET B = S D O ( 1 , 1 , 1 ) 1100 REM NOW STOP TIMER 1120 TIMER 0 THEN 5 0 0 1 1 4 0 DISMISS 1 1 6 0 END NOTE T h e system w i l l resume c o n t r o l when t h e SHUT-DOWN SWITCH i s r e s t o r e d t o normal position . 8-8 8.6 POWER FAIL - RESTART I f a power f a i l u r e occurs a t Run-Time t h e system w i l l close any o y n f i l e s and chain t o a BASIC f i l e (PWRUP.BA). The u s e r may w r i t e h i s awn restart o p e r a t i o n s . NOTE TD8/E f i l e operations r e q u i r e t h a t t h e I n t e r r u p t System be "off". Therefore, power f a i l on TD8/E's may not be d e t e c t e d i f f i l e I / O i s i n progress. Closing an open f i l e w i l l d e l e t e any f i l e w i t h t h e same name and extension. 8-9 CHAPTER 9 E D I T I N G AND CONTROL COMMANDS S e v e r a l commands f o r e d i t i n g OS/8 BASIC programs and f o r c o n t r o l l i n g t h e i r execution enable t h e u s e r t o perform such o p e r a t i o n s as: . erase c h a r a c t e r s or l i n e s . l i s t p a r t or a l l of a program . save programs on v a r i o u s s t o r a g e d e v i c e s , and , c a l l program from s t o r a g e devices. NOTE See Chapter 1 0 f o r a d e s c r i p t i o n of OS/8 s t o r a g e devices and f i l e s . . 9 1 9.1.1 CORRECTING PROGRAMS E r a s i n g C h a r a c t e r s and Lines Errors made while t y p i n g programs a t t h e t e r m i n a l are easily corrected. Typing a SHIFT/O o r p r e s s i n g t h e RUBOUT key causes d e l e t i o n of t h e l a s t c h a r a c t e r typed, and echoes back arrow (+) on t h e terminal. One c h a r a c t e r i s d e l e t e d each t i m e t h e key i s typed. For example : 20 DEN F44--F FNA(X,Y)=Xf2+3*Y The u s e r t y p e s N i n s t e a d of F and immediately n o t i c e s h i s mistake. He p r e s s e s t h e RUBOUT key ( o r SHIFT/O) t h r e e t i m e s , which i s once f o r as many c h a r a c t e r s i n c l u d i n g spaces t o be d e l e t e d . H e makes t h e c o r r e c t i o n and continues t y p i n g t h e l i n e . The typed l i n e e n t e r s t h e computer only when t h e RETURN key i s pressed. 20 DEF FNA (X,Y)=Xt2+3*Y Sometimes it is easier t o d e l e t e a l i n e b e i n g typed and r e t y p e t h e l i n e r a t h e r than attempt a c o r r e c t i o n u s i n g r u b o u t s , Typing CTRL/U o r p r e s s i n g t h e ALTMODE key w i l l delete t h e l i n e c u r r e n t l y b e i n g worked on and echoes DELETED and a c a r r i a g e r e t u r n - l i n e feed. U s e o f t h e CTRL/U or ALTMODE command i s e q u i v a l e n t t o t y p i n g rubouts back t o t h e beginning of t h e l i n e . To d e l e t e a l i n e t h a t has a l r e a d y been e n t e r e d i n t o t h e computer t h e u s e r simply t y p e s t h e l i n e number followed by a c a r r i a g e r e t u r n . Both t h e l i n e number and t h e l i n e are removed from h i s program. 9-1 The u s e r may change i n d i v i d u a l l i n e s by simply t y p i n g them i n again. Whenever a l i n e i s entered, i t r e p l a c e s any e x i s t i n g l i n e which h a s t h e same l i n e number. New l i n e s may be i n s e r t e d anywhere i n t h e program by g i v i n g them l i n e numbers which are between t w o o t h e r e x i s t i n g l i n e numbers. Using t h e s e e d i t i n g c a p a b i l i t i e s , t h e program may be modified and re-run u n t i l it works p r o p e r l y . 9.1.2 The RESEQ Program A f t e r t h e user h a s e x t e n s i v e l y modified h i s program, h e may f i n d t h a t some p o r t i o n s o f t h e program have l i n e numbers spaced so c l o s e l y t o g e t h e r t h a t t h e y do n o t p e r m i t any f u r t h e r a d d i t i o n o f statements s h o u l d he wish t o do SO. Renumbering t h e l i n e s i n t h e program so a s t o p r o v i d e a p r a c t i c a l increment between l i n e numbers can be accomplished a u t o m a t i c a l l y by u s i n g t h e RESEQ program l i s t e d below. The RESEQ program is saved as RESEQ.BA. I t s h o u l d be n o t e d t h a t t h e RESEQ program modifies t h e l i n e numbers i n a l l statements c o n t a i n i n g them (such as GOSUB and IF-THEN s t a t e m e n t s ) t o a g r e e w i t h t h e new l i n e numbers a s s i g n e d t o s t a t e m e n t s by t h e program. L i n e l e n g t h s must n o t exceed 72 c h a r a c t e r s . 990 1000 1 01 0 1020 1030 REM PROGRAM RESEQ D I M L$ (72) rF$ (1),C$ (1),NS (16) D I M L2$ (72) D I M N ( 350) LET F$=CHR$ (2 8) 1040 PRINT "FILE" ; INPUT N$ PRINT "START, STEP" ; INPUT S1,S LET Sl=INT (ABS (Sl)) LET S=INT (ABS(S)) 1050 1060 1070 1080 1090 1100 1110 1120 1130 1140 1150 1160 1170 1180 1190 1200 1 2 10 1220 1230 1240 1250 1260 1270 1280 1290 1300 1310 1320 1330 LET T=O LET N2=0 FILE #l:N$ LET I=1 INPUT #l:L$ IFEND #1 THEN 1320 LET L=LEN (L$) GOSUB 1980 I F N1>0 THEN 1220 PRINT "NO LINE NUMBER" PRINT L$ GO TO 1130 I F N b N 2 THEN 1260 PRINT "OUT O F SEQUENCE" PRINT L$ GO TO 1130 LET N2=N1 LET T=T+l LET N ( T ) = N l I F T<350 THEN 1130 PRINT "TOO MANY LINES" STOP RESTORE #1 FILEV #2:N$ 9-2 1340 1350 1360 1370 13 80 1390 1400 1410 1420 1430 1440 1450 1460 1470 1480 1490 1500 1510 1520 1530 1540 1550 1560 1570 15 80 1590 1600 1610 1620 16 30 1640 1650 1660 1670 16 80 1690 1700 1710 1720 1730 1740 1750 1760 1770 1780 1790 1800 1810 1820 1830 1840 1850 1860 1870 1880 189 0 19 00 1910 1920 LET N2=S1 INPUT #1: L$ IFEND #1 THEN 1730 LET 1=1 LET L=LEN (L$) GOSUB 1980 LET L2 $=STR$ (N2) PRINT #2:L2$; LET L$=SEG$(L$,I,72) LET N2=N2+S LET F=O LET D=POS (L$,F$ ,l)\LET P=D IF D = O THEN 1490 LET L2$=SEG$(L$,P+1,72) LET L$=SEG$ (L$,1 ,P-l) LET I=POS (L$,"GOTO" ,I)+4 IF I>4 THEN 1750 LET I=POS (L$,"GOTO" ,1)+5 IF I>5 THEN 1750 LET I=POS (L$,"THEN" ,1)+4 IF I>4 THEN 1750 LET I=POS (L$,"GOSUB", 1)+5 IF I>5 THEN 1750 LET I=POS (L$ "GOSUB" ,1)+6 IF I>6 THEN 1750 IF F=O THEN 1610 PRINT #2 :F$; PRINT #2:L$; LET F=F+l IF D>O THEN 1660 PRINT #2: GO TO 1350 LET D=POS(L2$,F$,l)\LET P=D IF D>O THEN 1700 LET L$=L2$ GO TO 1490 LET L$=SEG$ (L2$,I , P - l ) LET L2 $=SEG$ (L2$ ,P+l, 72 ) GO TO 1490 CLOSE #2 STOP LET -LEN (L$) GOSUB 1920 IF C=32 THEN 1760 IF CtO THEN 1890 LET 1 ~ 1 - 1 LET P=I GOSUB 1980 IF N1=0 THEN 1890 FOR J=1 TO T IF Nl<>N(J) THEN 1880 LET Q$=sTR$(J*s-s+s~) LET L$=sEG$(L$,~,P-~)LQs GO TO 1590 NEXT J PRINT "BAD REFERENCE" PRINT L$ GO TO 1590 IF I<=L THEN 1950 , 9-3 1930 1940 1950 1960 1 9 70 1980 1990 2000 2010 2020 20 30 2040 2050 2060 2070 LET C=-1 RETURN LET C=ASC(SEG$(L$,I,I)) LET I = I + l RETURN LET N1-0 GOSUB 1920 I F C<48 THEN 2040 I F 0 5 7 THEN 2040 LET Nl=N1*10+C-48 GO TO 1990 I F C<O THEN 2060 LET I=I-1 RETURN END T y p i c a l l y , t h e program would be used as follows: SAVE SYS:SAMPLE U s e r saves program SAMPLE which r e q u i r e s renumbering. READY BASIC i s ready f o r next command. OLD SYS:RESEQ U s e r c a l l s f o r program RESEQ. READY BASIC i s ready for next command. RU"H U s e r r u n s program. FILE? SYS:SAMPLE.BA Program responds asks with for name filename. o f program User t o be renumbered. START, STEP?lOO,lO Program a s k s f o r a s t a r t i n g l i n e number (START) and f o r t h e increment between l i n e numbers (STEP) User r e q u e s t e d t h a t SAMPLE s t a r t w i t h l i n e number 100 and e a c h l i n e be incremented by 1 0 . ReADY Renumbering i s accomplished. r e a d y f o r n e x t command. OLD SYS:SAMPLE U s e r c a l l s back h i s program. READY BASIC ready for next command. LISTNH U s e r g e t s l i s t i n g o f program SAMPLE . f u r t h e r modification. NOTE A l l commands d e s c r i b e d i n t h e following paragraphs, e x c e p t LISTNH and RUNNH, may two be abbreviated u s i n g t h e f i r s t letters o f t h e command. 9-4 BASIC for 9.2 THE LIST AND LISTNH COMMANDS An e n t i r e program can b e l i s t e d on t h e t e r m i n a l by t y p i n g LIST followed by a c a r r i a g e r e t u r n . A heading i s p r i n t e d b e f o r e t h e program i t s e l f and i s of t h e form: FILE EX VERSION NO. DATE For example, i f t h e u s e r i s working on a wants a l i s t i n g he t y p e s : program named USER.BA and LIST and BASIC responds w i t h : USER BA 1.0 26- JUL- 72 100 LET X=l . .. . b 200 END READY NOTE When any OS/8 BASIC command is completed, t h e message READY i s ‘ p r i n t e d a t t h e terminal. OS/8 BASIC i s t h e n ready t o a c c e p t any o t h e r commands from t h e user. by a l i n e number. T h i s causes t h a t l i n e and a l l f o l l o w i n g l i n e s i n t h e program t o be l i s t e d . For example: A p a r t of a program may be l i s t e d by t y p i n g LIST followed LIST 100 w i l l l i s t l i n e 100 and a l l remaining l i n e s i n t h e program. Typing CTRL/O w h i l e t h e l i s t i n g i s b e i n g p r i n t e d t e r m i n a t e s t h e p r i n t i n g and o u t p u t s t h e READY message. The LISTNH command may be used e x a c t l y as t h e e l i m i n a t e s t h e heading from t h e l i s t i n g . 9.3 LIST command, but it THE SCRATCH COMMAND The command: SCRATCH i s provided t o a l l o w t h e programmer t o clear h i s s t o r a g e area, d e l e t i n g any commands, o r a program which may have been p r e v i o u s l y 9-5 e n t e r e d , and- l e a v i n g a c l e a n area i n which t o work. If t h e s t o r a g e area i s n o t cleared before e n t e r i n g a new program, l i n e s f r o m p r e v i o u s programs may be executed a l o n g w i t h t h e new program, c a u s i n g errors o r The SCRATCH command e l i m i n a t e s a l l o l d s t a t e m e n t s and misinformation. numbers and s h o u l d be used before new programs are created. 9.4 THE NEW COMMAND The NEW command i s used t o name a program you are going t o create and performs an i n h e r e n t SCRATCH on t h e storage area. The command i s i n t h e form: NEW FILE.EX I t a s s i g n s t h e filename t o t h e program t o be created. For example: NEW USERA. BA creates f i l e USERA.BA. An a l t e r n a t e method of naming programs RETURN key. BASIC responds w i t h : is t o t y p e NEW followed by the FILE NAME-The u s e r types t h e filename and e x t e n s i o n followed by t h e RETURN key. NEW FILE NAME--USER.BA (.BA i s assumed and need n o t be t y p e d ) NOTE Extension .BA i s assumed i n t h e OLD, NEW, NAME, and SAVE commands u n l e s s otherwise specified. I f no e x t e n s i o n i s specified i n t h e OLD command, OS/8 I n d u s t r i a l BASIC first tries t o l o a d FILE.BA and i f u n s u c c e s s f u l tries t o locate and load FILE without the extension. 9.5 THE OLD COMMAND T h i s c o m a n d r e t r i e v e s a p r e v i o u s l y created f i l e from a storage device and places the f i l e i n t h e s t o r a g e area of t h e computer. The command is of the form: OLD DEV:FILE.EX 9-6 For example: OLD DTA1:SAMPLE.BA r e t r i e v e s f i l e SAMPLE from DECtape number s t o r a g e area of t h e computer. 1 and places An alternate method of r e t r i e v i n g a f i l e i s t o type t h e RETURN key. BASIC responds with: OLD in the followed by it FILE ,NAME-The u s e r t y p e s t h e d e v i c e , filename RETURN key. and extension followed by the in storage OLD FILE NAME--DTAl:SAMPLE.BA I f t h e d e v i c e i s o m i t t e d , DSK: i s assumed. 9.6 THE NAME COMMAND T h i s command p e r m i t s t h e u s e r t o rename t h e program area o f t h e computer. The command i s o f t h e form: the NAME FILE.EX S i n c e t h i s command changes o n l y t h e name of t h e s t o r a g e area of t h e n o t i t s c o n t e n t s , it can be used t o create t w o almost computer i d e n t i c a l v e r s i o n s of t h e same program. T h i s i s accomplished by r e t r i e v i n g the f i r s t f i l e , making m o d i f i c a t i o n s t o it, and t h e n SAVEing (see paragraph 9.7) t h e modified version under t h e new name. - 9-7 THE SAVE COMMAND The SAVE command saves on t h e s p e c i f i e d d e v i c e t h e f i l e c u r r e n t l y t h e s t o r a g e area o f t h e computer. The command i s of t h e form: in SAVE DEV:FILE.EX I f f i l e n a m e and e x t e n s i o n I f d e v i c e i s o m i t t e d , DSK: i s assumed. o m i t t e d , t h e c u r r e n t filename and e x t e n s i o n are used. are The SAVE command also p r o v i d e s a c o n v e n i e n t method f o r l i s t i n g l a r g e programs q u i c k l y on t h e l i n e p r i n t e r r a t h e r t h a n t h e terminal. For example : SAVE LPT: l i s t s t h e c u r r e n t program on t h e l i n e p r i n t e r . 9-7 9.8 THE RUN AND R U " H COMMANDS A f t e r a I n d u s t r i a l BASIC program h a s been typed and i s i n core, it is ready t o b e run. T h i s i s accomplished by simply t y p i n g t h e command: RUN The program heading i s p r i n t e d and t h e program b e g i n s e x e c u t i o n . are encountered, a p p r o p r i a t e error messages a r e typed on t h e keyboard: o t h e r w i s e , t h e program r u n s t o completion, p r i n t i n g When t h e END s t a t e m e n t i s reached, whatever o u t p u t w a s requested. OS/8 I n d u s t r i a l BASIC s t o p s e x e c u t i o n and p r i n t s : If errors READY I f t h e program does n o t run p r o p e r l y , or c o n t a i n s an i n f i n i t e loop and, hence, w i l l never s t o p , i t may b e t e r m i n a t e d by t y p i n g CTRL/C, which r e t u r n s c o n t r o l t o the OS/8 I n d u s t r i a l BASIC e d i t o r (READY). The RUNNH command s u p p r e s s e s p r i n t i n g of t h e heading and may i n p l a c e of t h e RUN command. be used NOTE I f a program t h a t is n o t SAVEd i s RUN, and f o r some reason i s n o t r e t r i e v a b l e by LISTing, t h e program may be r e t r i e v e d by c a l l i n g f o r OLD f i l e BASIC.WS. 9.9 THE BYE COMMAND The BYE command i n s t r u c t s t h e computer t o e x i t from OS/8 Industrial Typing a BASIC and r e t u r n s c o n t r o l t o t h e OS/8 Keyboard Monitor. CTRC/C w h i l e i n t h e OS/8 I n d u s t r i a l BASIC e d i t o r (READY) mode also r e t u r n s c o n t r o l t o t h e OS/8 Keyboard Monitor. NOTE Never t y p e BYE b e f o r e SAVEing a newly typed program. Unless t h e SAVE command i s used, t h e program w i l l be l o s t . 9-8 CHAPTER 1 0 FILES, FILE STATEMENTS AND C H A I N I N G GENERAL INFORMATION ON OS/8 INDUSTRIAL BASIC FILES 10.1 Resident Devices 10.1.1 The f i l e c a p a b i l i t y provided by OS/8 I n d u s t r i a l BASIC allows t h e u s e r t o w r i t e i n f o r m a t i o n i n t o (PRINT#) o r r e a d i n f o r m a t i o n from (INPUT#) f i l e s . Only I / O t o d e v i c e s which are p a r t of t h e r e s i d e n t p o r t i o n of t h e OS/8 Monitor may be done. The Resident Device h a n d l e r i n c l u d e s t h e devices: SYS: and DTAl: f o r TD8E's and SYS: and RKBO: f o r RK8E's A l l o t h e r c u r r e n t system d e v i c e h a n d l e r s c o n t a i n o n l y SYS: 10.1.2 F i l e Descriptions F i l e s are r e f e r e n c e d s y m b o l i c a l l y by a name o f up t o s i x alphanumeric c h a r a c t e r s followed, o p t i o n a l l y , by a p e r i o d and an e x t e n s i o n of t w o alphanumeric c h a r a c t e r s . The e x t e n s i o n t o a f i l e name i s g e n e r a l l y used as an a i d f o r remembering t h e format o f a f i l e . NOTE files operating under OS/8 Industrial BASIC are considered s e q u e n t i a l access f i l e s . That i s , t h e y must be read o r w r i t t e n s e q u e n t i a l l y , another, from the one i t e m a f t e r beginning of t h e f i l e All . 10.1.2.1 Fixed Length F i l e s A f i x e d l e n g t h f i l e i s one which i s a l r e a d y i n e x i s t e n c e . That i s , i t has been c r e a t e d and CLOSEd. The l e n g t h of a f i x e d l e n g t h f i l e i s e q u a l t o t h e number o f b l o c k s t h e f i l e and cannot be changed. 10.1.2.2 in V a r i a b l e Length F i l e s A variable l e n g t h f i l e i s a newly created f i l e . Until the f i l e is CLOSEd, it i s e q u a l i n l e n g t h t o t h e l a r g e s t f r e e space on t h e device. When t h e f i l e i s CLOSEd it becomes a f i x e d l e n g t h f i l e e q u a l i n l e n g t h t o t h e a c t u a l number of b l o c k s i t o c c u p i e s . 10-1 Unless t h e f i l e is CLOSEd, t h e CHAIN, cause a loss of t h e f i l e . 10.1.2.3 STOP or END statements will Numeric F i l e s Data i n numeric f i l e s are stored as successive three-word floating-point numbers (85 t o each OS/8 b l o c k ) with t h e l a s t word i n each block unused. 10.1.3.4 ASCII F i l e s Data i n ASCII f i l e s are s t o r e d i n s t a n d a r d OS/8 format ( t h r e e 8 - b i t Refer t o Chapter 11 of t h i s manual c h a r a c t e r s t o e v e r y t w o words). and the O S / 8 Software Support Manual (DEC-S8-OSSMA-A-D). 10.2 FILE STATEMENTS OS/8 I n d u s t r i a l BASIC p r o v i d e s a number o f s t a t e m e n t s f o r o p e r a t i n g on files. They i n c l u d e : FILE# PRINT# INPUT# RESTORE# CLOSE # I F END# The s t a t e m e n t s are d i s t i n g u i s h a b l e from o t h e r OS/8 I n d u s t r i a l BASIC s t a t e m e n t s by t h e number s i g n ( # ) which i s appended t o t h e statement. 10.2.1 The FILE# Statement This statement is used t o open a f i l e and i s of t h e form: ( l i n e number) FILEtype numeric e x p r e s s i o n : STRING EXPRESSION where : a. FILEtype i s one of f o u r p o s s i b i l i t i e s : FILE t y p e FILE FILEV FILEN FILEVN Definition Fixed l e n g t h - A-S CASCII II - numeric - numeric V a r i a b l e length Fixed l e n g t h V a r i a b l e length 10-2 b. The numeric e x p r e s s i o n has a v a l u e of one o r t w o and r e p r e s e n t s t h e i n t e r n a l f i l e number f o r t h e f i l e being .opened and i s used i n any o t h e r s t a t e m e n t s r e f e r e n c i n g t h i s f i l e . C. The s t r i n g e x p r e s s i o n i s e i t h e r a s t r i n g v a r i a b l e c o n s t a n t which has a value o f t h e form: or a string DEV: F I L E EX For example, t h e following program: 1 0 LET A$="DTAl :NETSAK. BA" 20 FILEN #l:A$ i s e q u i v a l e n t to: 1 0 FILEN #l:"DTAl:NETSAK.BA" f o r opening f i x e d l e n g t h numeric f i l e NETSAK on DECtape number 1 and a s s i g n i n g it i n t e r n a l f i l e number 1. I f DEV: i s missing from t h e s t r i n g e x p r e s s i o n , t h e device DSK i s assumed by d e f a u l t . NOTE Only t w o f i l e s , (numbered 1 and 2 ) b e s i d e s t h e t e r m i n a l ( F I L E #0) may be open i n a program a t any t i m e . However, t h e a b i l i t y t o open and close (CLOSE#) f i l e s under program c o n t r o l p e r m i t s t h e u s e r t o access an u n l i m i t e d number of files. When s e l e c t i n g a FILEtype, t h e u s e r should keep i n mind t h a t v a r i a b l e l e n g t h f i l e s (FILEV and FILEVN) are restricted t o o u t p u t t i n g only. That i s , v a r i a b l e l e n g t h f i l e s should be used i n c o n j u n c t i o n w i t h t h e P R I N T # s t a t e m e n t only. An attempt t o read ( I N P U T # ) from a v a r i a b l e Only one FILEV or FILEVN may l e n g t h f i l e r e s u l t s i n e r r o r message VR. be active p e r device a t a given t i m e . Fixed l e n g t h ASCII f i l e s (FILE) should be r e s t r i c t e d t o use w i t h t h e INPUT# s t a t e m e n t , b u t may be used w i t h t h e PRINT# s t a t e m e n t when t h e u s e r is c e r t a i n t h a t t h e A S C I I o r numeric d a t a h e i s P R I N T I N G (i.e*, t h e number of c h a r a c t e r s ) r e p l a c e s , e x a c t l y , t h e A S C I I o r numeric data on t h e f i l e . I t is recommended t h a t t h e use o f f i x e d l e n g t h A S C I I f i l e s (FILE) f o r o u t p u t be e n t i r e l y avoided. 10.2.2 The PRINT# Statement The PRINT# s t a t e m e n t w r i t e s d a t a i n t o f i l e s and is of t h e form: ( l i n e number) PRINT #N: l i s t of e x p r e s s i o n s and d e l i m i t e r s where N i s t h e numerical e x p r e s s i o n f o r a f i l e number. For A S C I I f i l e s , t h e e x p r e s s i o n s i n t h e l i s t can be s t r i n g o r numeric, and t h e TAB and PNT f u n c t i o n s can both be used. The d e l i m i t e r s can be commas or semicolons and have the same meanings that they have in t h e PRINT s t a t e m e n t f o r t h e t e r m i n a l ( r e f e r t o Chapter 3 ) . For numeric f i l e s , 10-3 the expressions semicolons. maybe o n l y n u m e r i c v a r i a b l e s s e p a r a t e d by c o m m a s o r 1 0 FILEV # 1 : M B 0 :DATE. DA" 20 LET F = l 30 PRINT #F: TAB ( 2 8 ) ;DAT$ (X) 40 CLOSE #F 50 END . T h i s r o u t i n e p r i n t s t h e d a t e , s t a r t i n g a t column 28 on t h e d e v i c e RKBO i n a f i l e named "DATE.DA" 10.2.3 The INPUT# Statement The I N P U T # s t a t e m e n t r e a d s d a t a from f i l e s and i s of t h e form: ( l i n e number) I N P U T #N: l i s t of v a r i a b l e s where N i s t h e numerical e x p r e s s i o n f o r a f i l e number. The INPUT# s t a t e m e n t does not e x p e c t a l i n e number on each l i n e of d a t a i n t h e file. I f one i s p r e s e n t , it i s r e a d as d a t a : 1 0 D I M N$(19,15) 20 FILE #l:"LARRY" 30 FOR I=l TO 19 40 INPUT #1: N$(I) 50 NEXT I 60 END The above r o u t i n e reads 19 s t r i n g s from f i l e LARRY. NOTE DSK: i s example. the system device in this The p r e v i o u s paragraph i n d i c a t e d t h a t numbers may be w r i t t e n i n t o an ASCII file. The r e a d i n g o f numbers from an ASCII f i l e r e q u i r e s some p r e c a u t i o n i f t h e data d e l i m i t e r i s o t h e r t h a n a comma o r semicolon. I n l i n e 30 of t h e example below, t h e data w r i t t e n i n t o f i l e number 1 w i l l b e s e p a r a t e d by a c a r r i a g e - r e t u r n and l i n e - f e e d which are b o t h written i n t o the f i l e . The subsequent r e a d i n g o f numbers from t h e f i l e i n l i n e number 80 shows t h e u s e of a p a i r of dummy arguments ( C and L) t o compensate f o r t h e c a r r i a g e - r e t u r n and l i n e - f e e d s i n c e t h e y would o t h e r w i s e be read as numeric data w i t h a v a l u e o f 0. 10 FILEV #l:A$ 20 FOR I = 1 TO 10 30 P R I N T #l:I 40 NEXT I 50 CLOSE #1 60 FILE #l:A$ 70 FOR I = 1 TO 1 0 80 INPUT # 1 : J , C , L 90 NEXT I 100 END 10-4 10.2.4 The RESTORE# Statement The RESTORE# s t a t e m e n t i s o f t h e form: ( l i n e n u d e r ) RESTORE # where N is a numerical e x p r e s s i o n f o r t h e f i l e number t o be reset t o t h e beginning. I f N i s e q u a l t o zero, o r i f #N i s missing from t h e s t a t e m e n t , t h e DATA l i s t i n t h e program i s reset t o t h e beginning. 10 FILE #2:"SUSAN" 20 INPUT #2: A,B,C,D 25 RESTORE #2 30 INPUT #2: E,F,G,H This program u s e s t h e same values from system f i l e SUSAN f o r v a r i a b l e s A, B, C , and D as it does f o r v a r i a b l e s E , F , G, and H. 10.2.5 The CLOSE# Statement The CLOSE# s t a t e m e n t i s of t h e form: ( l i n e number) CLOSE #N where N i s t h e numerical e x p r e s s i o n f o r t h e f i l e number t o be For example: closed. 10 D I M A$(5,10) 15 FOR 111 TO 4 20 LET A$ ( I ) = "SHERRY" & CHR$(I+48) &".BA" 25 FILE # l : A $ ( l ) 30 INPUT # l : B $ 35 I N B$="SANDY" THEN 60 40 CLOSE #1 45 NEXT I 50 PRINT "CANNOT FIND SANDY" 55 STOP 60 PRINT "FOUND SANDY I' .. .. . 0 90 END T h i s program s e a r c h e s through f o u r system f i l e s (SHERY1 through SHERY4) f o r t h e f i l e t h a t has SANDY as t h e f i r s t e n t r y . I f t h e f i r s t e n t r y i n the f i l e i s not SANDY, t h e f i l e i s c l o s e d ( s t a t e m e n t 40) and t h e n e x t f i l e i s opened. NOTE The u s e r must CLOSE# a l l o u t p u t f i l e s b e f o r e ending t h e program i n o r d e r t o prevent t h e loss of d a t a . 10-5 10.2.6 The I F END# Statement The I F END# s t a t e m e n t allows t h e u s e r t o determine whether o r t h e r e has been an End-of-File d e t e c t e d f o r t h e f i l e i n q u e s t i o n . s t a t e m e n t has t h e form: not The ( l i n e number) I F END #N THEN l i n e number where N i s a numerical e x p r e s s i o n f o r t h e number must refer t o a l i n e i n t h e program. file number. last INPUT# The line .. 0 ... 106 I F END #1THEN 170 . 170 END I f t h e IF END# s t a t e m e n t i s found t r u e , (read or w r i t e ) should be discarded. the or PRINT# The I F END# statement is n o t used t o determine i f more d a t a is available, b u t r a t h e r t o determine i f t h e l a s t read or w r i t e was valid. The f i r s t a t t e m p t , i n an I N P U T # or PRINT# s t a t e m e n t , to read or w r i t e p a s t an end-of-file c a u s e s an abort o f t h e I / O associated w i t h t h a t read or w r i t e , and t h e program p a s s e s c o n t r o l t o t h e n e x t o p e r a t i o n t o be performed. The second, and any subsequent a t t e m p t s , t o read or w r i t e p a s t an e n d - o f - f i l e c a u s e s an RE o r WE runtime error t o be p r i n t e d f o r each s y n t a c t i c a l i t e m i n t h e I N P U T # or PRINT# list. To avoid a l e n g t h y l i s t of error messages, avoid u s i n g long INPUT# or PRINT# l i s t s i n s i t u a t i o n s which may approach an end-of-file. 10.3 THE CHAIN STATEMENT The CHAIN s t a t e m e n t p r o v i d e s a convenient means f o r d i v i d i n g large programs i n t o a series of smaller programs which are w r i t t e n and stored s e p a r a t e l y , and e x e c u t e d i n a chain. The CHAIN s t a t e m e n t i s o f t h e form: ( l i n e number) CHAIN "DEV:Filename.extension" When BASIC e n c o u n t e r s a CHAIN s t a t e m e n t i n a program, it stops execution of that program, retrieves the program named in t h e CHAIN s t a t e m e n t from t h e s p e c i f i e d d e v i c e and f i l e , compiles t h e chained The u s e of t h e CHAIN program and b e g i n s e x e c u t i o n of t h e program. s t a t e m e n t , t h e r e f o r e , i s t h e a u t o m a t i c e q u i v a l e n t of running an OLD program w i t h no header (RUNNH). The f i l e BASIC.WS w i l l c o n t a i n t h e o r i g i n a l program i n t h e c h a i n and when e x e c u t i o n i s complete, t h e BASIC s t o r a g e area w i l l c o n t a i n t h e o r i g i n a l program. 10-6 Since B A S I C removes t h e program which c o n t a i n s t h e CHAIN s t a t e m e n t from core b e f o r e r e t r i e v i n g t h e chained program, t h e u s e r s h o u l d make c e r t a i n t o CLOSE# a l l o u t p u t f i l e s t h a t are opened by F I L E s t a t e m e n t s i n t h e program which c o n t a i n s t h e CHAIN s t a t e m e n t i n order t o avoid t h e loss of d a t a generated by t h e program. NOTES 1. Control commands OLD, RUNNH, are described i n Chapter 9. and SAVE 2 . I f DEV: i s n o t s p e c i f i e d , assumed by d e f a u l t . DSK: is 10-7 CHAPTER 11 CREATING ASSEMBLY LANGUAGE FUNCTIONS 11.1 INTRODUCTION OS/8 I n d u s t r i a l BASIC has a f a c i l i t y which a l l o w s e x p e r i e n c e d PDP-8 assembly language programmers t o i n t e r f a c e t h e i r own assembly language r o u t i n e s t o OS/8 I n d u s t r i a l BASIC. This f a c i l i t y p e r m i t s t h e u s e r t o add f u n c t i o n s t o OS/8 I n d u s t r i a l BASIC which can o p e r a t e d i r e c t l y on s p e c i a l purpose p e r i p h e r a l devices. T h i s c h a p t e r d e s c r i b e s i n some d e t a i l t h e o r g a n i z a t i o n and i n t e r n a l c h a r a c t e r i s t i c s o f t h e OS/8 I n d u s t r i a l BASIC Run-time System (INBRTS) and i s i n t e n d e d t o serve as a programming guide f o r t h e c r e a t i o n of such user-coded assembly language f u n c t i o n s . T h i s material assumes t h e u s e r t o be f a m i l i a r w i t h OS/8 and PDP-8 assembly language. For a d d i t i o n a l i n f o r m a t i o n on e i t h e r subject, see t h e OS/8 SYSTEM REFERENCE MANUAL. I n a d d i t i o n t o t h i s c h a p t e r t h e programmer would f i n d m o s t u s e f u l a listing of the OS/8 Industrial BASIC Runtime System (DEC-S8-LBASB-A-LA). 11.2 THE OS/8 INDUSTRIAL BASIC SYSTEM The OS/8 I n d u s t r i a l discrete p a r t s : 1. 2. 3. 4. 5. BASIC system is divided The BASIC e d i t o r The BASIC compiler The BASIC l o a d e r The BASIC r u n t i m e system The runtime system over l a y s into the following .. (INBSI C SV) ( INBCMP SV) (INBLDR. SV) ( INBRTS. SV) (1NBSIC.AF) (INBSIC. SF) (INBSIC. FF) The OS/8 I n d u s t r i a l BASIC e d i t o r i s used t o create and e d i t t h e source program. On r e c e i p t of a RUN command, t h e e d i t o r creates a temporary f i l e c a l l e d BASIC.WS, stores t h e source i n t h a t f i l e , t h e n c h a i n s t o t h e compiler. The compiler compiles t h e program i n t o a 1 2 - b i t pseudo-code which i s loaded i n t o c o r e a l o n g w i t h t h e runtime system by t h e loader. The run t i m e system i n t e r p r e t s each p s e u d o - i n s t r u c t i o n , On completion o f c a l l i n g each o f t h e o v e r l a y s i n t o core as needed. t h e program, t h e runtime system c h a i n s back t o t h e e d i t o r , and t h e c y c l e i s repeated. Following i s a diagram showing t h e f i l e s on t h e systems d e v i c e a s s o c i a t e d with o r used by each system component. BASIC Component Associated Files Usage BASIC. WS program s t o r a g e BASIC.WS BASIC.TM program s t o r a g e compiled code s t o r a g e 11-1 compiled code storage Loader BASIC, TM Rufime System INBS I C AF 1NBSIC.SF INBS I C FF . . 1 overlays ( i f needed) The u s e r must avoid u s i n g t h e filenames above: they are t h e OS/8 I n d u s t r i a l BASIC System. 11.3 THE OS/8 reserved for INDUSTRIAL BASIC RUNTIME SYSTEM A t t h e t i m e t h e u s e r ' s BASIC program i s a c t u a l l y b e i n g executed, the p o r t i o n o f t h e BASIC system i n c o n t r o l i s t h e Run t i m e System (INBRTS) INBRTS i s a l s o i n core when user-coded f u n c t i o n s are . and as such, a knowledge of it i s e s s e n t i a l t o w r i t i n g an executed, BASIC assembly language f u n c t i o n . Note t h a t t h e f o l l o w i n g s e c t i o n s r e f e r f r e q u e n t l y t o s p e c i f i c core l o c a t i o n s i n INBRTS by The a c t u a l v a l u e of t h e s e symbolic names (always c a p i t a l i z e d ) symbols can be o b t a i n e d from t h e symbol t a b l e (Appendix H) f o r t h e Note t h a t t h i s symbol t a b l e i s f o r a v e r s i o n of BASIC being used. non-EAE system: t h e major r o u t i n e e n t r y p o i n t s mentioned i n t h i s c h a p t e r , however, are t h e same f o r both systems. A l l diagrams i n t h i s c h a p t e r have t h e lowest core a d d r e s s a t t h e bottom. This c h a p t e r a l s o makes use of t h e v a r i a b l e names A, A ( 0 , O ) A$, and A$ ( 0 ) t o r e p r e s e n t t h e g e n e r a l case. A l l r e f e r e n c e s i n t h i s c h a p t e r t o "page 0" r e f e r t o t h e INBRTS page 0 (Page 0 , F i e l d 0 ) . OS/8 . , 11.3.1 INBRTS C o r e Layout When e x e c u t i n g , INBRTS h a s t h e f o l l o w i n g c o n f i g u r a t i o n : Resident 3S/8 FIELD N Symbol (where N= h i g h e s t core field in machine ) Tables N7400 OR N7600 In-core DATA List . .. 0 0 Array Space @ Pseudo Code FIELD 1 11377 12400 F i l e Buffers Process I / O USR swap] 10000 (OS/8 % c 11-2 ., 07600 FIELD 0 F i l e Table 07577 Floating Point Package 06677 INBRTS 04600 Interpreter 03400 0 The h i g h e s t core f i e l d i s used f o r INBRTS symbol t a b l e s , s t o r i n g o f t h e f i e l d 1 and f i e l d 2 ( i f non-ROM TD8 /E) r e s i d e n t p o r t i o n s of t h e OS/8 Monitor, t h e in-core DATA l i s t ( d a t a generated by DATA s t a t e m e n t s i n t h e program) and pseudo-code ( g e n e r a t e d by t h e c o m p i l e r ) . The bottom of t h e a r r a y space (marked by l i n e A) can exceed t h e f i e l d boundary and proceed i n t o lower f i e l d s , b u t t h i s w i l l only happen f o r Note t h a t i f t h e bottom of t h e pseudo-code e x t e n d s l a r g e programs. below l i n e B ( 1 2 4 0 0 ) , one f i l e b u f f e r space must b e s a c r i f i c e d , w i t h corresponding loss of runtime f i l e c a p a b i l i t i e s . A s t h e bottom of t h e pseudo-code approaches 12000, t h e number o f f i l e s which may be simultaneously open a t runtime approaches 0. A t l e a s t 400(8) words of b u f f e r must be f r e e f o r each f i l e opened a t runtime. The f i l e b u f f e r s a r e a l l o c a t e d dynamically a t runtime i n response t o FILE commands i n t h e BASIC program, and i f n o t f u l l y used may be used as b u f f e r space by t h e u s e r function. 11.3.2 INBRTS Overlays Locations 3400-4577 o f f i e l d 0 s e r v e as an o v e r l a y area, i n t o which t h e c u r r e n t l y needed o v e r l a y i s read. The o v e r l a y s c o n s i s t mainly of f u n c t i o n s which are i n f r e q u e n t l y used, and are c o n s t r u c t e d as follows: 1NBSIC.AF A r i t h m e t i c Functions SIN, COS, ATN, EXP, FIX, FLOAT, INT, RND, SGN, SQR, LOG INBSIC. S R S t r i n g Functions CHR$, DAT$, LEN, POS, SEG$, STR$, VAL, Error p r o c e s s i n g , TRC ASC, INBSIC. FF F i l e Functions CHAIN, CLOSE, FILE Note t h a t t h e o v e r l a y d r i v e r r e a d s i n a new o v e r l a y o n l y i f t h e o v e r l a y c u r r e n t l y r e s i d e n t does n o t c o n t a i n t h e f u n c t i o n s p e c i f i e d i n a given f u n c t i o n c a l l . I f t h e f u n c t i o n c a l l i s f o r a f u n c t i o n which i-s found i n t h e c u r r e n t l y r e s i d e n t o v e r l a y , no o v e r l a y I / O t a k e s place. NOTE On TD8E's i n t e r r u p t s are d i s a b l e d d u r i n g t h e I / O f o r overlays. 11-3 11.3.3 INBRTS Symbol Tables INBRTS locates v a r i a b l e s and s t r i n g s a t runtime v i a f o u r permanently These tables, which always r e s i d e i n t h e r e s i d e n t symbol tables. h i g h e s t core f i e l d , are t h e S c a l a r Table ( f o r variables l i k e A, B l ) , t h e Scalar Array Table ( A ( 1 ) , B ( 1 , 1 ) ) t h e S t r i n g Symbol Table (AS, Al$), and t h e S t r i n g Array Table, ( B l S ( 2 ) ) . A more detailed d e s c r i p t i o n of t h e s t r u c t u r e of t h e s e tables can be found i n S e c t i o n 11.5. , 11.4 11.4 DATA FORMATS . 1 Variables V a r i a b l e s are s t o r e d i n core as s t a n d a r d 3-word numbers. The f i r s t word i s a s i g n e d , 2's complement t h e second and t h i r d words r e p r e s e n t t h e s i g n e d , floating point exponent, w h i l e 2's complement mantissa. I LOW MANTISSA I f HIGH MANTISSA f exponent S i n g l e v a r i a b l e s are stored as 3-word entries i n t h e S c a l a r Table. Arrays are s t o r e d i n core as successive 3-word entries, w i t h t h e f i r s t s u b s c r i p t varying t h e f a s t e s t , and A(0,O) occupying t h e lowest core address. The a d d r e s s and f i e l d of A(0,O) are s p e c i f i e d i n t h e S c a l a r Array Table. The s t r u c t u r e of t h e symbol t a b l e s i s d e s c r i b e d i n S e c t i o n 11.5. A (M-2 , N ) 11-4 Strings 11.4.2 S t r i n g s are s t o r e d as 6-bit A S C I I c h a r a c t e r s , w i t h a c h a r a c t e r c o u n t as t h e f i r s t word of t h e s t r i n g . The l e f t h a l f of e a c h c h a r a c t e r word i s used f i r s t , w i t h unused c h a r a c t e r s padded w i t h s p a c e s (40(8)). The c h a r a c t e r c o u n t i s a s i g n e d , 2 ' s complement number r e p r e s e n t i n g t h e a c t u a l number of c h a r a c t e r s i n t h e s t r i n g , n o t t h e number of words devoted t o t h a t s t r i n g . Each s t r i n g i s a l l o c a t e d [INT(T)+l] n+l words, where n i s t h e maximum l e n g t h s p e c i f i e d i n a t h a t many words a r e a c t u a l l y used o r n o t . BAS I C I t I' DIM statement, whether BRTS count f o r C I' I) count f o r next s t r i n g BA It count __c 7773 "TS" 'I 7774 BR " count The minimum s t r i n g i s one c h a r a c t e r long. The a d d r e s s of t h e c o u n t word f o r each s t r i n g i s p o i n t e d t o by i t s e n t r y i n t h e S t r i n g Symbol Table. S t r i n g a r r a y s are s t o r e d as s u c c e s s i v e s t r i n g s , w i t h A$(O) occupying t h e lowest core address. Each s t r i n g i s a l l o c a t e d enough s p a c e f o r i t s maximum l e n g t h , even though a l l of t h i s space may n o t be used. I I I I I I 1 I count n+l I N T (-) count 11-5 2 words where n i s t h e maximum l e n g t h of string specified i n D I M statement NOTE For any of t h e above d a t a t y p e s , a f i e l d boundary may f a l l anywhere w i t h i n any Routines t h a t use individual i t e m . s u c c e s s i v e words i n any data i t e m must be c a r e f u l t o check f o r a f i e l d boundary within t h a t i t e m . In-core DATA l i s t 11.4.3 The in-core DATA l i s t i s stored as s e q u e n t i a l d a t a i t e m s i n core. S t r i n g s again are devoted even numbers of words, and are p r e f i x e d by a count. There i s no s e p a r a t o r or i d e n t i f i e r o f DATA i t e m s and t h e DATA l i s t is always i n t h e h i g h e s t core f i e l d . A page 0 , f i e l d 0 p o i n t e r t o t h e s t a r t i n g a d d r e s s of t h e DATA l i s t less 1 i s maintained a t DLSTRT, and t h e address of t h e l a s t word o f t h e l i s t can be found a t DLSTOP . Example : In BASIC: DATA 1 I 2 , "THREE" I 4 In core: FIELD N 'I string count 4 THREE 7773 2 FIELD fl D h 1 STARTING ADDRESS O F DATA L I S T + I I &------I 11-6 4 DLSTRT word i n DATA l i s t P o i n t e r t o DATA l i s t -1 11.4.4 The S t r i n g Accumulator (SAC) as one The of the o p e r a t i o n s , and t h e r e s u l t is always l e f t i n t h e SAC. s t r i n g accumulator i s t o s t r i n g s as t h e hardware AC i s t o PDP-8 instructions. The SAC s t a r t s a t location SAC f o r 36 words (72 c h a r a c t e r s ) , and t h e l e n g t h of t h e s t r i n g c u r r e n t l y i n t h e SAC i s s t o r e d as a n e g a t i v e number i n STRLEN. A page 0 p o i n t e r t o t h e s t a r t o f t h e SAC less 1 i s maintained a t SACPTR. A l l INBRTS s t r i n g o p e r a t i o n s use t h e S t r i n g Accumulator (SAC) 11.5 INBRTS SYMBOL TABLE STRUCTURE The INBRTS symbol tables all r e s i d e i n t h e h i g h e s t core f i e l d . A CDF t o t h e symbol table f i e l d can be found i n l o c a t i o n CDFIO of f i e l d 0. 11.5.1 The S c a l a r Table The S c a l a r Table is t h e h i g h e s t symbol t a b l e i n c o r e , and i t c o n s i s t s of successive 3-word entries, each e n t r y c o n t a i n i n g a 3-word f l o a t i n g - p o i n t number. One e n t r y e x i s t s f o r each v a r i a b l e used i n t h e program, and a few e x t r a e n t r i e s are used as temporaries. A p o i n t e r t o t h e s t a r t of t h e S c a l a r Table can be found a t l o c a t i o n SCSTRT of f i e l d 0. The scheme f o r s c a l a r v a r i a b l e s is as follows: FIELD X Scalar Table F d F l FIELD 0 CDFIO I CDF X 1- Variable A I SCSTRT SCALAR TABLE 11.5.2 The Array Symbol T a b l e The Array Symbol Table c o n s i s t s of s u c c e s s i v e 4 - word e n t r i e s , each e n t r y s p e c i f y i n g t h e l o c a t i o n and s i z e of an a r r a y used i n t h e program. Each e n t r y i s as follows: DIMENSION 2 DIMENSION 1 POINTER TO A ( 0 , O ) 11-7 The first word o f each e n t r y i s a 1 2 - b i t p o i n t e r t o t h e l o c a t i o n o f t h e exponent word of t h e f i r s t element i n t h e a r r a y . The second word i s a CDF N where N i s the f i e l d f o r t h e p o i n t e r i n t h e f i r s t word. The t h i r d word i s t h e f i r s t dimension of t h e a r r a y ( o b t a i n e d by adding 1 t o t h e M i n a D I M A ( M , N ) s t a t e m e n t because t h e f i r s t s u b s c r i p t i s always 0 ) , and t h e l a s t word i s t h e second dimension o f t h e a r r a y ( o b t a i n e d by adding 1 t o t h e N i n t h e aforementioned D I M s t a t e m e n t f o r I f t h e a r r a y i s uni-dimensional, t h e second t h e same r e a s o n ) . To l o c a t e t h e n t h element i n t h e a r r a y , INBRTS dimension i s zero. performs the following c a l c u l a t i o n : A d d r of A(M,N)=3*[M+(DIM1+1)*N]+Addr of A ( 0 , O ) A p o i n t e r t o t h e s t a r t of t h e Array Symbol Table less 1 ( f o r u s e i n an The index r e g i s t e r ) can be found i n f i e l d 0 a t l o c a t i o n ARSTRT. scheme f o r a r r a y s is: I I I. I Array Symbol Tab l e (FIELD X) Array CDF Y A(M,N) ~ 1) I I CDF10 I (FIELD Y) I CDF X FIELD J8 ARSTRT 11.5.3 The S t r i n g Symbol T a b l e The S t r i n g Symbol T a b l e has s u c c e s s i v e three-word 11-8 e n t r i e s as follows: -MAXIMUM # OF CHARS I N STRING CDF FOR STRING POINTER TO STRING The f i r s t word is a 1 2 - b i t p o i n t e r t o t h e c o u n t word o f t h e s t r i n g . The second word o f each e n t r y i s a CDF f o r t h a t c o u n t word, and t h e t h i r d word o f t h e e n t r y i s t h e maximum l e n g t h of t h e s t r i n q ( i n number n e g a t i v e number. A of c h a r a c t e r s ) s t o r e d as a 2's complement p o i n t e r t o t h e s t a r t of t h e S t r i n g Symbol Table ( l e s s 1) can be found i n f i e l d 0 location STSTRT. N o t e t h a t t h e maximum number o f c h a r a c t e r s i n t h e s t r i n g r e p r e s e n t s t h e amount of s p a c e a l l o c a t e d f o r t h e s t r i n g ; t h e amount of s p a c e a c t u a l l y used i s r e p r e s e n t e d by t h e c o u n t word which i s s t o r e d w i t h t h e s t r i n g . , The scheme for simple s t r i n g s i s : INT (max. l e n g t h + l ) +1 2 words long I String Symbol Table (FIELD X) -MAX LENGTH I I entry 2 CDF Y String A$ POINTER TO A$ (FIELD Y ) .* - entry 1 COUNT FOR A$ I L ---------------FIELD 11.5.4 I( CDF10 f> CDF X STSTRT 1 POINTER TO STRING SYMBOL T A B L E - 1 1 The S t r i n g Array T a b l e The S t r i n g Array T a b l e c o n s i s t s of c o n s e c u t i v e 4-word each e n t r y as follows: DIMENSION O F A$(O) -MAXIMUM #OF CHARS I N A$ (0) CDF FOR A$ (0) POINTER TO A$ (0) 11-9 entries, with , The f i r s t word contains a p o i n t e r t o t h e c o u n t word of s t r i n g A$(O) and t h e second word c o n t a i n s a CDF f o r t h i s count. The t h i r d word h a s t h e maximum l e n g t h ( i n c h a r a c t e r s ) of each element i n t h e array s t o r e d as a 2 ' s complement n e g a t i v e number. The l a s t word c o n t a i n s t h e dimension o f t h e s t r i n g a r r a y , o b t a i n e d by adding 1 t o t h e M i n a D I M s t a t e m e n t of t h e form D I M A$(M,N) because t h e f i r s t element i s always A$ ( 0 ) . A p o i n t e r t o t h e s t a r t o f t h e S t r i n g Array Table less 1 can be found i n f i e l d 0 a t l o c a t i o n SASTRT. The scheme f o r s t r i n g a r r a y s is: String Array Table M+1 (FIELD entry 2 -N CDF Y COUNT POINTER TO AS ( B ) - entry 1 FIELD PI S t r i n g Array AS ( M t N ) (FIELD Y) AS (8) COUNT i CDF10 I CDF X SASTRT I POINTER TO START O F S T R I N G ARRAY TABLE -1 1 To locate t h e n t h element of t h e s t r i n g array, INBRTS performs the f o l l o w i n g calculation: addr of A$(N)=addr where Z = i n d i v i d u a l element l e n g t h 11.6 . FLOATING-POINT PACKAGE The INBRTS f l o a t i n g - p o i n t package i s permanently r e s i d e n t , and as such it is r e a d i l y a v a i l a b l e f o r use by assembly language r o u t i n e s f o r floating-point c a l c u l a t i o n s . 11.6.1 F l o a t i n g - P o i n t Accumulator One o f t h e operands of e v e r y f l o a t i n g - p o i n t o p e r a t i o n i s t h e F l o a t i n g Accumulator (FAC) , and t h e r e s u l t of a l l f l o a t i n g - p o i n t o p e r a t i o n s (except FPUT) i s always l e f t i n t h e FAC. The FAC i s found a t EXP HORD, and LORD on page 0 w i t h s t a n d a r d PDP-8 23-bit f l o a t i n g - p o i n t 11-10 format: LORD LOW MANT I S S A - H I G H MANTISSA mantissa exponent The f l o a t i n g - p o i n t accumulator i s t o f l o a t i n g - p o i n t i n s t r u c t i o n s what t h e hardware accumulator i s t o PDP-8 machine language i n s t r u c t i o n s . F l o a t i n g - P o i n t Routines 11.6.2 The f o l l o w i n g f l o a t i n g - p o i n t r o u t i n e s are s u b r o u t i n e use : Function S t a r t i n g Address ADD SUBTRACT MULTIPLY DIVIDE INVERSE SUBTRACT INWRSE D I V I D E LOAD FAC STORE FAC available for user Operation FFADD FAC+FAC+OPERAND FFSUB FFMPY FFDIV FACeFAC-OPERAND FACyFAC *OPE RAND FAC+FAC/OPEFWND FAC+OPERAN D- FAC FACI-OPE FWD/FAC FAC+OPERAND OPE RAND+FAC FFSUBl FFDIVl FFGET FFPUT The symbol "+" means "is replaced by". Note t h a t t h e store f u n c t i o n (FFPUT) i s t h e o n l y o p e r a t i o n i n which t h e r e s u l t i s n o t l e f t i n t h e FAC Note a l s o t h a t FFPUT i s a n o n - d e s t r u c t i v e store, i.e., t h e FAC i s t h e same a f t e r t h e store o p e r a t i o n as b e f o r e . There are two c a l l i n g sequences f o r t h e f l o a t i n g - p o i n t r o u t i n e s , e a c h Mode w i t h a d i f f e r e n t method f o r p a s s i n g t h e address of t h e operand. 1 is t h e m o s t e f f i c i e n t , and can b e used whenever t h e operand is i n field 0. Mode 2 is t h e f i e l d independent c a l l , b u t i s more core e x p e n s i v e t h a n mode 1. The m o d e b e i n g used i s determined as f o l l o w s : 1. I f t h e c o n t e n t s of the AC i s non-zero on e n t r y , t h e i s m o d e 2. 2. I f the c o n t e n t s of t h e AC i s zero on e n t r y , t h e l o c a t i o n FF examined. I f FF i s a l s o z e r o , m o d e 1 is t h e c a l l i n g mode. FF i s non-zero, mode 2 i s used. mode used The c a l l i n g modes are as follows: Mode 1 - address of operand follows c a l l t o f l o a t i n g - p o i n t r o u t i n e . CLA DCA FF /SWITCH 11-11 FF=O FOR MODE 1 is If JMS I POINTER ... (operand a d d r e s s ) /JUMP TO FLOATING-POINT ROUTINE /12 B I T ADDRESS OF OPERAND POINTER,(starting a d d r e s s ) Mode 2 - /FLOATING- POINT ROUTINE /STARTING ADDRESS. address of operand i n AC on c a l l t o f l o a t i n g - p o i n t routine. CLA IAC DCA FF CDF N TAD OPADDR JMS I POINTER (unused) POINTER, ( s t a r t i n g a d d r e s s ) OPADDR, (operand) /FF SWITCH NOT EQUAL TO o FOR /MODE 2 /DF TO FIELD OF OPERAND /ADDRESS OF OPFRAND /JUMP TO FLOATING-POINT ROUTINE /THIS LOCATION UNUSED /RETURNS HERE. /ADDRESS OF FLOATING-POINT ROUTINE /ADDRESS OF OPERAND Both modes return w i t h a c l e a r AC and t h e data f i e l d set t o 0 . Note t h a t t h e s w i t c h FF i s n o t a l t e r e d by t h e r o u t i n e s t h e m s e l v e s , hence it i s o n l y n e c e s s a r y t o set i t when d e s i r e d t o change modes, n o t b e f o r e e v e r y call. The mode 2 c a l l always r e t u r n s t o t h e second i n s t r u c t i o n f o l l o w i n g t h e c a l l , s k i p p i n g the word -following t h e JMS. S i n c e t h i s word i s completely unused, it i s a good location f o r constant s t o r a g e . JMS The FF s w i t c h is n e c e s s i t a t e d by t h e s p e c i a l case when i t i s d e s i r e d t o r e f e r e n c e an operand l o c a t e d a t l o c a t i o n 0 i n a f i e l d o t h e r t h a n field 0. I f t h e FF s w i t c h were n o t p r e s e n t , t h e f l o a t i n g - p o i n t package would examine t h e AC, f i n d i t empty, and u s e t h e a d d r e s s i n t h e word f o l l o w i n g t h e c a l l , s i n c e t h e r e i s no way o f d i s t i n g u i s h i n g an empty AC from an operand a d d r e s s of 0 loaded i n t o t h e AC. The FF s w i t c h , t h e n , i s used t o t e l l t h e f l o a t i n g - p o i n t package whether t h e zero AC m e a n s "mode 1 c a l l " o r "operand a t 0 " . INBRTS m a i n t a i n s l i n k s f o r FGET and FPUT on page 0 of f i e l d p r o v i d i n g convenient access t o t h e s e f r e q u e n t l y used r o u t i n e s . Page 0 Link N a m e Routine Linked FGETL FPUTL FFGET FFPUT Examples : Some examples of INBRTS f l o a t i n g - p o i n t code: 1. Routine t o calculate X + 2 + 2 X + 1 . . CLA 11-12 0, DCA FF JMS I FGETL X JMS I FMPYLK X JMS I FPUTL Y J M S I FGFTL /OPERAND ADDRESS WILL /FOLLOW CALLS (MODE 1) /LINK I S ON PAGE 0 /x * x /SAVE X42 /LOAD X AGAIN n JMS I FMPYLK TWO JMS I FADDLK /2x+1 ONE JMS I FADDLK Y /X'42+2X+1 . . 0 FADDLK FMPYLK Two , , FFADD FFMPY 0002 2000 0000 0001 2000 0000 ? ONE , x, /2 x /RESULT NOW I N FAC /LINK TO ADD ROUTINE /LINK TO FLOATING MULTIPLY /FLOATING POINT CONSTANT /2.0 /FLOATING POINT CONSTANT /1.0 /VARIABLE 0 . . 0 . . 0 . . Y /FLOATING-POINT 0 0 0 2. TEMPORARY Rou-ine -0 at 1 5 successive floating-point numbers s t a r t i n g a t location 0 of f i e l d 2. START ALOOP , , MINUS5 , FADDLK , OPADDR K3I , CLA DCA OPADDR J M S I FCLR IAC DCA FF CDF 20 TAD OPADDR JMS I FADDLK -5 TAD OPADDR TAD K 3 DCA OPADDR IAZ MINUS5 JMP ALOOP HLT FFADD 0 3 / /FIRST OPERAND AT LOCATION 0 /ZERO FAC /CALLS ARE MODE 2 /OPERAND ADDR I N AC /CALL ADD ROUTINE /LOCATION UNUSED, S O WE USE / I T AS A COUNTER /UPDATE OPERAND ADDFESS /DONE? /NO /YES-ANSWER I N FAC. POINTER TO ADD ROUTINE /POINTER TO OPERAND /EACH OPERAND I S 3 WORDS LONG. 11-13 F l o a t i n g - P o i n t Operations 11.6.3 There are also f o u r simple f l o a t i n g - p o i n t o p e r a t i o n s t h a t t h e FAC and are a v a i l a b l e t o user s u b r o u t i n e s . Function S t a r t i n g Address NEGATE NORMALIZE FFNEG FFNOR FFSQ FACCLR SQUARE CLEAR operate on Operation FAC+-FAC NORMAL1 Z E*FAC FAC-AC FAC4 *FAC These f u n c t i o n s are a l l called by simple JMS, and r e t u r n w i t h t h e Page 0 Links are maintained f o r n e g a t e , n o r m a l i z e , and hardware AC=O. clear. Page 0 Link Routine F'NEGL FFNEG FFNOR FACCLR FNORL FCLR 11.7 INBRTS SUBROUTINES There are several subroutines i n INBRTS which can be u s e f u l t o assembly language f u n c t i o n s . A d i s c u s s i o n of each of t h e s e r o u t i n e s follows. They are i d e n t i f i e d i n t h e d i s c u s s i o n by t h e t a g f o r t h e i r s t a r t i n g a d d r e s s , and a l l t a g s r e f e r r e d t o can b e found i n t h e symbol table. 11.7.1 Subroutine ARGPRE Subroutine ARGPRE i s used t o locate scalar Table. When c a l l e d , it u s e s t h e r i g h t m o s t 8 b i t s (0-225 decimal) o f location INSAV as t h e e n t r y number t o be found, and on r e t u r n , t h e d a t a f i e l d i s s e t t o t h e f i e l d o f t h e variable and t h e AC p o i n t s t o t h e exponent word o f t h e variable. ARGPRE is c a l l e d v i a a JMS, and is used most o f t e n i n p a s s i n g arguments t o and from t h e u s e r s u b r o u t i n e . (See S e c t i o n 11.8) Example: Load t h e FAC w i t h t h e t h i r d variable i n t h e S c a l a r Table. CLA TAD C2 DCA INSAV IAC DCA FF JMS I ARGPRL JMS I FGETL (unused) HLT c2 I ARGP RL , /WE WANT ENTRY # 3 , BUT /SINCE THE FIRST ONE IS 0 , /LOAD INSAV WITH 2 /SET FF SWITCH /CALL ARGPRE /THE AC AND DATA FIELD /ARE SET, S O THIS IS A /MODE 2 CALL. 2 ARGPRE 11-14 11.7.2 Subroutine XPUTCH Subroutine XPUTCH i s u s e d - t o p u t ASCII c h a r a c t e r s i n t o t h e t e r m i n a l ring buffer, When c a l l e d , t h e 8 - b i t ASCII c h a r a c t e r is i n t h e On r e t u r n , t h e AC i s c l e a r e d . Note that r i g h t m o s t 8 b i t s o f t h e AC. u n l e s s t h e r i n g b u f f e r i s empty, XPUTCH does n o t cause any c h a r a c t e r s t o be p r i n t e d ; it merely p l a c e s t h e c h a r a c t e r i n t h e t e r m i n a l r i n g buffer. I f t h e r i n g b u f f e r i s f u l l t h e system w i l l w a i t u n t i l i t can p l a c e t h e c h a r a c t e r i n t h e r i n g b u f f e r . A page 0 l i n k t o XPUTCH i s maintained a t l o c a t i o n XPUT. Example : Put a carriage r e t u r n / l i n e f e e d combination i n buffer. terminal /LOAD CR INTO AC /CALL XPUTCH V I A PAGE 0 L I N K /LOAD LINE FEED INTO AC /PUT I N BUFFER CLA TAD 0215 J M S I XPUT TAD K212 JMS I XPUT K215, K212, the . /ASCII CODE FOR CR /ASCII CODE FOR LF 215 2 12 . Subroutine PSWAP 11,7 3 Under normal c o n d i t i o n s , INBRTS r u n s w i t h t h e OS/8 page 17600 p o r t i o n of t h e r e s i d e n t monitor moved t o t h e h i g h e s t page o f c o r e (second h i g h e s t page i f TD8/E system). PSWAP i s used t o swap t h i s page back Prior t o calling and f o r t h p r i o r t o doing any o p e r a t i o n s w i t h OS/8. OS/8, PSWAP should be used t o restore t h e page 17600 r e s i d e n t t o 17600, and when OS/8 o p e r a t i o n s are complete, PSWAP should be c a l l e d a g a i n t o swap t h e 17600 r e s i d e n t back up t o h i g h core. A page 0 l i n k t o PSWAP i s maintained a t location PlSWAP, Example: The following code uses t h e USR i n OS/8 t o perform on the f i l e BASIC.DA on t h e systems device. . . CLA JMS I PlSWAP CLA IAC CIF 1 0 JMS I K7700 2 mm 0 HLT J M S I PlSWAP /AC SHOULD BE 0 ON CALL /RESTORE OS/8 PAGE 17600 RESIDENT /DEVICE # FOR SYS: IS 1 /CALL USR /LOOKUP /POINTER TO FILE NAME /CONTAINS LENGTH ON RETURN /ERROR RETURN /SWAP OS/8 RESIDENT BACK /TO H I G H CORE . 11-15 a LOOKUP NOTE I f PSWAP i s used, it must be executed an When t h e assembly even number o f t i m e s . language f u n c t i o n i s c a l l e d , t h e page 17600 r e s i d e n t i s a t h i g h core; when t h e f u n c t i o n r e t u r n s t o INBRTS, t h e 17600 r e s i d e n t must be back i n high core. On TD8E systems interrupts should be disabled before calling PSWAP and reenabled a f t e r l a s t c a l l . Subroutine UNSFIX 11.7.4 Subroutine UNSFIX i s used t o f i x a p o s i t i v e , 1 2 - b i t , magnitude o n l y i n t e g e r from t h e FAC and r e t u r n w i t h t h e r e s u l t i n t h e hardware AC. The range of t h e f i x e d i n t e g e r i s 0-4095; an a t t e m p t t o f i x a number l a r g e r t h a n 4095 o r a n e g a t i v e number w i l l cause a n "FO" o r 'IFM" error, r e s p e c t i v e l y . UNSFIX i s c a l l e d v i a simple JMS, and a page 0 l i n k t o UNSFIX i s maintained, c a l l e d INTL. UNSFIX d e s t r o y s t h e c o n t e n t s of t h e FAC. Example: The f o l l o w i n g code u s e s t h e FAC1 as a count of t h e number t i m e s t o r i n g t h e b e l l on t h e t e r m i n a l . of . . BELLOP , CLA JMS I INTL CIA DCA COUNTR TAD K207 JMS I XPUT ISZ COUNTR JMP BILLOP . K207, . 11.7 5 /FIX THE FAC TO 12-BIT INTEGER /NEGATE THE INTEGER /AND STORE AS COUNT /ASCII FOR BELL /PUT I N RING BUFFER /RIGHT NUMBER YET? /NO-RING ANOTHER BELL 20 7 Subroutine STFIND Subroutine STFIND i s used t o locate a s t r i n g v a r i a b l e o r t h e f i r s t When c a l l e d , i f t h e l i n k i s non-zero, element of a s t r i n g a r r a y . STFIND l o o k s f o r an e n t r y i n t h e S t r i n g Array Table. I f t h e l i n k is z e r o , STFIND uses t h e S t r i n g Symbol T a b l e . For s t a n d a r d s t r i n g v a r i a b l e s , the r i g h t m o s t 8 b i t s o f l o c a t i o n INSAV are used as t h e number of the e n t r y t o be obtained; for s t r i n g array variables t h e l a s t 5 b i t s are used. On r e t u r n s from STFIND, t h e AC c o n t a i n s a CDF t o t h e f i e l d o f t h e s t r i n g s p e c i f i e d , l o c a t i o n STRPTR p o i n t s t o t h e f i r s t word (count word) o f t h e s t r i n g , l o c a t i o n STRMAX h o l d s t h e m a x i m u m l e n g t h of t h e s t r i n g (as a n e g a t i v e number), and location STRCNT contains t h e actual number o f c h a r a c t e r s i n t h e s t r i n g (as a n e g a t i v e number). STFIND i s used m o s t o f t e n i n p a s s i n g arguments t o and from u s e r f u n c t i o n s . 11-16 Examples : 1. To f i n d s t r i n g number 7 TAD K6 DCA INSAV CLL JMS I S T F I N L K6, 6 STFINL, STFIND 2. . , 11.7.6 o To f i n d t h e f i r s t element of s t r i n g a r r a y number 2. TAD K 1 DCA INSAV CLL CML JMS I S T F I N L K1, STFINL /THE NUMBERING STARTS WITH /SET UP STFIND POINTER /WE WANT SIMPLE STRING /CALL STFIND /THE SECOND ENTRY /WE WANT STRING ARRAY /CALL STFIND 1 STFIND Subroutine BSW Subroutine BSW i s used t o swap t h e two h a l v e s of t h e hardware AC. BSW i s c a l l e d by a simple JMS, and a page 0 l i n k c a l l e d BSWL i s maintained. 11.7.7 Subroutine MPY Subroutine MPY i s a 12-by-12-bit b i n a r y m u l t i p l y r o u t i n e . The AC i s m u l t i p l i e d by t h e c o n t e n t s of l o c a t i o n TEMP3 ( b o t h numbers are t r e a t e d as 1 2 - b i t , unsigned i n t e g e r s ) , and on r e t u r n , t h e high-order b i t s of t h e r e s u l t are i n TEMP6, and t h e low-order b i t s of t h e r e s u l t a r e i n t h e AC. The page 0 l i n e t o MPY i s MPYLNK. 11.7.8 Subroutine DLREAD S u b r o u t i n e DLREAD i s used t o r e a d t h e n e x t w o r d of t h e i n c o r e DATA l i s t i n t o t h e AC. I f t h e r e i s no m o r e d a t a i n t h e DATA l i s t , a DA error message r e s u l t s . Example: Read t h e n e x t number from t h e DATA l i s t i n t o t h e FAC. CLA JMS I DLREAL DCA EXP JMS I DLREAL DCA HORD JMS I DLREAzl DCA LOSR .. DLREAL, /READ EXPONENT WORD INTO AC /STORE I N FAC /READ HIGH MANTISSA FROM L I S T /STORE HIGH MANTISSA WORD /READ LOW MANTISSA FROM L I S T /STORE LOW MANTISSA WORD DLREAD 11-17 . 11 7.9 Subroutine ABSVAL Subroutine ABSVAL i s used t o t a k e t h e a b s o l u t e v a l u e of t h e FAC. If t h e FAC i s p o s i t i v e , ABSVAL i s e s s e n t i a l l y a NOP; i f t h e FAC i s n e g a t i v e , i t i s negated b e f o r e r e t u r n . 11.8 P A S S I N G ARGUMENTS TO THE USER FUNCTION INBRTS c a l l s t h e u s e r assembly language f u n c t i o n w i t h a JMP instruction. P r i o r t o e x e c u t i n g t h a t J M P , it p l a c e s t h e f i r s t numeric argument i n t h e FAC, t h e second i n Scalar Table e n t r y 0 , t h e t h i r d i n Scalar T a b l e e n t r y 1, etc., u n t i l t h e argument l i s t i s satisfied. If any s t r i n g arguments are used, t h e f i r s t i s found i n t h e SAC and t h e second is p o i n t e d t o by S t r i n g Table e n t r y 0. The u s e r f u n c t i o n o b t a i n s t h e s e arguments as needed by c a l l i n g t h e r o u t i n e s ARGPRE and STF’ND a p p r o p r i a t e l y . A l l u s e r f u n c t i o n s occur i n FIELD 1. FIELD 1 core usage i s as follows: I I BASIC 12400 BASIC CODE USER FUNCTIONS FILE I / O 12000 BASIC CODE FILE I / O NON-INTERRUPTING USER FUNCTIONS 11400 I PROCESS I / O I 10000 The p r o c e s s I/O area which e x t e n d s up t o 1 4 0 0 i n f i e l d 1 i s used by The area from 1 4 0 0 t o 1777 i n f i e l d 1 i s a t h e real-time f u n c t i o n s . s h a r a b l e area: I f any f i l e I / O i s done, t h i s area w i l l be allocated f i r s t f o r t h e b u f f e r space: i f no f i l e I / O i s done, t h i s area may be used f o r n o n - i n t e r r u p t i n g u s e r f u n c t i o n s . F i n a l l y , i f no f i l e I / O or non-interrupting u s e r f u n c t i o n s are b e i n g used, BASIC i n t e r p r e t i v e code can extend i n t o these l o c a t i o n s . T h e area f r o m 2000 to 2 3 7 7 i n f i e l d 1 i s another sharable area: If 2 f i l e s are needed a t runtime, t h i s w i l l be t h e second area allocated: i f t h i s area i s n o t needed f o r 2 f i l e s , l a r g e BASIC programs can u s e t h i s area f o r extended core, o r i t may be used as a r e s i d e n t area f o r any t y p e s o f u s e r f u n c t i o n s . Users adding t h e i r own f u n c t i o n s t o t h e BASIC Run-Time System have to provide i n f o r m a t i o n t o INBRTS so it may handle core -_ c o r r e c t l y . T h i s w i l l be d e t a i l e d later. 11-18 11.8.1 I n t e r f a c i n g FIELD 1 Code w i t h FIELD 0 S u b r o u t i n e s For convenience a r o u t i n e r e s i d e s i n FIELD 0 (CALLFO) which w i l l a c c e p t t h e word following t h e J M S as t h e FIELD 0 s u b r o u t i n e t o c a l l . An argument can be passed t o t h e subroutine i n t h e AC. Return t o FIELD 1 occurs a t argument: +l. The sequence looks as follows: I n FIELD 1 TAD AC CIF 0 JMS I [CALLFO subroutine t o call r e t u r n occurs h e r e w i t h Data FIELD-1 The f o l l o w i n g f u n c t i o n t a k e s t h e f i r s t t w o numeric performs t h e operation on them s p e c i f i e d i n A$: arguments and for and UDEF EXM(X,A$,Y) LET Z=EXM ( 2 , "PLUS" ,1) Legal values f o r A$ are s t r i n g s beginning w i t h " M I " f o r "MINUS". "PL" "PLUS" I f t h e f u n c t i o n i s t o r e t u r n any value, t h a t value should be l e f t i n t h e FAC on r e t u r n . The u s e r f u n c t i o n must always r e t u r n by a JMP I ILOOP i n FIELD 0 w i t h t h e d a t a FIELD 0. To g e n e r a t e a f a t a l I A ( i l l e g a l argument) error message, perform a JMP t o location I A i n INBRTS. /ENTRY POINT, DATA FIELD=O Em, DCA I (INSAV TAD I FlSACP TAD PL /INITIALIZE FOR ARG 0 /GET FIRST 2 CHARS OF A$ FROM SAC SZA CLA JMP EMINUS CIF 0 JMS I (CALLFO ARGPRE CIF0 JMS I (CALLFO FFADD RETURN, CDF CIF 0 JMP I (ILOOP EMINUS, TAD I FlSACP TAD M I SNA CLA JMP ISMINS CIF CDF 0 JMP I ( I A ISMINS, CIF 0 JMS I (CALLFO ARGPRF, 11-19 CIF 0 JMS I (CALLFO FFSUB JMP RETURN PL * MII -20 14 -1511 11.8.2 Using t h e USE Statement I f t h e assembly language f u n c t i o n needs t o know t h e l o c a t i o n o f an a r r a y ( f o r b u f f e r space, m u l t i p l e argument p a s s i n g , a r r a y argument), The USE s t a t e m e n t p l a c e s t h e o c t a l t h e USE s t a t e m e n t i s necessary. number f o r t h e a r r a y s p e c i f i e d i n t o l o c a t i o n USECON. By u s i n g t h i s v a l u e as an index i n t o t h e Array Symbol Table, t h e a r r a y s p e c i f i e d can be l o c a t e d and used by t h e assembly language f u n c t i o n , as necessary. For example: The h y p o t h e t i c a l assembly language f u n c t i o n PLT r e q u i r e s a 100-word b u f f e r , To a s s u r e a l l o c a t i o n o f t h i s b u f f e r , t h e BASIC u s e r of PLT i s i n s t r u c t e d t o dimension a 34-element a r r a y and use it i n a USE s t a t m e n t b e f o r e c a l l i n g t h e PLT f u n c t i o n . In BASIC: 10 20 30 40 REM DEFINE THE USER FUNCTION UDEF PLT (X,Y) REM ALLOCATE A 34 ELEMENT ( 1 0 2 WORDS) ARRAY FOR A BUFFER DIM B ( 3 4 ) i 100 USE 110 Y=PLT (3,2.8) . 0 The f u n c t i o n PLT f i n d s B as f ollotm : PLT , TAD USECON CLL RTL TAD ARSTRT DCA XR5 TAD CDF10 DCA .+I TAD I XR5 DCA BPTR TAD I X R 5 DCA BCDF TAD I XR5 DCA DIM1 TAD I XR5 DCA DIM2 /GET ENTRY NUMBER O F B /MULTIPLY BY 4 (EACH ARRAY TABLE /ENTRY I S 4 WORDS LONG) /MAKE POINTER INTO ARRAY TARLE /AND SAVE I T /GET CDF TO SYMBOL TABLE F I E L D /PUT INTO L I N E /CHANGE DF TO SYMBOL TABLE F I E L D /GET POINTER TO B ( 0 ) /SAVE FOR LATER /GET CDF FOR B (0) /SAVE FOR LATER /GET ARRAY DIPENSION 1 /GET ARRAY DIMENSION 2 0 11-20 N o t e t h a t t h e USE s t a t e m e n t merely p a s s e s an e n t r y number t o t h e assembly language function: a l l a c t u a l parameters must be o b t a i n e d from t h e Array Symbol Table u s i n g t h a t e n t r y number as an index. Note a l s o t h a t t h e p h y s i c a l l o c a t i o n o f a r r a y s passed i n such a f a s h i o n can be almost anywhere i n core, and a f i e l d boundary may f a l l w i t h i n t h e array. 11.9 INBRTS I / O 11.9.1 Terminal I / O INBRTS d r i v e s t h e t e r m i n a l asynchronously by m a i n t a i n i n g a c h a r a c t e r t e r m i n a l o u t p u t b u f f e r and u s i n g i n t e r r u p t s . The procedure i s as follows : 1. C h a r a c t e r s are i n s e r t e d i n t o t h e t e r m i n a l r i n g b u f f e r by c a l l i n g s u b r o u t i n e XPUT. I f t h e r i n g b u f f e r i s f u l l , XPUT w a i t s u n t i l a c h a r a c t e r i s p r i n t e d and a s l o t i s f r e e . 2. INBRTS p r i n t s a c h a r a c t e r from t h e r i n g b u f f e r f l a g comes up. whenever the Assembly language f u n c t i o n s are f r e e t o u s e t h e r i n g b u f f e r v i a XPUT. 11.9.2 INBRTS F i l e Formats BASIC f i l e s are formatted as follows: 1. Numeric f i l e s - Numeric f i l e s are f o r m a t t e d as c o n s e c u t i v e 3-word f l o a t i n g - p o i n t numbers,85 t o each 256-word OS/8 block. The l a s t word i n each block i s unused. There is no end-of-f i l e marker. 2. ASCII F i l e s ASCII f i l e s are s t o r e d i n OS/8 ASCII format, t h a t i s , t h r e e 8 - b i t c h a r a c t e r s packed t o e v e r y t w o words as follows : - ' H I ORDER CHAR 3 CHAR 1 LO ORDER CHAR 3 CHAR 2 11-21 11.9.3 INBRTS B u f f e r Space L o c a t i o n s 11400-12377 i n INBRTS are devoted t o f i l e b u f f e r space. B u f f e r s are a l l o c a t e d as t h e y are needed, t h e lowest f r e e b u f f e r always b e i n g a l l o c a t e d first. A map of c u r r e n t l y a l l o c a t e d b u f f e r s i s maintained on page 0 , c a l l e d BMAP. B i t s i n t h e m a p are on i f t h e b u f f e r is a l l o c a t e d , o f f i f t h e b u f f e r i s f r e e . B i t 1 1 r e p r e s e n t s t h e b u f f e r from 11400-11777, b i t 10 f o r 12000-12377. I f any o f t h e b u f f e r s are not available because t h e pseudo-code or variable s p a c e e x t e n d s below 12400, t h e corresponding BMAP b i t s are set when INBRTS is started. 11.9.4 INBRTS Device D r i v e r Space The o n l y a v a i l a b l e d e v i c e d r i v e r s are t h e r e s i d e n t d e v i c e d r i v e r s . No o t h e r space i s a l l o c a t e d f o r d e v i c e d r i v e r s . On TD8E systems units 0 and 1 are r e s i d e n t , on RK8E systems a l l o f u n i t 0 i s r e s i d e n t . N o t e t h a t assembly language f u n c t i o n s t h a t are used i n programs which do n o t r e q u i r e more than one f i l e open a t once may wish t o u s e some o f t h e b u f f e r space f o r t h e i r own purposes. T h i s space can b e a l l o c a t e d by s e t t i n g a p p r o p r i a t e b i t s i n BMAP, by modifying INBRTS i n i t i a l i z e code ( f o l l o w s TAG TTYBUF) A f t e r t h e b i t s are s e t , INBRTS w i l l n o t use t h i s space i n subsequent FILE commands. . 11.9.5 The INBRTS I / O T a b l e INBRTS keeps t r a c k o f t h e s t a t u s of each of t h e f i l e s which may be open simultaneously by means o f t h e I / O t a b l e . S t a r t i n g a t FILE1, it has t w o 13-word e n t r i e s , l a b e l e d FILE1 and FILE2. Each name corresponds t o t h e number s p e c i f i e d i n t h e f i l e statement which opened t h a t f i l e , and t h e format of each e n t r y is as f o l l o w s : HEADER WORD POSITION OF PRINT HEAD (FOR COLUMN FORMATTING) OR DEVICE NAME MAXIMUM FILE LENGTH OR DEVICE NAME FILE NAME FILE NAME FILE NAME FILE NAME STARTING ADDRESS OF BUFFER ( I N FIELD 1) CURRENT BLOCK I N BUFFER READlWRITE POINTER INTO BUFFER HANDLER ENTRY POINT STARTING BLOCK NUMBER FOR FILE ACTUAL FILE LENGTH The header word bits have significance as follows: B i t Positions Meaning 0-3 OS/8 4-5 C u r r e n t c h a r a c t e r number f o r unpacking ASCII f i l e s 6 0 i f t h e c u r r e n t b u f f e r l o a d h a s n o t been changed 1if number f o r d e v i c e the current 11-22 buffer load has been a l t e r e d 7 0 i f device i s f i l e s t r u c t u r e d 1 i f device i s read/write only 8 0 i f t h e h a n d l e r i s 1 page long 1 i f it i s a 2-page h a n d l e r 9 0 i f f i l e is fixed length 1 i f variable length 10 0 i f more d a t a i n f i l e 1 i f EOF has been seen 11 0 i f f i l e numeric 1 i f f i l e ASCII 11.10 INTERFACING THE ASSEMBLY LANGUAGE FUNCTION TO INBRTS A l l assembly language f u n c t i o n s are r o u t i n e s , c a l l e d by a JMP through t h e U s e r Function Table. This table, which b e g i n s a t l o c a t i o n 1560 i n INBRTS, c o n t a i n s absolute p o i n t e r s t o t h e s t a r t i n g a d d r e s s e s of each of t h e user assembly language f u n c t i o n s . U s e r f u n c t i o n s must be o r i g i n e d t o run i n FIELD 1, and must r e t u r n t o INBRTS v i a a JMP I ILOOPL i n FIELD 0. T o i n t e r f a c e a set o f u s e r f u n c t i o n s t o INBRTS, perform t h e following o p e r a t i o n s : 1. Assemble all the u s e r assembly language functions; t n e e n t r y t o t h e f u n c t i o n s must be i n FIELD 1. E n t r y i s w i t h t h e d a t a FIELD set t o 1. FIELD 1 PAGE 0 s c r a t c h l o c a t i o n s and u s e f u l FIELD 0 are given i n S e c t i o n 11.11.3. pointers .R PAL8 *NWNAME 2. Load t h e user f u n c t i o n s and 1NBRTS.BN i n t o Absolute Loader, and save t h e core image. core with the .R ABSLDR "INBRTS ,USER$ 3. Using O S / 8 ODT, modify t h e U s e r Function Table i n INBRTS which starts a t 1574, e n t e r i n g p o i n t e r s t o t h e u s e r assembly language f u n c t i o n s . Unmodified t a b l e e n t r i e s are 2 3 6 ( 8 ) ; replace t h e s e e n t r i e s with the s t a r t i n g addresses ( p o i n t e r s l t o the u s e r assembly language function. Starting a t location enter the p o i n t e r s i n t h e table i n t h e e x a c t 15748 corresponding o r d e r i n which t h e f u n c t i o n s appear i n t h e UDEF s t a t e m e n t which d e f i n e s them. 11-23 . ODT 1574/236 2000 (LF') 1575/236 2020 tc .SAVE SYS INBRTS 0-7577,lOOOO-lXXXX; 7605 where XXXX r e p r e s e n t s t h e functions. high core address of the user I n t h e procedure above t w o f u n c t i o n s are i n t e r f a c e d which s t a r t a t l o c a t i o n s 2000 and 2010 r e s p e c t i v e l y LF i n d i c a t e s p r e s s i n g the LINE FEED key. . Example: There are t h r e e assembly language f u n c t i o n s i n o u r package, called PLT, H I , and LO. The BASIC u s e r i s i n s t r u c t e d t h a t when h e u s e s t h i s f u n c t i o n package, PLT, H I and LO must be d e f i n e d ' i n t h a t o r d e r . The f u n c t i o n f i l e s , t h e n , look l i k e : Function Source (USER.PA) *2000 HI, /ENTRY POINT FOR HI /ORDER OF ENTRY POINTS IS /NOT CRITICAL . 0 0 PLT , CIF CDFO JMP I [ILOOP /ENTRY FOR PLT . CIF CDFO JMP I [ILOOP Lo, . . /ENTRY FOR LO 0 CIF CDFO JMP I [ILOOP T o e n t e r t h e s e t h r e e f u n c t i o n s i n t o t h e u s e r f u n c t i o n t a b l e i n INBRTS, t h e procedure is: . GET SYS :INBRTS .ODT 1574/236 1575/236 1576/236 PPPP (LF) HHHH (LF) LLLL '4C .SAVE SYS :INBRTS 11-24 where PPPP, HHHH, and U L L r e p r e s e n t o c t a l s t a r t i n g addresses f o r PLT, H I , and LO r e s p e c t i v e l y . LF i n d i c a t e s p r e s s i n g t h e LINE FEED key. NOTE INBRTS e s t a b l i s h e s c a l l s t o t h e u s e r f u n c t i o n by s e t t i n g up a one-to-one correspondence between t h e p o i n t e r s a t 1574 and t h e f u n c t i o n names p r e s e n t i n a UDEF statement. Therefore, t h e order of t h e p o i n t e r s must e x a c t l y correspond t o t h e order of I f t h e BASIC t h e f u n c t i o n d e f i n i t i o n s i n UDEF. u s e r wants t o use only t h e n ( t h ) f u n c t i o n i n a given u s e r package, h e must s t i l l d e f i n e n f u n c t i o n s i n t h e UDEF s t a t e m e n t , though t h e f i r s t n-1 may be dummies. For example: A package of f o u r assembly f u n c t i o n s t h a t u s e arguments as follows. language ONE ( X ) Two ( X , Y ) THR ( X , Y , Z ) FOU ( X , Y , Z , A ) I f a BASIC u s e r wishes t o use only ONE, t h e UDEF would look l i k e : one function 1 0 UDEF ONE (X) I f t h e BASIC u s e r wants t o use f u n c t i o n s FOU, t h e UDEF would look l i k e : ONE and 1 0 UDEF ONE(X) ,DUA(D) ,DUB For this u s e r , DUA and DUB are dummy u s e r f u n c t i o n names which are never called t h e y merely set up t h e r i g h t correspondence between names and pointers. The easiest way t o a s s u r e t h a t t h e p o i n t e r s are e s t a b l i s h e d c o r r e c t l y i s t o provide t h e u s e r of an assembly language f u n c t i o n package w i t h a s e t of complete UDEF s t a t e m e n t s t h a t d e f i n e a l l f u n c t i o n s c o r r e c t l y , and i n s t r u c t him t o use t h e complete s e t o f UDEF's each t i m e . 11.11 GENERAL CONSIDERATIONS AND HINTS 11.11.1 Routines Unusable by Assembly Language Functions Because only one o v e r l a y is r e s i d e n t a t any t i m e , assembly language f u n c t i o n s can only c a l l r o u t i n e s i n t h e o v e r l a y which i s r e s i d e n t when e x e c u t i n g , they cannot use any r o u t i n e s t h a t reside i n any o f t h e t w o o t h e r overlays. Following i s a l i s t of t h e INBRTS f u n c t i o n s and r o u t i n e s grouped by overlay. 11-25 Function Routine N a m e A r i t h m e t i c Overlay FFATN Arctangent Function FFCOS Cosine Function FFE XP EXPON Exponential Function (eX ) B Power Function (A ) INT Signed i n t e g e r Function FFLOG Naperian log Function SGN Sign Function FFSIN Trigonometric S i n e Function RND Random Number g e n e r a t o r FROOT Square root Function S t r i n g Overlay ASC S t r i n g Function ASC CHR CHR$ Function DAT DAT$ Function LEN S t r i n g l e n g t h Function POS S t r i n g s e a r c h Function SEG S t r i n g segmenting Function STR STR$ Function VAL VAL Function TRC Trace Function B i l e Overlay CLOSE OPENAF F i l e manipulation r o u t i n e s OPENAV OPENNF OPENNV 11-26 11.11.2 Using OS/8 So l o n g as t h e assembly language f u n c t i o n i s c a r e f u l l y designed t o p r o t e c t a l l core areas b e i n g used by INBRTS, t h e r e are no r e s t r i c t i o n s Once t h e page 17600 r e s i d e n t monitor on t h e f u n c t i o n ' s use of OS/8. h a s been restored, t h e OS/8 U s e r S e r v i c e Routine (USR) may be c a l l e d a t w i l l , and f i l e s may be located, used, and closed again. If the u s e r ' s BASIC program does n o t need f u l l f i l e c a p a b i l i t i e s , t h e assembly language f u n c t i o n is f r e e t o u s e t h e b u f f e r s p a c e from 11400-12377. The assembly language f u n c t i o n should be c a r e f u l , however, t o check t h e b i t maps and s t a t u s words on page 0 t o make certain a given area i s f r e e b e f o r e u s i n g it. Note t h a t t h e system d e v i c e d r i v e r may be used without r e s t o r i n g t h e page 17600 r e s i d e n t : r e s t o r a t i o n i s only r e q u i r e d when it i s desired t o use t h e USR. 11.11.3 Page 0 Usage Following is a map of t h e INBRTS page 0 usage. Locations marked w i t h an * may be used by t h e assembly language f u n c t i o n w i t h o u t s a v i n g t h e contents . FIELD 0 , PAGE 0 0-2 3- 7 10-15 * 16-17 20-30 30-36 37-62 63-67 73-107 110-161 162-177 Interrupt vector System parameters and temps Index r e g i s t e r s System p o i n t e r s Compiler-INBHTS communieation System r e g i s t e r s F l o a t i n g - p o i n t package area System r e g i s t e r s Constants Links t o INBRTS s u b r o u t i n e s I/O Table pointers FIELD 1, PAGE 0 0- 17 20-33 34-40 Unused ( a v a i l a b l e f o r u s e r ) S c r a t c h Area P o i n t e r s f o r FIELD 0 r o u t i n e s Assembly language f u n c t i o n s are f r e e , o f course, t o u s e any of the p o i n t e r s or c o n s t a n t s , b u t they must be i n t a c t when c o n t r o l i s r e t u r n e d t o INBRTS. 11.12 ASSEMBLY LANGUAGE FUNCTION EXAMPLE To i l l u s t r a t e t h e material i n the p r e v i o u s s e c t i o n s , an example of a complete assembly language f u n c t i o n f o l l o w s . N o t e t h a t t h i s example i s t u t o r i a l i n n a t u r e : it is meant t o i l l u s t r a t e argument p a s s i n g and g e t t i n g along with language f u n c t i o n s . INBHTS rather a t y p i c a l use f o r assembly functions and an a d d i t i o n t o the The f u n c t i o n performed i s r e a d i n g a s t r i n g from The example consists of t w o user i n t e r r u p t s k i p chain. than 11-27 a second t e r m i n a l and s t o r i n g it i n a s t r i n g variable; t h e s t r i n g w i l l be p r i n t e d on t h e main console terminal i f a c a r r i a g e return i s entered. 100 105 110 120 130 140 150 160 170 180 200 2 10 220 2 30 300 310 320 330 340 350 360 37.0 380 1000 1010 1020 1030 10 40 1050 1060 5000 REM REM REM REM REM REM REM REM REM REM DIM T H I S IS A DEMONSTRATION INDUSTRIAL BASIC PROGRAM WHICH WILL RUN COMPUTE BOUND AND ACCEPT CHARACTERS FROM A SECOND TELETYPE U S I N G THE INTERRUPT FACILITY. THE RUN TIME SYSTEM HAS BEEN MODIFIED TO ADD CODE TO THE INTERRUPT S K I P CHAIN AND INSERT THE ADDRESSES OF THE USER FUNCTIONS A$(40) UDEF T T l ( X ) , T T 2 $ ( A $ ) PRINT 'I I M RUNNING" TIMER .1 THEN 1000 FOR I = 1 TO 5 E 5 ' J = J+1 I F J 500 THEN 350 PRINT I J = O NEXT I TIMER 0 THEN 1000 PRINT "DONE" STOP X = TTl(0) I F X=O THEN 1040 I F X 0 THEN 1050 PRINT "*****"; A$ DISMISS A$ = TT2$ (A$) DISMISS END 11-2 8 11.13 L I N K I N G INTO THE INTERRUPT SKIP CHAIN I f t h e u s e r desires t o p r o c e s s I / O from an I / O d e v i c e which i s c u r r e n t l y n o t supported by INBRTS and t h e i n t e r r u p t f a c i l i t y must be used, t h e u s e r must add code t o t h e i n t e r r u p t s k i p chain. The u s e r may allocate t h e second f i l e I / O b u f f e r a t l o c a t i o n 1 2 0 0 0 f o r s t o r a g e of t h e i n t e r r u p t d r i v e n code and t h e s k i p c h a i n . I f t h i s i s done, remember t o mark t h i s b u f f e r as " i n use" so t h a t INBRTS w i l l n o t t r y t o allocate it. F i l e I / O b u f f e r 1 may n o t be used f o r i n t e r r u p t i n g code, b u t can be used f o r n o n - i n t e r r u p t i n g u s e r f u n c t i o n s because it i s swapped by t h e OS/8 system when INBRTS c a l l s upon t h e USR t o perform services. NOTE INBRTS g e t s an i n t e r r u p t r e g u l a r l y once every 1/50 second f o r c l o c k s e r v i c e s . Obviously i n t e r r u p t s are o f f i n t h e s k i p c h a i n , t h e r e f o r e no computations o f any t y p e should be performed. Actual l i n k i n g i n t o t h e s k i p c h a i n i s performed as follows: . R ABSLDR *INBRTS . (UFUNCS are any u s e r f u n c t i o n s ) *UFUNCS$ ODT 6773/0000 addr addr i s the FIELD 1 address of the the user continuation of the skip chain 1041/6764 6773 +c .SAVE SYS I N B R T S . save arguments as needed f u n c t i o n s and INBRTS. NOTE E n t r i e s i n the u s e r f u n c t i o n table may also be modified a t t h i s t i m e . Location 6773 i n FIELD 0 is a CIF CDF 10. I f t h e u s e r w a n t s t h e d a t a f i e l d t o be zero upon e n t r y t o t h e FIELD 1 p o r t i o n of t h e s k i p , he must change t h e CIF CDF 10 t o CIF 10. 11-29 by FIELD 1 /EXAMPLE / OF ASSEMBLY LANGUAGE INTERFACE TO INBRTS /DEFINE USED IOTs ASKF = 6331 AKRB = 6336 ATSF = 6 3 4 1 ATLS = 6346 ATCF = 6 3 4 2 /DEFINE REFERENCED LOCATIONS I N INBRTS FACCLR = STRLEN = SACPTR = CALLFO = INTRET = ILOOP = HORD = /THE ADDITION TO THE INTERRUPT SKIP CHAIN *2 00 0 TTYSCN, AKSF JMP TESTOUT AKRB DCA CHAR TESTOUT , ATSF SKP ATCF C I F CDF 0 JMP I (INTRET / I S READER FLAG UP /NO.. /YES GET CHARACTER /SAVE I T / I S PRINTER FLAG U P /NO.. /YES. .CLEAR I T /RETURN BACK TO F I E L D 0 .... .. /ROUTINE TO DETERMINE FUNCTION DESIRED BY /ALTERNATE TELETYPE / I F FAC =O, NO ACTIVITY, I F F A 0 0 ADD CHARACTER TO /CURRENT STRING, AND I F FAC<O PRINT STRING TT1, TAD CHAR /GET CHARACTER SNA / I S ONE REALLY THERE? JMP NOCHAR I N P U T RECENTLY /NO...NOTHING ATLS IT /YES...ECHO AND (77 /MAKE I T 6 - B I T FOR INTERNAL FORMAT DCA SVCHAR /SAVE CHARACTER FOR STRING FUNCTION DCA CHAR /CLEAR LAST TYPED FLAG CIF 0 /USE CALLFO INTERFACE FUNCTION JMS I (CALLFO /TO CALL ROUTINE WHICH CLEARS FACCLR /FAC TAD SVCHAR /SEE I F CHARACTER TAD (-15 /WAS A CARRIAGE RETURN SNA CLA / S K I P I F NOT CLL CML RAR .MAKE AC NEGATIVE /YES. IAC /SET AC TO 1 OR 4 0 0 1 NOCHAR, CDF 0 /PLACE RETURN ARGUMENT I N . 11-30 DCA I (HORD C I F CDF 0 JMP I (ILOOP /FAC HIGH ORDER WORD /RETURN /TO INTERPRETER /ROUTINE TO CONCATENATE LAST TYPED CHARACTER /ON ALTERNATE TELETYPE TO STRING I N THE STRING /ACCUMULATOR /SHOULD ONLY BE CALLED I F TT1 RETURNED A /POSITIVE NUMBER TT2 I PUTIN , HIGHPT, SVCHAR, CHAR PTR, , CDF 0 TAD I (STRLEN CIA CLL RAR TAD I (SACPTR DCA PTR SNL JMP HIGHPT TAD I PTR TAD SVCHAR DCA I PTR CMA TAD I (STRLEN DCA I (STRLEN C I F CDF 0 JMP I (ILOOP /INBRTS INFO. I S I N F I E L D 0 /GET CURRENT STRING LENGTH /MAKE I T P O S I T I V E /CONVERT TO WORD OFFSET FROM CHAR OFFSET /POINTS TO SAC-1 /SAVE I T / L I N K = l MEANS 2ND CHAR I N WORD /WILL BE F I R S T CHARACTER I N WORD /GET UPPER HALF OF LAST CHARACTER /ADD I N NEW CHARACTER /PLACE BACK INTO SAC /BUMP LENGTH UP BY ONE, BUT I T I S /NEGATIVE TAD SVCHAR CLL RTL RTL RTL JMP PUTIN /CHARACTER MUST GO INTO HIGH / S I X B I T S O F WORD /RETURN /TO INTERPRETER /FINISH PUTTING I T I N 0 0 0 11-31 APPENDIX A OS/8 A.l BASIC STATEMENT, COMMAND, AND FUNCTION SUMMARY ELEMENTARY OS/8 Statement BASIC STATEMENTS Example of Form . DEV: F i lemane e x t Explanation Stops e x e c u t i o n o f t h e c u r r e n t program, r e t r i e v e s t h e program named i n t h e CHAIN s t a t e m e n t from t h e s p e c i f i e d d e v i c e and f i l e , compiles the chained program and begins e x e c u t i o n o f t h e program. CHAIN CHAIN DATA DATA xl,x2, ,xn Values x l through xn are to be associated with corresponding v a r i a b l e s i n a €U3AD s t a t e m e n t . The values may be either or strings. numerics S t r i n g s must be e n c l o s e d by q u o t a t i o n marks. DEF DEF FNB(x) = f (x) The u s e r may d e f i n e h i s own f u n c t i o n t o be called within h i s program by p u t t i n g a DEF s t a t e m e n t a t t h e beginning of a program. The f u n c t i o n name b e g i n s w i t h FN and must have t h r e e letters. The argument l i s t i n t h e f u n c t i o n may c o n t a i n as many as 4 numeric and 2 string arguments. ... DEF FNB(x,y) = f ( x , y ) DIM For numerics: D I M v l ( n 1 ) , v2(nl,m2) Enables t h e u s e r t o create a table o r a r r a y w i t h t h e specified number of elements where v i s t h e v a r i a b l e name and n and m are t h e maximum s u b s c r i p t values. Any number of a r r a y s can be dimensioned i n a s i n g l e D I M statement. For s t r i n g s : I is the length of s t r i n g variable v l $ , K i s t h e number of s t r i n g s and L is t h e l e n g t h of s t r i n g s of s t r i n g variable v2$. S t r i n g s longer than DIM v l $ (I),v2$ (K,L) A- 1 8 characters must be dimensioned. String tables are i l l e g a l . END END L a s t statement in the program. Signa 1s completion of t h e program. FOR-TO-STEP FOR v=xl TO x2 STEP x3 Used to implement loops: the variable v is s e t equal t o t h e expression xl. From t h i s p o i n t t h e loop c y c l e is completed V f ollowinq which i s incremented a f t e r each cycle by x3 u n t i l i t s v a l u e i s g r e a t e r t h a n x2. I f STEP x3 i s o m i t t e d , x3 is assumed t o +l. x3 may also be n e g a t i v e . I f x3 i s p o s i t i v e and x l > x 2 , t h e loop i s never executed. GOSUB GOSUB x A l l o w s the user t o enter a subroutine at several p o i n t s i n t h e program. Control t r a n s f e r s t o l i n e X. GOTO GO TO n or GOTO n Transfers control t o line n and continues e x e c t i o n from t h e r e . IF-G(Tr0 I F f l r f 2 GOTO n Same as IF-THEN. IF-THEN I F f l r f 2 THEN n I f the relationship r between t h e e x p r e s s i o n s f l and f 2 i s t r u e , t r a n s f e r s c o n t r o l t o l i n e n; i f n o t , continue in regular sequence GO TO or . I f f l and f 2 are s t r i n g t h e y are compared on t h e b a s i s o f t h e A S C I I numeric v a l u e of each c h a r a c t e r i n See paragraph the string. 7.1.4 f o r d e t a i l s . INPUT Causes t y p e o u t o f a INPUT vl,v2,...,vn ? to the user and waits for the u s e r t o supply t h e v a l u e s of the variables vl through vn. See paragraph 3.5.1 f o r INPUT r u l e s . LET Assigns t h e v a l u e of to expression f v a r i a b l e V. The w o r d i s optional. LETv-f A-2 the the LET NEXT Used t o t e l l t h e to return to computer t h e FOR s t a t e m e n t and e x e c u t e t h e loop again u n t i l v i s g r e a t e r t h a n or e q u a l t o terminal value i n FOR statement (or V is < terminal value if increment < O ) NEXT V . PRINT PRINT al,a2,...,an P r i n t s t h e v a l u e s of t h e specified arguments, which may be v a r i a b l e s , t e x t , or format c o n t r o l characters (, or : I . See paragraph f o r format c o n t r o l 3.5.2 and p r i n t i n g r u l e s . RANDOMIZE RANDOMIZE Generates new random numbers. READ READ v i , ~ 2 , . . . , ~ n Variables v l through vn are a s s i g n e d t h e v a l u e of t h e corresponding numbers or s t r i n g s i n the DATA list. REM REM When typed as t h e first t h r e e letters of a l i n e e v e r y t h i n g between R E M and end of l i n e i s ignored t o allow t y p i n g of remarks w i t h i n t h e program. RESTORE RESTORE Sets p o i n t e r back t o t h e beginning of t h e l i s t o f DATA values. RETURN RETURN Transfers control t o statement following l a s t GOSUB . STOP STOP UDEF UDEF f u n c t i o n name (arguments) sets of the the When encountered i n t h e program t h e STOP s t a t e m e n t t e r m i n a t e s execution. The UDEF s t a t e m e n t i s used t o d e f i n e t h e s y n t a x of a call to a user-coded machine language f u n c t i o n ( f u n c t i o n name) w i t h i t s a s s o c i a t e d arguments. A- 3 ,...,vn USE USE v l , v 2 CONTACT-THEN CONTACT v THEN n The USE statement i d e n t i f i e s t h e l i s t s and a r r a y s r e f e r e n c e d by a machine user- coded language f u n c t i o n . Define t h e l i n e number (n) t o schedule when a c o n t a c t i n t e r r u p t o c c u r s on p o i n t V. COUNTER-THEN COUNTER v THEN n Define t h e l i n e number (n) to schedule when the counter point v reaches zero. TIMER-THEN TIMER v THEN n Define t h e l i n e number (n) t o schedule when t h e t i m e v h a s elapsed. Continue to cycle until timer d i sab l e d . DISMISS A.2 OS/8 E x i t from u s e r interrupt mode main l i n e code. DISMISS rocess -p resume BASIC FILE STATEMENTS See Chapter 1 0 of t h i s manual f o r d e t a i l s r e g a r d i n g t h e BASIC f i l e s t a t e m e n t s and f i l e d e s c r i p t i o n s . use of OS/8 St aternen t Example of Form Explanation CLOSE # CLOSE #N: Closes a f i l e N p r e v i o u s l y by a FILE I N opened s t a t e m e n t where N i s t h e numerical e x p r e s s i o n f o r t h e f i l e number. FILE # FILEV # FILEN # FILEVN # FILE #n:s FILEV #n:s FILEN #n:s FILEVN #n:s These s t a t e m e n t s , open, respectively, a fixed l e n g t h A S C I I , variable length ASCII, fixed length numeric, and variable l e n g t h numeric f i l e , where 1 or n h a s a v a l u e of 2 and s i s a string expression w i t h a value of DEV:FILE.EX. DEV is system handler. INPUT # INPUT I N : I F END # I F END vl,v2 ,...,vn #N THEN n A- 4 Reads v l through f i l e number N. vn I f an a t t e m p t made t o read h a s been or w r i t e from PRINT # PRINT #N: a1 ,a2,. ..,an beyond t h e l a s t datum i n file number N , c o n t r o l p a s s e s t o l i n e number n. Writes t h e values of t h e arguments i n t o f i l e number N. RESTORE # Sets pointer back to b e g i n n i n g o f f i l e number RESTORE #N N. A.3 O S / 8 BASIC CONTROL COMMANDS Command Example of Form BYE BYE Explanation Exits from BASIC and returns control t o Keyboard Monitor. CTRL/C CTRL/C execution of program and control t o OS/8 I n d u s t r i a l BASIC e d i t o r . In editor mode r e t u r n s c o n t r o l t o O S / 8 Keyboard Monitor. Stops returns CTRL/O CTRL/O Stops t h e l i s t i n g of t e x t and r e t u r n s control t o BASIC e d i t o r . LIST LIST LI L i s t s program w i t h heading. LI LIST n LI n LIST n LI n L i s t s program s t a r t i n g from LISTNH LISTNH n LISTNH LISTNH n Same as LIST and LIST n, b u t heading suppressed. NAME NA NAME FILE.EX NA FILE.EX T h i s statement renames t h e c u r r e n t program i n user core. NEW NEW FILE.EX NE NE FILE.EX Used t o name a program t o created. Performs an i n h e r e n t SCRATCH. OLD OL OLD DEV: FILE.EX OL DEV: FILE.EX Performs i n h e r e n t SCRATCH and retrieves a p r e v i o u s l y c r e a t e d f i l e from t h e device s p e c i f i e d . RUN RUN RU RU Compiles and e x e c u t e s t h e program c u r r e n t l y i n core, w i t h heading. RUNNH RU"H Compiles and executes t h e c u r r e n t l y i n core, w i t h suppressed. SAVE SAVE DEV?FILE.EX SA DEV:FILE.EX Saves t h e c u r r e n t program on t h e device specified. SA l i n e n , w i t h heading. A- 5 be program heading SCRATCH sc A.4 SCRATCH sc Deletes a l l program s t a t e m e n t s from user core. OS/8 BASIC FUNCTIONS Explanation Function This f u n c t i o n argument X. returns the absolute value of the ASC (X) This f u n c t i o n r e t u r n s t h e decimal A S C I I number Appendix D) corresponding t o t h e c h a r a c t e r X. (see ATN ( X ) This function calculates t h e angle ( i n t a n g e n t i s given by t h e argument X. radians) whose is a numeric e x p r e s s i o n (modulo 6 4 ) which is t r u n c a t e d t o an i n t e g e r . The decimal i n t e g e r i s converted t o i t s e q u i v a l e n t A S C I I c h a r a c t e r (see Appendix D). X The c o s i n e f u n c t i o n i s used t o c a l c u l a t e t h e c o s i n e of an a n g l e s p e c i f i e d i n r a d i a n s . This f u n c t i o n r e t u r n s t h e d a t a i n t h e The argument X is a dummy argument. form MM/DD/YY. T h i s f u n c t i o n c a l c u l a t e s t h e v a l u e of e(2.71828) t h e t h e X power. Used w i t h a DEF s t a t e m e n t t o d e f i n e a T h e r e a f t e r used as any o t h e r f u n c t i o n . user This function r e t u r n s the g r e a t e s t t h e v a l u e of t h e argument X. integer This function of returns the number raised function. less than characters in s t r i n g XS. The M G ( X ) f u n c t i o n c a l c u l a t e s t h e n a t u r a l l o g a r i t h m o f X. T h i s f u n c t i o n , which can be used o n l y i n a P R I N T s t a t e m e n t , o u t p u t s t h e c h a r a c t e r whose decimal A S C I I v a l u e i s X. T h i s function is useful f o r outputting non-printing characters . POS (XS,YS ,z 1 This function returns the location in s t r i n g X$ of the f i r s t occurrence of s t r i n g Y$ s t a r t i n g w i t h t h e Zth c h a r a c t e r i n s t r i n g X$. See paragraph 7.2.4 f o r POS function rules. T h i s f u n c t i o n r e t u r n s a random number between 0 and 1. This f u n c t i o n r e t u r n s t h e s u b s t r i n g of between p o s i t i o n s Y and Z i n c l u s i v e l y . 7.2.5 for SEG$ f u n c t i o n r u l e s . A-6 which i s See paragraph X$ SGN ( X ) The s i g n f u n c t i o n r e t u r n s t h e v a l u e 1 i f X i s any p o s i t i v e number, 0 i f z e r o , and -1 i f any n e g a t i v e number. This f u n c t i o n i s used t o c a l c u l a t e t h e s i n e of an a n g l e specified i n radians. The square root f u n c t i o n computes t h e t h e a b s o l u t e value of an e x p r e s s i o n . square root of a This f u n c t i o n c o n v e r t s t h e numeric value o f s t r i n g which i s i t s decimal r e p r e s e n t a t i o n . X to This f u n c t i o n which can o n l y be used i n s t a t e m e n t , moves t h e p r i n t head t o p o s i t i o n X. a PRINT This f u n c t i o n t u r n s on t h e trace f e a t u r e i f x=l and t u r n s o f f t h e trace f e a t u r e i f x=O. When t h e trace f e a t u r e i s on, l i n e numbers are p r i n t e d between p e r c e n t s i g n s as t h e l i n e s are encountered i n t h e program. The f e a t u r e i s u s e f u l when debugging programs. This f u n c t i o n r e t u r n s t h e number r e p r e s e n t e d by t h e s t r i n g X$ which i s t h e decimal r e p r e s e n t a t i o n of a number. A. 5 INDUSTRIAL FUNCTIONS Explanation Function ANI (P,G) This f u n c t i o n r e a d s a n a l o g i n p u t p o i n t P a t g a i n G and r e t u r n t h e value i n v o l t s . AN0 (P ,VI This f u n c t i o n loads t h e D/A p o i n t P w i t h t h e v a l u e V. 1 0 2 3 = f u l l scale Ominimum CLK (X) I f t h e value of X is z e r o o r n e g a t i v e t h i s f u n c t i o n If the r e t u r n s t h e t i m e of day clock i n seconds. value of X i s p o s i t i v e t h e t i m e of day c l o c k i s s e t t o t h e value of X 14x486 4 00 CN1 (P) This f u n c t i o n r e t u r n s t h e number of counts u n t i l z e r o i n c o u n t e r P. , remaining CNO (P V) T h i s f u n c t i o n loads t h e c o u n t e r ( P ) such t h a t V i t e m s w i l l be counted before t h e c o u n t e r (P) i n t e r r u p t s (overflows) RDI ( P , N ) This f u n c t i o n through N. SDo (P,N ,VI This f u n c t i o n l o a d s t h e v a l u e V, i n b i n a r y , p o i n t ( s ) P through N ( r i g h t j u s t i f i e d ) . . returns A- 7 the value of point(s) P into T h i s function return the r e s u l t s of the s e n t t o p o i n t ( s ) P t h r u N. W E (XI STA (X) These are U P I R I d e n t i f i c a t i o n Functions. ( R e f e r t o chapter 8, section 8.4). CNT ( X ) Arguments are dummies. A- 8 last data APPENDIX B COMPILE-TIME DIAGNOSTICS are Compile-time d i a g n o s t i c messages typed o u t by OS/8 BASIC form: in the where XX i s t h e d i a g n o s t i c code and YY i s t h e l i n e number a t which t h e error occurred. D i a g n o s t i c Code Explanation CH Error i n CHAIN statement. DE Error i n DEF statement. DI Error i n D I M s t a t e m e n t s y n t a x or s t r i n g dimension greater than 72, or a r r a y dimensioned t w i c e . Fw E r r o r i n f i l e number or filename d e s i g n a t i o n . FP I n c o r r e c t F O R loop parameters o r FOR l o o p syntax. FR Error i n defined IF THEN or GOTO missing from . function arguments IF or function not or bad statement, relational operator. error. IO I/O LS Missing e q u a l s i g n i n LET statement. LT Statement too long (greater t h a n 80 characters). MD Line number d e f i n e d more than once. l i n e number b e f o r e l i n e i n error. ME Missing END statement. YY equals MO Operand expected, n o t found. Mp Missing p a r e n t h e s i s o r error i n e x p r e s s i o n parentheses. within MT Operand of mixed t y p e o r operator does n o t match operands (e.g., A$=l and A&2 are b o t h i n c o r r e c t ) . NF NEXT NM Line number missing a f t e r GOTO, GOSUB, or THEN. OF Output f i l e error. statement statement. B-1 without corresponding FOR PD R e s u l t of either too Pushdown stack overflow. complex a s t a t e m e n t (or s t a t e m e n t s ) o r too many n e s t e d FOR-NEXT loops QS S t r i n g l i t e r a l too long or does n o t end i n quote. ss Subscript o r f u n c t i o n argument error. ST Symbol table overflow due t o too many v a r i a b l e s , l i n e numbers, or l i t e r a l s . Combine l i n e s u s i n g b a c k s l a s h (Q t o condense program. SY System . incomplete. INBSIC.SV, INBCMP.SV, System files such and 1NBRTS.SV missing. as Condense or CHAIN. TB Program too big. TI) Too much data i n program. TS Too many t o t a l characters i n t h e s t r i n g literals. RT I n c o r r e c t real t i m e s t a t e m e n t s . UD Error i n UDEF s t a t e m e n t . UF FOR loop w i t h o u t corresponding NEXT s t a t e m e n t . us Undefined s t a t e m e n t number. (i.e., statement number mentioned i n s t a t e m e n t i s n o t i n program.) W Incorrect statement xc E x t r a characters a f t e r t h e logical and of l i n e . (e.g., LET A=B.D t h e dot a f t e r t h e B s u g g e s t s t h a t B i s t h e end of t h e l i n e and t h e character D appears extraneous.) . or missing -- B- 2 array designator in USE APPENDIX C RUNTIME DIAGNOSTICS Runtime d i a g n o s t i c messages typed o u t by OS/8 BASIC a r e i n t h e form: XX AT LINE YYYYY where XX is t h e d i a g n o s t i c code and YYY i s t h e l i n e number a t which Most runtime errors s t o p e x e c u t i o n of the t h e error occurred. program. Those errors which do n o t s t o p t h e program a r e termed non-fatal (NF) and are i n d i c a t e d below. Explanation D i a g n o s t i c Code BO N o more f i l e b u f f e r s a v a i l a b l e . CI I n q u i r e f a i l u r e i n CHAIN. Device n o t found. CL Lookup f a i l u r e i n CHAIN. Filename n o t found. DA Attempt t o read p a s t end o f d a t a l i s t . DE Device d r i v e r failure. DO N o more room DV Attempt t o d i v i d e by 0. error. Caused by hardware I/O f o r drivers. Too d e v i c e s used i n f i l e commands. many different Result is set to zero. when I/O (NF) EF Logical end o f f i l e . Usually device runs o u t o f medium. caused EM Attempt t o e x p o n e n t i a t e a power. EN E n t e r error i n opening f i l e . Device i s read o n l y or t h e r e i s a l r e a d y one v a r i a b l e f i l e open on t h a t d e v i c e or f i l e n o t found. FB FILE busy. FC OS/8 FI Attempt t o close or u s e unopened f i l e . FM Attempt t o f i x minus number. Usually n e g a t i v e s u b s c r i p t s o r f i l e numbers. FN I l l e g a l f i l e number. FO Attempt t o f i x number g r e a t e r t h a n 4095. Usually caused by n e g a t i v e s u b s c r i p t s of f i l e numbers. negative number to a A t t e m p t t o use a f i l e a l r e a d y i n use. error while c l o s i n g variable f i l e . read only on f i l e closed a l r e a d y . c-1 Device i s caused by Only 0,l and 2 are legal. GR RETURN w i t h o u t a GOSUB. GS Too many n e s t e d GOSUBs. IA I l l e g a l argument i n UDEF f u n c t i o n call. IF I l l e g a l DEV:filename s p e c i f i c a t i o n . IN Inquire found LM A t t e m p t t o t a k e log o f n e g a t i v e number o r 0. OE D r i v e r error w h i l e o v e r l a y i n g . device hardware error. ov Numeric or i n p u t overflow. PA I l l e g a l argument i n POS f u n c t i o n . RE Attempt to read p a s t end of f i l e . sc S t r i n g too long (greater t h a n 72 characters) a f t e r concatenating. SL S t r i n g too long or undefined. SR Attempt t o read s t r i n g from numeric f i l e . ST S t r i n g t r u n c a t i o n on i n p u t . allowed. (NF) su S u b s c r i p t o u t of D I M s t a t e m e n t range. SW A t t e m p t t o w r i t e s t r i n g i n t o numeric f i l e . VR Attempt t o read variable l e n g t h f i l e . WE Attempt t o w r i t e p a s t end o f f i l e (NF). . failure in The l i m i t i s 10. opening file. Device Caused by not SYS (NF) Stores m a x i m u m l e n g t h Added Run-Time Process I / O E r r o r s BE Width crosses module boundary. DR DISMISS executed while not in user interrupt routine. GE Module i s n o t t h e correct g e n e r i c code (rype). IG I n v a l i d g a i n specified for analog i n p u t . Gc I l l e g a l g e n e r i c code (Module n o t s u p p o r t e d ) . IV D a t a i t e m o u t of v a l i d range. SG Channel n o t d e f i n e d a t system g e n e r a t i o n . c-2 IC I l l e g a l channel (channel n o t i n v a l i d r a n g e ) . QW Zero width or width n o t wide enough. TM A t t e m p t to start: too many timers, counters contacts. TE T i m e too l a r g e ( 3 8 6 4 0 0 for c l o c k or timer. c- 3 or APPENDIX D ASCII CONVERSION TABLE Character 6-Bit O c t a l Decimal Character 6 - B i t Octal Decimal 01 02 03 04 05 06 07 10 11 12 13 14 15 16 17 20 21 22 23 24 25 26 27 30 31 32 60 61 62 63 64 65 1 2 3 4 5 6 7 8 9 10 11 12 13 14 6 7 8 9 space 66 67 70 71 40 41 42 43 44 45 46 47 50 51 52 53 54 54 55 56 57 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 58 59 60 61 62 63 0 27 ~ 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 0 1 2 3 4 5 I n # $ % c ' (apostr. 1 ( 1 * + ,(comma) 15 16 17 18 19 20 21 22 23 24 25 26 48 49 50 51 52 53 / i < > ? @ I \ 1 t 4- D- 1 55 56 57 72 73 74 75 76 77 00 33 34 35 36 37 28 29 30 31 APPENDIX E OS/8 INDUSTRIAL BASIC SYSTEM BUILD INSTRUCTIONS OS/8 I n d u s t r i a l BASIC i s d i s t r i b u t e d on D E C t a p e . The D E C t a p e version of O S / 8 I n d u s t r i a l B A S I C c o n t a i n s SAVE i m a g e s ( r e a d y - t o - r u n ) f o r each of t h e OS/8 I n d u s t r i a l B A S I C system components as w e l l as b i n a r i e s f o r each s y s t e m c o m p o n e n t . OS/8 I n d u s t r i a l BASIC, then, i s d i s t r i b u t e d a s t h e following f i l e s : File - D i s t r i b u t e d on: Component . .. . I N B S I C BN INBSIC. SV INBCMP BN INRCMP S V INBLDR. BN INBLDR. S V INBRTS BN B i n a r y for editor E d i t o r save image C o m p i l e r binary C o m p i l e r save image EAEOVR. BN O v e r l a y f o r KE-8/E EAE ( 8 / E w i t h KE-8/E EAE) R u n t i m e s y s t e m save image ( f r o m INBRTS BN) . INBRTS S V DECtape . function DECtape DECtape overlay S t r i n g f u n c t i o n overlay F i l e m a n i p u l a t i o n overlay . 1NBSIC.SF I N B S I C FF A s s e m b l i n g the OS/8 made r b i n a r y Loader save i m a g e R u n t i m e system b i n a r y Ar i t h m e t i c I N B S I C . AF DECtape DECtape DECtape DECtape DECtape DECtape DECtape DECtape DECtape I n d u s t r i a l B A S I C sources I n s t r u c t i o n s f o r assembling each of t h e O S / 8 I n d u s t r i a l B A S I C sources follow. PAL-8 ( u n d e r O S / 8 ) i s used, and t h e d e s c r i p t i o n s r e p r e s e n t OS/8 commands. T o a s s e m b l e OS/8 I n d u s t r i a l B A S I C , a 12K machine i s required. The OS/8 BASIC sources are named as follows: NAME.MM where NN r e p r e s e n t s t h e version number. f i l e s are n a m e d : Name - first Component . . INBSIC. 01 INBCMP 0 1 INBLDR. 0 1 INBRTS 0 1 1. For t h e E d i t o r Source C o m p i l e r Source Loader Source R u n t i m e System Source To assemble t h e e d i t o r : .R PAL8 *DEV:INBSIC.BN DEV:INBSIC.Ol E-1 release, the 2. To assemble t h e compiler: . . .R PAL8 *DEV :INBCMP BN< DEV :INBCMF' 0 1 3. The runtime system s o u r c e is c o n d i t i o n a l i z e d f o r PDP-8/E with Assembly instructions f o r each o f t h e supported c o n f i g u r a t i o n s follow. EAE. To assemble f o r PDP-8E w i t h o u t EAE: .R PAL8 *DEV: INBRTS.BN<DEV:INBRTS. Ol/K T o assemble t h e run-time system o v e r l a y f o r PDP-8E, PDP-8F o r PDP-8/M w i t h KE-8/E EAE o p t i o n , p r e p a r e a f i l e c a l l e d EAE.PA t h a t looks as follows: EAE-1 PDP8E=1 PAUSE Then : .R PAL8 *DEV:EAEOVR. BN-DEV:EAE. PA, DEV: INBRTS . 01 / ~ Making SAVE Images from Binary F i l e s : T o create SAVE images of each o f t h e OS/8 I n d u s t r i a l perform t h e f o l l o w i n g OS/8 commands. 1. BASIC binaries, For t h e editor: . R ABSLDR *DEV:BASIC. BN$ SAVI3 SYS :BASIC; 3011 . 2. For t h e compiler: .R ABSLDR *DEV:BCOMP.BN$ .SAVE SYS :BCOMP; 7000 3. For t h e l o a d e r : .R ABSLDR *DEV: INBLDR. BN$ SAVE SYS $ BLOAD: 7 6 05 . 4. For t h e runtime system: .R ABSLDR *DEV:INBRTS.BN$ (ifyou have no KE-8/E or E-2 EAE o p t i o n ) *DEV:INBRTS.BN,DEV:EAEOVR.BN$ ( i f you have PDP-8/E, PDP-8M or PDP-8F with KE-8/E EAE) .SAVE SYS INBRTS 0-7577, 10000-11377; 7605 .SAVE SYS 1NBSIC.AF 3400-4577 .SAVE SYS 1NBSIC.SF 12000-13177 .SAVE SYS INBSIC-FF 13400-14577 NOTE All BASIC system files must t h e systems d e v i c e ( S Y S : ) . 5. reside on A t t h i s p o i n t , I n d u s t r i a l BASIC i s ready t o run. E-3 APPENDIX F INDUSTRIAL BASIC SYSTEM GENERATION Each f u n c t i o n a l I / O module (analog i n p u t , analog o u t p u t , d i g i t a l i n p u t , d i g i t a l o u t p u t ) o p e r a t e s on a continuous range of l o g i c a l addresses. The mapping between t h e l o g i c a l address and the corresponding p h y s i c a l address of t h e UDC module and subchannel i s performed w i t h i n t h e system, based on t a b l e s which d e f i n e t h e UDC c o n f i g u r a t i o n and which t h e u s e r g e n e r a t e s d u r i n g "SYSTEM GENERATION". System g e n e r a t i o n i s t h e process o f s e t t i n g t h e f u n c t i o n a l module t a b l e s f o r analog i n p u t , analog o u t p u t , d i g i t a l i n p u t , d i g i t a l o u t p u t , s p e c i f i n g t h e base of t h e contact modules, and t h e base of c o u n t e r modules. The f i r s t s t e p i s t o determine t h e c l a s s i f i c a t i o n of each p h y s i c a l channel. The c l a s s i f i c a t i o n yroups are c o n t a c t s (W742) counter(W7341, analog i n p u t (ADUO1) , analog o u t p u t (BA633) d i g i t a l i n p u t (W740) and d i g i t a l output. Once t h e channels are c l a s s i f i e d t h e I / O t a b l e i n INBRTS may be generated. The following i s a sample system g e n e r a t i o n of t h i s set o f modules. , , Slot - Module Class - BW7 42 BW742 BW740 BW740 BM6 84 BM686 BM6 86 BW734 mu01 contact contact d i g i t a l input d i g i t a l input d i g i t a l output d i g i t a l output d i g i t a l output counter analog i n p u t The t w o i n t e r r u p t i n g module t y p e s ( c o n t a c t s and c o u n t e r s ) r e q u i r e o n l y t h e base address of t h e i n i t i a l contiguous p h y s i c a l channel o f each module type. The t w o module t y p e s do n o t have t o be a d j a c e n t t o each o t h e r , b u t each module ( c o n t a c t s and c o u n t e r s ) MUST be i n contiguous channe 1s. Logical channels s t a r t a t t h e h i g h o r d e r b i t (or subchannel zero) of t h e f i r s t p h y s i c a l channel of a given t y p e of f u n c t i o n a l I / O module and c o n t i n u e s e q u e n t i a l l y i n t h e o r d e r t h e p h y s i c a l channels are s p e c i f i e d i n t h e f u n c t i o n a l I / O table. I f channels 5 , 7 , 9 are d i g i t a l i n p u t and t h e t a b l e e n t r i e s are i n t h a t o r d e r , l o g i c a l channels 1 through 1 2 a r e on p h y s i c a l channel 5, w h i l e 25 through 36 would be on p h y s i c a l channel 9 (Note t h e b r e a k s are dependent on t h e number o f I/O p o i n t s or subchannels p e r module). - The tables are most simply a l t e r e d via OS/8 ODT; a d d r e s s should be converted t o octal addresses. F- 1 the UDC physical The table addresses are: DIGITAL INPUT - 10600 DIGITAL OUTPUT - 10610 ANALOG INPUT - 10620 ANALOG OUTPUT - 10630 - 7310 COUNTER - 7276 CONTACT The sample system table would be altered as follows: .GET SYS INBRTS . ODT 10600/7777 0203 (CR) 10610/7777 10611/7777 0405 (LF) 0677 (CR) 106201/7777 1077 (CR) 7276/7777 0007 (CR) 7310/0000 0 (CR) tc .SAVE SYS INBRTS Notice that addresses are entered in octal numbers and if an odd number of addresses exists the last entry is terminated by 77. A line feed gives the next entry in the current table. The table generation is terminated via CTRL/C and the SAVE command. The table may be altered to reflect alteration in hardware configurations; the sequence of channel entries determines the mapping into logical channels. F- 2 APPENDIX G O P T I M I Z I N G SYSTEM PERFORMANCE There are s e v e r a l s t e p s t h e OS/8 I n d u s t r i a l BASIC u s e r can t a k e t o speed up BASIC e x e c u t i o n and compilation t i m e s , t h u s speeding up OS/8 I n d u s t r i a l BASIC throughput rates. This appendix c o n t a i n s s u g g e s t i o n s f o r improving system performance. 1. Bypassing t h e E d i t o r The OS/8 I n d u s t r i a l BASIC compiler is c o n s t r u c t e d such t h a t i t w i l l a c c e p t any source f i l e f o r i n p u t . Thus, i t i s p o s s i b l e t o e x e c u t e an a l r e a d y e x i s t i n g BASIC program d i r e c t l y , s a v i n g t h e overhead o f an OLD and RUN command t o t h e e d i t o r . The format i s as follows: .R INBCMP *DEV:FILE.BA I f OS/8 I n d u s t r i a l BASIC i s used i n t h i s f a s h i o n , it OS/8 Monitor on completion, r a t h e r than t h e OS/8 returns t o the I n d u s t r i a l BASIC editor. Normal Usaqe F a s t e r Equivalent .R INBSIC NEW OR OLD--FILE *FILE .R INBCMP READY RU”H READY I n g e n e r a l , use R INBSIC when: a. b. C r e a t i n g new programs or modifying o l d programs Debugging o l d programs U s e R INBCMP: a. To run e x i s t i n g programs b. I n BATCH stream t o run BASIC programs Source f i l e s f o r u s e by INBCMP must conform t o t h e following r u l e s : a. There should be no blank l i n e s . b. Statements must be i n t h e executed. C. L i n e numbers are r e q u i r e d o n l y f o r s t a t e m e n t s t h a t are r e f e r e n c e d i n IF, GOSUB, and GOT0 s t a t e m e n t s . In other words, i f t h e o n l y way a s t a t e m e n t may be reached i s f o r t h e preceding s t a t e m e n t t o be executed, it does n o t r e q u i r e a l i n e number. I n t h e following example, t h e r e are no unnecessary l i n e numbers. order G-1 in which the are to be FOR I=1 TO 1 0 I F 1 1 2 THEN 400 PRINT I GO TO 410 400 PRINT "TWO" 410 NEXT I END ' N o t e t h a t t h e s o u r c e f i l e can be created i n one of t w o ways: it may be created i n t h e normal f a s h i o n w i t h t h e OS/8 I n d u s t r i a l BASIC e d i t o r and saved ( i n which case a l l l i n e s w i l l c o n t a i n l i n e numbers), or i t may be p r e p a r e d u s i n g any o f t h e o t h e r O S / 8 e d i t o r s (EDIT, TECO). In t h i s second case, t h e u s e r can t a k e advantage o f t h e e x t r a f e a t u r e s supported by t h e s e s o p h i s t i c a t e d e d i t o r s o v e r t h e O S / 8 I n d u s t r i a l BASIC e d i t o r . 2. Placement of BASIC Overlays on SYS For DECtape system u s e r s , t h e improved by t w o simple s t e p s : a. of the U s e a DECtape d r i v e o t h e r t h a n DTA0 f o r DSK: statement). b. performance system (via the TD8E system may o n l y use d r i v e s 0 and 1. can be ASSIGN Place t h e OS/8 I n d u s t r i a l BASIC system f i l e s as close t o g e t h e r on t h e SYS t a p e as p o s s i b l e . The b e s t approach i s t o make a "BASIC t a p e " c o n t a i n i n g o n l y t h e OS/8 system, P I P , and t h e BASIC system image f i l e s . Both a c t i o n s have t h e e f f e c t o f speeding up O S / 8 BASIC by t h e simple r e d u c t i o n o f t h e t a p e motion r e q u i r e d f o r o v e r l a y i n g and compiling. 3. Placement o f Function C a l l s Within BASIC Programs M o s t o f t h e OS/8 BASIC f u n c t i o n s and f i l e o p e r a t i o n s reside i n one o f t h e t h r e e system o v e r l a y s . S i n c e t h e system o v e r l a y d r i v e r reads i n an o v e r l a y o n l y i f t h e f u n c t i o n d e s i r e d i s n o t p r e s e n t i n t h e c u r r e n t l y r e s i d e n t o v e r l a y , o v e r l a y i n g overhead c a n be reduced by t h e simple mechanism of p l a c i n g c a l l s t o f u n c t i o n s t h a t reside i n t h e same o v e r l a y as close as p o s s i b l e i n t h e BASIC program. For example: 10 INPUT A$ 20 Z$= SEG$(A$,1,6) 30 FILEN #1: Z$ 40 I N P U T A$ 50 Z$= SEG$(A$,1,6) 60 FILEN #2:Z$ The above BASIC program u s e s t h e f i r s t six c h a r a c t e r s of a s t r i n g typed by t h e u s e r as a f i l e name t o open a BASIC f i l e . It uses t h e SEG$ f u n c t i o n , a F i l e command, t h e SEG$ f u n c t i o n , and t h e F i l e command again. Since SEG$ and FILE are i n d i f f e r e n t o v e r l a y s , t h e o v e r l a y e r w i l l be used f o u r t i m e s . A f a s t e r way t o accomplish t h e same o p e r a t i o n s follows : 1 0 INPUT A$,B$ 20 Z$=SEG$ (A$, 1,6) 30 X$=SEG$ (B$,1,6) 40 FILEN #1: Z$ G-2 50 FILEN #2: X$ The above only overlays t w i c e , saving considerable time i n t h e program execution. The functions are grouped i n the overlays a s f o l l o w s : Overlay 1 (1NBSIC.AF) : SIN,COS,ATN,LOG,EXP,RND,SQR,SGN,POWER(A Overlay 2 (1NBSIC.SF) : ASC,CMR$,DAT$,LEN,POS,SEG$,STR$,VAL Overlay 3 (1NBSIC.FF): CLOSE, FILE, FILEN, FILEV,FILEVN G- 3 B) APPENDIX H RUN-TIME SYMBOL TABLE /Q!3/8 INDUSTRIAL BASIC RUNTIME b3U7 3S75 A6SVAL 2363 ACH 0045 ACL 08146 4CLO 0046 A C S A V E 6744 ACSR 6072 A C S R P T 4704 ACX 0044 AC0 8Q40 004s AC1 AC2 0@42 A O C A L C 0636 ADFC 0705 ADFW 4747 AIROR 0043 AJT 6712 ALl 5057 ALlK 3774 AblP 6240 ALSPP 5140 ALlPT 4705 ALlPTR 5642 AMODE 2310 ANOLST 3 4 S i ANOPTR 3406 ANITBL 0 6 2 0 ANOTBL 0630 ANOUT 0656 AN1 3775 AN2 3776 APQB0l 237Y bRGET 6200 C R G E T K 55693 ARGETL 5444 ARGETP 6127 ARGPLK 4312 ARGPLL 3511 AHGPQL 4220 4 R G P R E 03a4 ARGPRL 1415 ARGSET 0 0 7 1 A R I T H A 6373 A ABSV ARJYP 4RRAYI ARSTRT ARTRAP ASC 07@7 06B0 0022 4366 3487 ASeNOE 3243 ASCOLK 3457 ASCON 3667 ASCQUP 1260 ATABOF 0 4 1 0 ATABOL 1162 ATAN 4200 A T A N A l 4438 ATANA2 4436 ATANA3 4444 ATANB0 4425 A T A N B l 4433 ATANBi! 4 4 4 1 ATANB3 4447 A999 2507 BAUCHN 0855 EIADGC PI844 BAS 6627 B C G E T 3035 BCGETL 2776 BCPUT a745 BCPUTL 3034 BE 0047 BENO 5572 BKHERE 7347 B L I N I T 3352 tlLREAO 3 3 3 4 BMAP Q(836 BO 4210 B R T S B 1216 8 S H F T 0427 B S T R T 5547 BSWL 0144 BSMP 6361 BUFASS 4222 BUFCHK 2706 UUFCHL (4147 Ul 4216 82 4211 CA0 4506 CAF 66817 CbLFFP 7243 CALL8E 63046 CALLF0 7 2 2 1 CALLOW 0 0 6 1 CBLK 3672 CC16 4414 cc3 4316 cc4 4315 CDFXNL OS34 CDF10 c1820 COFPS Bli125 COFPSL 0115 CDFPSU 0206 COFXX 2140 CDF0 0216 COFklB0 4 3 4 1 CDF10 6307 CDF20 4565 COIN 3623 CFETCH 1322 PALBnV7 9/20/73 C H A I N 3600 CHAR 0053 CHARNO 6677 CWAR3P 21146 CHAR3U 3064 CHK63 6604 CHKB4 6613 CHR 3400 CHRNOL 0 1 5 1 C I 3624 CL 3640 CLEANP 4243 CLENG 3442 CLF 3570 CLN 08130 C L O C K 7000 CLOS€ 34Q3 CLOSEB 3445 CLOSER 3405 CLPY 1115 CLPYl 1122 CLSTAG 3544 CMMA 6434 CM210 6674 CNOBMK 2765 CIUOBML 5 5 7 3 CNOEMP 3104 CbQCLL 0146 CNOCLR 3016 C k T B A S 7276 CNTCBP 6666 CNTCBS 7310 C N T C O M 1254 ChfCST 1331 CNTCT 1106 C N T C T I 7122 CNTERI 1110 CNTFNC 0527 CNTFUC 7170 C N T I N 1314 ChTLC 7215 CNTOUT 1277 C N T R C T 1107 ChTSW 1077 ChTSWi! 1104 CCJMBNE 2766 COMLOP 2527 COMMA 2512 COMMAS 2551 COMMON 0200 COYONP 0 0 4 1 C O M X I T 0475 C O N T A C 1327 CONTXT 7125 cos 4053 PAGE 148-1 COUNCK 1363 COUNTR 1236 CPLOOP 3233 CR 6432 CREAD 3665 CRETN 3456 CRFUNC 0765 CRLF 0153 CRLFR 2346 CRAEP 1360 CSFN 2001 C S M O V E 4Q51 CSTA 4070 C S T A C 4071 C l l N L 7400 C13 4531 4320 c20 C2000 6 6 7 0 e2400 6 6 7 1 c3 4070 c4 4047 C770 6676 C7760 6675 DA 2302 DADP 0060 D A T A B A 3675 D A T C O M 3613 OAT€ 3600 D A T T A B 4525 DAY 3742 OAYTBL 4564 OBAO 6115 O B A D l 5534 OBAOlP 6 1 7 s DCNT 5139 DCNTP 4726 DCOS 7520 OCOSP 6665 DE 3366 DECNV 5 2 1 3 DECON 5 2 1 4 DECONV 5207 D E C O N l 5335 DEVCAL 0 1 2 4 DEVNAL 4317 D E V N A l 4030 OEVNAZ 4 0 3 1 DGTYP 5 0 7 6 OGTYPP 4725 D I G O U T 0400 OIGl 4125 D I G l A 3571 DIG2 4126 DIG3 4127 0164 4130 /OS/8 INDUSTRIAL B A S I C R U N T I M E DIG5 9131 D I S I N 3630 Q I S M I S 0141 D I S P C H 7523 D I V B Y 0217 D I V I O 012s DLCDF 2303 D C C D F L 1164 DLPTR 0Cl16 OLREAP 2275 DLRELK 7554 OLSTOP 0027 O C S T R T 0030 DNA1 3621 DNA2 3622 DNUMBR 53@5 DO 4045 R O A O D 6023 DONA 6027 DONE 3765 OONEF 5 9 6 6 BOlrlHK 6 4 6 6 OR 1867 D R l r R G l 0547 RRARG2 05SB ORARG3 0 5 5 1 ORCALL 8532 DRERR 3365 DRERRP 0555 D R I V R L 4046 D R I V R N 4200 QS 441 1 O S W I T 0052 DT1 5101 DV 6355 OVLPl 5711 OVLl 5514 DVOPS 6315 DVOPSP 5533 D V O P l 6336 OVOP2 5 5 3 5 m m p w 6333 DVOVR 5777 O V T R A P 3514 DV 1 5765 OV2 5755 DV24 5795 DV24P 5532 D V Z Y P T 5136 EAE 0IQQ0 EATONE 6 4 1 4 EBC EBLK EDBLK EDON 2730 3737 3746 S2h0 tF 3367 kFRTAL 4261 EFLG 8056 ELQP 7053 EM 3615 EMDQNE 3606 EMOQNL 3570 EMESS 41113 EMLOOP 3545 EN 4274 ENTLQK 4262 ENTNO 0162 ENTRYN 4032 ENVAL 3516 EOFSEL 0143 E O F S E T 2236 EOSPA 6677 ERROIS 1457 ERRET 4050 ERROR 01!6 ERRORR 4002 ESHFT 0435 W R A4134 E S T R N G 4112 ETA8 4137 ETABA 4135 ETLOP 4033 EXP 0044 EXPA0 4422 EX PA^ 4417 E X P B 1 4414 EXPON 3477 EXPONK 3630 E X P O N ~4120 EXPP 0040 E20P10 1307 FACCLR 0362 FACR 6031 FACREL 0133 FACHES 2370 F A C S A L 0132 FACSAV 3 3 6 1 FAUOL 4860 FAoDLK 3473 FAQDLL 5312 FAODM 4360 F A O ~ 6004 F A T A L 6771 FATCCHK 4040 FB 4012 FBITGT 6547 F R I T S 0117 FC 3443 FCLR 8137 FCNT 527s FD 5527 FOOQN 5742 FBDONP 5 5 3 1 FOIVL 4062 FDIVM 4 3 6 1 F O I V l L 4067 F D I V l M 9362 FDVPT 5 3 1 1 FDl 5504 FDlP 5721 FERRLP 4 0 1 1 0037 FF FFAOO 6 0 0 0 FFADP 4733 F F A T N 4200 FFCOS 4053 FFOIV 5722 F F O I V l 5412 FFDP 5446 FFDVP 4734 FFOl 5726 FFEXP 4120 FFE%PL 3625 FFGET 6 2 4 1 FFIN 5200 FFINLK 3476 F F I N l 5232 FFIX 4500 FFLOAT 4533 FFLOG 4263 FFLOGL 3626 FFMPP 4735 FFMPY 5600 FFMT 4613 FFNEG 6135 FFNEGA 5410 FFNEGK 5502 FFNEGP 5303 FFNEGR 5773 FFNGP 4736 FFNOR 6215 FFNORR 6236 FFORMT 1302 FFOUT 4600 FFPUT 6256 FFPUTP 0135 FFSIN 4000 FFSQ 6347 FFSUB 6117 F F S U S l 5400 FGETL 0134 FGETM 0134 FI 2273 FIDLE 0 1 2 3 FIDVP 3 6 3 1 FIG02 5241 FILEFA 6375 F I L E 1 6714 FILE2 6731 FILSTR 3 3 1 1 FILSTU 4306 FISUBL 4372 FXXDNE 4525 FXXL 4066 F I X L P 4515 FJOCI 0400 FLDW 0057 PLEN 4273 FLING 5142 FLINK 4722 FLN 3637 FLOAT 0562 FLOAT6 3420 FLQATL 3645 FLQATM 4356 FLOOK 4236 FLUSH 6425 FM 1624 FMPVL 3572 FMPYLK 4 0 6 1 FMPYLL 5310 FMPYLY 3627 FMPYM 4357 FN 2005 FNAP 3441 FNDMCY 0317 F N E G I 1226 FNEGL 0140 FNLP 6334 FNOM 4271 FNORL 0 1 3 6 FNORP 6176 FO 1637 FOTYPE 2355 FOUTl 4625 FOUT2 4634 FOUT3 4674 POUT4 4667 FPPARG 7246 FPPPNT 0035 FPPTMl 1164 FPPTMZ 1 1 6 1 FPPTM3 1156 FPPTM4 1153 FPPTMS 1150 FPPWRK 7 2 5 1 FPUTL 0135 FPUTLL 0720 FPUTM 0135 FRACT 48)71 /OS/8 INOUSTRIAL FRANDP 2 3 4 1 F R O O T 3646 FSORL 4065 FSQRM 4365 FSTOP 370pJ FSTOPI 05S7 FSTOPN 0 5 5 6 FSTOPP 0560 FSTOPl 0 1 6 1 FSUBL 4064 FSUBLL 3573 FSUBM 4363 FSUBlL 4@63 FSUBlM 4364 F S W I T C 2050 F T C O M 2424 FTiFLG 4 5 3 1 FTRPRT 4S0S FtYb 3015 FTYPE 4555 FTYPL 0150 FTYPSE 3462 FUBXXX 1406 F U D X X l 1416 FURXX2 1405 FUJUMP 1523 F U N C l I 1467 FUNCZI 1466 FUNC3I 1 5 3 5 FUNC41 1550 FUNCSI 1465 F1116 0 0 1 6 F I X 1 7 0017 FlSAV 0020 FlSAV2 0 0 2 1 F l S A V 3 0022 FlTMPl 0023 FlTMP2 0024 FlTMP3 0025 FlTMP4 0026 G A I N S 0353 GC 7274 GCHR 5322 GCSE 1153 G C S € 1 1157 GCcl3 7307 GD 5025 GE 0045 GENERR 8853 GETCH 3225 GETCHG 3 5 0 1 GETCHL 01U2 GETE 5250 GKNT 5003 GON 3761 B A S I C RUNfIME GOSUB 0415 GOTSPT 1036 GR 0470 GS 0417 GSP 0447 G S P O T 0003 G S T C K 2314 GTFLG 42B0 GTlFLG 4263 WAhlGlld 7565 HGhCLK 7115 HGHTME 7 1 1 3 HOOKL, 3776 HdRO 0045 HORDP 0 0 3 6 I A 1464 IC 0056 IDbE 2270 IF 4424 IG a070 3534 ILOOP Q 2 1 2 ILOOPF 0 2 3 4 ILOOPL 8 1 1 3 ILOOP2 0214 XN 4033 INALQG 0277 INBFP BIB07 XNITFN 6427 INPHK 6521 I N P f C L 3477 XNPUT 5347 INSAV 0065 I N S A V P 06134 INSC 3413 INT 3400 I N T E R 5 1141 XNTL 0114 I N f P C 0035 I N T P O S 3420 I N T R E T 6764 IOTA6 2 @ 3 1 IQUT 5360 ISZAC2 6310 I S Z F G T 5275 IS2BIG 0065 I V Om60 I V G A I N 0@67 Z l L N L 7410 JEOFI 0450 J F A I L 0413 JFOR 2034 JMPFIL 1446 JMP1 0245 J M P I S A 0734 IGS J M P I S N 4012 J M P 1 2 0744 JMP13 1205 JMP16 1604 JMPUSR 1557 JMS1 0244 JWSIU 1417 JMS15 1 4 3 2 JMS17 1540 JMSSI 0303 JMSTAO 1531 JNEG 3466 JSL 2627 JUSNEG 3464 KC 3751 KC240 1140 KEX 3547 KFOl 5447 KKK240 3573 KKMl0 3704 KKMl2 5775 KK12 5313 KK13 4333 K42000 4067 KK40 3265 KK7 4730 KK7600 1253 KL7600 3744 KM€ 5306 KWl2 5135 KM13 5776 K M 1 4 4 5134 KM15 3754 KM20 4932 KM22 3777 UM4 0004 KM40 0105 UP7 4732 KNT 4737 KNTP 5154 KSKP 4110 KSKP2 4000 KUPARO 3750 UYBRD 7201 K0 4412 KO001 3464 K0a07C 3703 K O O 1 O 0073 K0014 0074 K0037 0740 K0Q37C 3677 K0Q57 3 7 0 1 K0077 0075 K0l0lrl 81676 K0200 06377 K0210 3205 K0300 4057 K0340 0 1 0 0 K0377 0 1 0 1 K1400 4313 Kl6 4721 K20 3266 K200 0077 K2000 4314 K215 0054 K232 3461 K240 3204 K26B 4056 42700 3 7 0 0 K300 6711 K4207K 4350 K5700 3702 K6 4740 K6000 3 7 7 2 K6213K 4 3 5 1 K6222 4572 K6223 4510 473 4564 K7400 0 1 Q 2 K7477 0 1 0 4 K7506 5 3 4 6 K7554 0 4 3 6 K7577K 43S2 K7600 0437 K7607K 3677 K7700 0 1 0 3 K7760 3662 K7773K 4353 L A S T B 3325 LDH 0131 LOHC 2075 LOYCDL 4504 LOHOF 2647 L D H I N I 2676 LOHINL 0127 LDHL 2646 LDHPR 4 5 0 1 LOHPST 2133 LDHPSW 4502 LDHR 2705 LDHSST 0157 LDHSWT 2704 LEN 3414 LEV 5477 LF 6452 LINEHI 0046 L I N E 1 1113 L I N E 1 1 1127 LINELO 0067 LK7607 3745 /OS/8 INDUSTRIAL B A S I C RUNTIME LM LMAKE 6360 4@60 LMAKEL 3566 LNE 0524 LNEFUC 7167 LNKSVE 6747 LNSET 1075 LN2 447 1 LNZOV2 4411 LOADOF 3163 LOG 4263 L O G C l 4455 LOGC3 4460 LOCCS 4463 LOGt?€ 44B6 LOQP 5052 LOP01 3 7 2 2 LOP02 3746 LQPl 6875 LOP2 be37 LORD 8046 LllRRP 0037 LOWCLK 7116 LOWTME 7114 LPY 1026 LROl 7361 LRESET 2165 LRSCOM 2 6 5 5 L S U B l I 1404 L S U B Z I 1Y13 LSlI 1401 LS2I 14BB LTRPRT 4302 L7466 3676 L7600K 4355 L7605K 3664 L7Q0SP 4356 L7607 1527 C7620 3 6 6 1 L 7 6 2 1 3663 47642 US71 L7644 3660 L 7 7 2 1 4573 L7727 4574 L7746 0354 MAKE0 4052 M A S K I 0031 MASKL 3427 MATCHL 1126 MCC 3747 MCDFl 6667 MCNTLC 7220 MCOCQN 4400 MCRMAL 3456 MCSPE 44B1 M C T H L Z 3103 YONE 3226 MDONE 5627 MQSET 5450 MDSETK 5774 MDSETP 5445 MRV s31i17 MD 1 5452 MDlP 5443 MFATAL 4136 M I N U S 5363 MIhUSP 3460 MINUS3 0355 MIN4 4354 MKbl 2727 MML 4501 MMM4 4415 MM260 3572 MNXTE 7112 M N I T E P 3757 MNTHCK 3760 MOOEBK 0064 MODESM B063 MONTH 3755 MPLP 5653 M P L P l 5654 MPLPZ 5666 MPY 2244 MPVLNK 0 1 2 1 MPlEL 5 7 0 1 MP12LP 2 2 5 1 MP24 5643 M1 4727 MlR 3470 M13 453B MI4 @la6 M215 0055 M240 5361 M6 4413 N A M E G 4416 NAMEGL 4050 NCG 4450 NCGS 4464 NCHK 4113 NCHKL 4262 NEMCDF 6 3 0 1 NEWTAG 7330 NEXRCK 4260 NEXREC 3275 NEYREL 0152 NFL4G 412@ NFLGST 4111 NGT 4257 NHNDLE 4103 NHNDLL 4261 PALB-VJ 9/20/73 3724 NOCZ 3420 NOP1 6111 NOP2 6053 NORMLP 6225 NOTE 4743 NULLS7 4370 NUM 4113 N X T A R G 7233 N1 4403 NlA 4542 N2 4404 N3 4U05 N3A 4402 4406 NS4 4407 N6 4410 N6A 4543 N7666 3 6 1 1 O A C H R 6455 OADB 6157 OPDDP 5 1 4 1 O A T A D I 1526 OCDF 2136 OE 1512 OLP 7015 ONE 3474 OhlEHAF 4466 ONERET 4472 ONE1 4475 OPENAF 4001 OPENAV 4000 OPEhlNF 4004 OPENNV Y003 OPERII 1200 OPH 0050 OPL 0051 OPNEG 6146 OPNEGP 5502 OPSR 6034 OPX 0047 O T R A P A 4532 OUT 5144 OUTDG 5150 OUT'OGP 4720 OVADD 1 5 1 1 OVDNE 1516 OVERLA 3400 OVML 0343 OVRLAY 1530 00 6354 PA 4415 P A C K C H 2735 PACKL 0145 PATCHF 5364 NOCTC PAGE 148n4 PATCHP 0155 PDNE 3216 PDP 5001 PHYCHN 0027 PINFO 0 3 5 6 PIOV2 4403 PLUS 5362 PNT 1763 POLYNL 4304 POLYSN 4026 POS 44QQ P O S I T N 4500 POSSET 4424 P O V T A B 0357 POWER 3472 PR 5016 PROCP 4776 PRDCPP 5143 PRES7 3542 PRNTX 5160 PRNTXP 4723 P R N T X l 5164 P R Z R O 5172 PRZROP 4724 PS 5023 PSFLAG 0 0 3 1 PSSTRT 0026 PSWAP 1230 PSWAP;! 4 3 2 1 PSWP2P 4544 PSlL 0360 PSZL 0361 PTR 7061 PTRBMP 2156 PTR1 0033 PUSKP 0 4 1 1 PUTCH 5247 PUTCHL 0112 PWFECH 0200 PWFECL 0120 PWRFLD 7574 PWRJMP 0107 PWRNAM 3552 PWRUP 011@ PZR 5015 PlCDF 1240 P l C D F l 1245 P l S W A P 0256 P2CDF 1243 P2CDFL 4566 P 2 C O F l 1247 P2CDLl 4567 P2SWAL 3743 P200 5211 QUAD2 4017 /OS/8 XNDUSTRIAL B A S I C R U N T I M E QUA03 4022 QUAD4 4a24 0042 QW R D I G I N 0453 ROIGOU US01 R O I T B C 0600 R D L I S T 7545 ROOTRL Id640 R f 3Cal0 READFL 300Q R E A D F W 3145 R E A 0 1 3105 READ17 0735 RELUSR 4 2 6 1 REPOWR 7555 R E S D L S 2552 R E S T 1 1650 R E S T O R 2555 RETMOL 3674 RETMOO 3521 R E T R N I 0456 RETRNO 3S71 R E T R N l 3610 RET@ 35h5 R I G H T L 2665 RIGHTS 2633 R I P T R 2455 RND 4544 RQ 6437 RONLY 3307 RQ6 0251 RSEEO 23U5 RSEEDC 4563 RTN2 5371 R T Z R O 5620 RWONC 3305 SAC 0316 SACCMK 2122 SACEM 2216 SACL 3421 SACPTR 0111 SACUBC 2106 SA# 0733 S A F I N D 1745 SARRAY 0 7 2 2 SASTHT 0 0 2 4 sc 2232 SCALDF 0314 SCALOL 1145 $CASE 0241 SCDF 1735 SCOMP 2051 SCBNTU 4462 SCQNl 22881 S C S T R T BIB21 SOIS B273 SDQTBL 41610 SE 4706 SEG 427 1 SEGCML 4373 S E G C O M 2222 S€P 5157 SEPl 0256 SETF 2044 SETTTY 6532 SETUP 1343 SEI 4707 SFN 2@@0 S F N L P 2023 SG 0054 SGN 3632 SHfTNO Of412 SHLFT 5635 S I G N F 5300 SIN 4000 SINAl 4367 S I h i A 3 4372 S I N A S 4375 SINA7 440B SI“ 0521 $LOAD 3146 SLOOP 3713 SLOVER 2 5 4 1 S L R C O M 261U SMODE 0 2 6 6 SNGQ 2117 S N E Q l 2116 SPFUNC l b @ B S P l N N R 0017 SWHPS 4452 SR 3127 SRCLP 4445 SREAR 2416 SRESET 0 3 7 0 S R F I N 2447 S R L I S T 24BQ SRLQOP 2 4 1 1 SSAO 4555 wasp 0510 SSLP 3156 SSMODE 2307 SSTEX 0 5 2 3 S S T O R E 41U73 ST 2444 STAENT 0465 START8 4272 START3 1 1 4 1 S T A R T 4 66062 STATE 0551 St8 3636 PPL8*V7 9/20/43 STCGTJ 3500 STCOM STCU0C STDF STOFL STFILK STFINO 1676 2124 1677 1163 0741 1664 S T F I N K 4503 S T F I N L 0302 STH 0130 STHDF 2603 STHDKK 0374 S T H I N I 2636 S T H I N L 0126 STHL 2600 STHR 2645 S T H R S T 016Q STHSWT 2644 STOPEM 1107 STOP1 4051 STOR 6750 STPCNT 12U6 STPTMR 1161 STR 3422 STRCNT 0071 STRLEN 01132 S T R M A X 0070 STRNGA 6374 STRPTW 0072 S T S L P 3U40 STSTRT 0023 SU 0623 SUB0 6125 SU60P 5 4 1 1 SUCJMP 0 4 2 6 SUPFUB 6400 sw 3256 SWCCP 2477 SWITCC 0 0 4 2 SWITl 0 0 5 4 SWIT2 0055 SWRITE 2460 s1 0033 S l P R A Y 6527 s2 0834 SZPRAY 6530 TAB 1753 TABLE 0226 TADTAB 1 5 3 2 T A G I T 0750 TAGITP 0352 T 8 L D Y P 3767 TBLSCN 0 2 3 3 TCLFLG 6 7 6 0 TDFIXL 4347 PAGE 1 4 8 r S 101 0476 TOOPfl 1 5 0 3 TDOFF2 0 5 4 3 TOONE 3553 TDSRCH 7 1 4 1 TO8Pl 6 6 7 2 TD8PZ 6673 TE 0066 TEMP1 0 0 4 0 TEMP10 0 0 6 1 TEMP11 0 0 6 2 TEMP17 3 0 2 3 TEMP18 3 0 1 6 TEMP2 0 0 0 6 TEMP21 2636 TEMP24 0 5 2 5 TEMP3 0 0 4 2 TEMP4 0 0 4 3 TEMP5 0047 TEMP6 00S0 TEMP7 0 8 5 1 TEN 5317 TICKS 0364 TIME 0677 T I M E R 1000 TIMEX 1105 T I M I N T 7117 1109 7121 0043 6353 7060 7055 7011 T M R T M l 7056 TMRTM2 7057 TM3 5155 TM3Pf 5304 TO 0064 TOOBIG 0256 TOBMNY 0063 TOUT 3272 T O V P I 4160 T O Z B I G 0042 TP 5314 T P R I N T 3524 TP1 5319 TRACE 3 7 7 0 TRHOOK / 1 3 4 TRPRET 1 0 6 5 TRREST 3775 TRYCLS 3 5 2 6 TSMET 7052 T S T T T Y 1042 T T C H C T 1032 TZNeNT TINCNZ TM TMPY TMRCNT TMREND TMRSCN /OS/8 INDUSTRIAL B A S I C TTESf2 4QQl TTFULP 10@3 TTGET 3 1 4 1 T T G E T P 1031 T T M O R E lF855 T T P U T P 1030 TTYBUF 6600 T T V C H K 1Q3U T T Y C H X 3565 TTYENO 6677 TTYF 6712 T T Y I N B 6600 T T Y S I Z 1033 T T Y T C F 1053 TTYUSR 4111 Tin 7063 TlHR 7073 T1L 7062 T l L N H 7103 T l L N C 71B2 TlLR 7072 T2H 7065 12HR 7075 TZL 7064 T2LNH 71@5 T2LNL 7104 TZLR 7Q74 13H 7067 73HR 7077 T3L 7066 T 3 L N H 7107 T3LNL 7106 T3LR 787b TYH 78171 TUHR 71Q1 TUL 7070 T4LNH 7111 TULNL 71112 f4LR 7180 UDCBAO 0850 UPCHNL 01@7 UDCI 7254 URCM3 6664 UOCTAG 7257 U R C T M l 7362 UDCTM2 7363 UDCWRK 7366 UDDI 6365 UDEI 6364 UOCA 6363 UDLB 6367 UDSC UQSF UDSS UNPACK UNSFXX UNSLP RUNTIME PAL8mV7 9/20/73 6353 )IDRITE XFLOAT XIT XLCOM XPUT XPUTCH XR0 XRl XR2 XR3 XR4 XRS XXllS XX212 xx4 X7607 YEAR 4522 4505 0456 4514 0122 1000 0010 QQll 0012 0013 0014 0015 2340 2313 2312 1235 3756 1513 5361 6351 3u47 1615 1642 UNSOUT 1646 UP 0134 UPDATE 37415 UPDAY1 3715 UPDAYZ 3720 UPLVL 6SU2 USE 2562 USECON 0005 USELOG 3613 USELOL 3 5 6 7 USH 0077 USHCAL 4072 USHCP 3470 USHERR 6763 USRREL 4183 USRRP 3 4 7 1 U123C 3056 VAL 346h VALCNT 3422 VALGET 3502 VALLK 0154 VALUE 0057 VR 3063 WOONE 3245 WE 3032 WHO 7535 W I D T H 0534 WQHDr4 0163 W Q R D l 0172 WORD10 8165 W O R D 1 1 0166 WQR012 8147 UDPD13 @ I 7 0 W O R D 1 4 0171 WORD2 El173 #OR03 8174 wQR04 0175 WORDS 0176 wQRR6 El177 WORD7 0164 MRaLK 3342 W R e L K K 3463 WROA 3112 W R I T E 1 3200 W R l T F L 3023 UDLS 6357 WRJTFW 6225 UORA UDRD UDRS 6356 6366 6355 W0YTR 3466 WQPTRA 3465 X O G E T 45@6 ZAPION ZCNT ZNP ZMINY ZR ZRCONT ZRQFF ZRORET Z2tZ 3773 6341 4334 1342 1352 1334 4470 7357 PAGE 148-6 INDEX - Absolute value function ABS (X), 6-5 ABSVAL subroutine, 11-18 Alphanumeric information, 7-1 Analog input (ANI) function, 8-5 Analog output (ANO) function, 8-5 Angle brackets ( < > I , 7-3 Arctan function - ATN(X1 , 6-7 ARGPRE subroutine, 11-14 Arguments passed to user function, 11-8 Arithmetic, 2-1 exponentiation, 2-5 functions, 6-2 numbers, 2-1 operations, 2-2 overlay, 11-26 parentheses, 2-3 priority of operations, 2-3 relational operators, 2-4 variables, 2-2 Array location, 11-20 Arrays, 5-3 Array symbol table, 11-7 ASC function, 7-5 ASCII conversion table, D-1 ASCII files, 10-1 ASR-33 Teletype, 1-3 Assembling the sources, E-1 Assembly language functions, 11-1 example , 11-27 Assembiy language/INBRTS interface, 11/23 Assignment statement, 3-4 Constants, 7-1 CONTACT statement, 8-3 Control commands, 1-7, 9-1, A-5 Control statements, 3-13 Conventions for alphanumeric strings, 7-1 Conversion ASCII/decimal number, 7-5 string/number, 7-6 Core layout, INBRTS, 11-2 Core usage, Field 1, 11-18 Correcting the program, 1-4, 9-1 Cosine function -COS (X), 6-6 Count (CNT) function, 8-7 Counter input (CN1) function, 8-6 Counter output (CNO) function, 8-6 COUNTER statement, 8-2 CTRL/ characters, 1-2 Data formats, 11-4 DATA list, in core, 11-6 DATA statement, 3-11 DAT$ function, 7-7 Debugging function TRC(X) , 6-9 Decimal formats, 2-1 DECwriter, 1-2 Definition of OS/8 Industrial BASIC, 1-1 DEF statement, 6-8 Deletion of character, 1-3, 9-1 of line, 9-1 of statement, 1-4 Delimiters, 10-4 Device driver space, INBRTS, 11-22 Devices, resident, 10-1 Diagnostics, compile time, B-1 run time, C-1 Dimension (DIM) statement, 5-2 Dimensioning strings, 7-1 DISMISS statement, 8-3 DLREAD subroutine, 11-17 Documentation conventions, 1-2 - Backslash ( \ ) , 3-3 BSW subroutine, 11-17 Buffer space, 11-22 BYE command, 9-8 Carriage return ( 3 , 1-2 Chaining, 10-1 CHAIN statement, 10-6 Character deletion, 1-3, 9-1 Characters ASCII, D-1 format control, 3-7 CHR$ function, 7-5 Clock (CLK) function, 8-4 CLOSE# statement, 10-5 Commands, 1-6 control, 1-7, 9-1, A-5 edit, 1-7, 9-1 Comments, 3-3 Compiler , 1-6 Compile time diagnostics, B-1 Concatenation of strings, 7-4 Considerations in assembly, 11-25 Editing commands, 1-7, 9-1 Editor, 1-6 End-of-file detection, 10-6 END statement, 3-4 Entering new program, 1-3 Equals (=) sign usage, 2-2 in IF-THEN statement, 7-3 Errors, typing, 1-3, 1-41 9-1 E-type notation, 2-1 Example program, 1-5, 3-1 assembly language function, 11-27 control program, 8-7 Exclamation mark ( 1 ) usage, 3-5 x-1 Executing the program, 1-4 Exponential format, 2-1 Exponential function - EXP(X), Exponentiation, 2-5 Extended I/O functions, 8-3 Interrupting program execution, 1-4 Interrupt skip chain, 11-28 I/O table, INBRTS, 11-22 6-7 Keyboard monitor, - FAC see Floating point accumulator Features of OS/8 Industrial BASIC, 1-1 File formats, INBRTS, 11-21 File overlay, 11-26 FILE# statement, 10-2 Files, 10-1 Fixed length files, 10-1 Floating point accumulator (FAC), 11-10 Floating Point Package, 11-10 Floating point routines, 11-11 FNA(X) function, 6-8 FOR statement, 4-1 Format control characters, 3-7 Functions, 6-1, A-6 arithmetic, 6-2 debugging, 6-9 extended input/output, 8-3 industrial, A-7 input/output, 3-5 transcendental, 6-6 user-defined, 6-8 1-3 Leaving the computer, 1-5 LEN function, 7-4 LET statement, 3-4, 7-3 Line deletion, 9-1 Line (LNE) function, 8-6 Line numbers resequenced, 9-2 Linking into the interrupt skip chain, 11-28 LIST command, 9-5 LISTNH command, 9-5 Lists, 5-1 Loader, 1-6 Loading OS/8 Industrial BASIC, 1-2 Logarithm function, 6-7 LOOPS, 4-1 nesting, 4-2 Mainline mode, 1-8 Matrices, 5-1 Messages, diagnostic, B-1, C - 1 MPY subroutine, 11-17 Multiple statements, 3-3 Multiply routine, 12-by-11 binary, 11-17 Generation of system, F-1 GOSUB statement, 6-11 GOT0 statement, 3-13 Hardware requirements, 1-1 Hints for assembly, 11-25 IF END# statement, 10-6 IF-GOT0 statement, 3-14 IF-THEN statement, 3-14, 7-3 INBRTS/assembly language interface, 11-23 INBRTS core layout, 11-2 file formats, 11-21 input/output, 11-21 Input of string data, 7-1 Input/output statements and functions, 3-5 INPUT statement, 3-5, 3-8 INPUT# statement, 10-4 Inserting statement, 1-4 Interfacing assembly language to INBRTS, 11-23 Interfacing Field 1 and Field 0, 11-19 Integer formats, 2-1 Integer function - INT(X). 6-5 NAME command, 9-7 Names of files, 10-1 Natural Logarithm function - LOG(X), 6-7 Nested loops, 4-2 Nested subroutines, 6-12 NEW command, 9-6 NEXT statement, 4-1 Numbers arithmetic, 2-1 printing format for, 3-8 resequenced line, 9-2 statement, 3-2 Numeric files, 10-1 OLD command, 9-6 Operations arithmetic, 2-2 relational, 2-4 Overlays, 1-6, 11-26 INBRTS, 11-3 Page 0 usage, 11-27 Parentheses usage, 2-3 Passing arguments to the user function, 11-8 x-2 PNT function, 3-10 POS function, 7-6 Power fail - restart, 8-9 PRINT statement, 3-6 PRINT# statement, 10-3 PRINT statement used with INPUT statement, 3-8 Print zones, 3-7 Priority of arithmetic operations,2-3 Program correction, 1-4, 9-1 entry, 1-3 example, 1-5, 3-1, 8-7 11-27 execution, 1-4 interruption, 1-4 loading and running, 1-2 subroutine, 11-15 termination statements, 3-4 Question mark (?) usage, 3-5 in string data, 7-2 RANDOMIZE statement, 6-4 Random number function - RND(X) , 6-2 Read digital input (RDI) function, 8-5 Read digital output (RDO) function, 8-5 READ statement, 3-11 Real time operations, 8-1 example, 807 extended functions, 8-3 power fail restart, 809 statements, 8-1 UPIR identification functions, 8-6 Relational operators, 2-4 in IF-THEN statement, 7-3 REMARK statement, 3-3 RESEQ program, 9-2 Resident devices, 10-1 Restart after power fail, 8-9 RESTORE statement, 3-12 RESTORE # statement, 10-5 RETURN statement, 6-11 Routines floating point, 11-14 unusable by Assembly Language functions, 11-25 RUBOUT, 1-3, 9-1 RUN and RUNNH commands, 9-8 Running OS/8 Industrial BASIC, 1-2 Runtime diagnostics, C-1 Runtime system, 11-2 Runtime system overlays, 1-6 - - SAC see String Accumulator SAVE command, 9-7 Scalar table, SHIFT/ characters, 1-2 SHIFT/L, 3-3 SHIFT/O, 1-3, 9-1 Sign function - SGN(X) , 6-4 Sine function - SIN(X) , 6-6 Spaces, blank, 1-2 Spaces in programs, 3-2 in statements, 2-4 Square root function - SQR(X), 6-6 Statement deletion or insertion,l-4 Statement numbers, 3-2 Statements, 1-6, 3-1 control, 3-13 elementary OS/8 BASIC, A-1 file, 10-1, A-4 input/output, 3-5 program termination, 3-4 real time, 8-1 State (STA) function, 8-7 STFIND subroutine, 11-16 Stop execution, 1-4 STOP statement, 3-4 STR$ function, 7-6 String accumulator (SAC), 11-7 String array table, 11-9 String concatenation, 7-4 String handling functions, 7-4 String overlay, 11-26 Strings, 7-1, 11-5 String symbol table, 11-8 String to number conversion, 7-6 String variable or array, locating a, 11-16 Subroutines, 6-1 GOSUB statement, 6-11 INBRTS, 11-11 nesting, 6-12 RETURN statement, 6-11 Subscripted variables, 5-1 Symbols used in manual, 1-2 Symbol tables, H-1 INBRTS, 11-4, 11-7 System build instructions, E-1 System components, 11-1 System generation, F-1 System performance, G-1 TAB function, 3-10 Tables, data, 5-1 Teletypes, 1-2 Terminal I/O, 11-21 Terminals, 1-2 Termination of program, 3-4 TIMER statement, 8-1 Transcendental functions, 6-6 TRC (X) debugging function, 6-9 Typing errors, 1-3, 1-4, 9-1 11-7, 11-14 UDEF function call, 6-8 Underlining, 1-2 UNSFIX subroutine, 11-16 SCRATCH command, 9-5 SEG$ function, 7-7 Send digital output (SDO) function, 8-5 x-3 Unusable r o u t i n e s , 11-25 UPIR see U s e r Process I n t e r r u p t Service Routine USE s t a t e m e n t , 6-8, 11-20 User p r o c e s s i n t e r r u p t mode, 1-8 U s e r Process I n t e r r u p t Service Routine ( U P I R ) , 8-1 i d e n t i f i c a t i o n f u n c t i o n s , 8-6 Using OS/8 11-27 - VAL f u n c t i o n , 7-6 Variable l e n g t h f i l e s , 10-1 Variables, 2-2, 7-1 s t o r a g e o f , 11-4 s u b s c r i p t e d , 5-1 XPUTCH s u b r o u t i n e , 11-15 Zero s u b s c r i p t , 5-2 Zeroes, s u p p r e s s i o n o f l e a d i n g / t r a i l i n g , 2-1 x-4 HOW TO OBTAIN SOFTWARE INFORMATION Announcements f o r new and r e v i s e d software, as w e l l as programming n o t e s , s o f t w a r e problems, and documentation c o r r e c t i o n s , a r e p u b l i s h e d by Software Information S e r v i c e i n t h e following n e w s l e t t e r s . DIGITAL Software News f o r t h e PDP-8 and PDP-12 DIGITAL Software News f o r t h e PDP-11 DIGITAL Software N e w s f o r 18-bit Computers These n e w s l e t t e r s c o n t a i n information a p p l i c a b l e t o s o f t w a r e a v a i l a b l e Articles i n D I G I T A L from D I G I T A L ' S Software D i s t r i b u t i o n Center. Software N e w s update t h e cumulative Software Performance Summary which i s i n c l u d e d i n each b a s i c k i t of system s o f t w a r e f o r new computers. T o a s s u r e t h a t the monthly DIGITAL Software N e w s is s e n t t o t h e a p p r o p r i a t e software c o n t a c t a t your i n s t a l l a t i o n , p l e a s e check w i t h t h e Software S p e c i a l i s t o r Sales Engineer a t your n e a r e s t D I G I T A L office. Q u e s t i o n s o r problems concerning D I G I T A L ' S software should b e r e p o r t e d t o t h e Software S p e c i a l i s t . I f no Software S p e c i a l i s t i s a v a i l a b l e , p l e a s e send a Software Performance Report form w i t h d e t a i l s of t h e problems t o : D i g i t a l Equipment Corporation Software Information S e r v i c e Software Engineering and S e r v i c e s Maynard, Massachusetts 01754 These forms, which are provided i n t h e software k i t , should be f u l l y completed and accompanied by t e r m i n a l o u t p u t as w e l l as l i s t i n g s o r t a p e s of t h e u s e r program t o f a c i l i t a t e a complete i n v e s t i g a t i o n . An answer w i l l be s e n t t o t h e i n d i v i d u a l , and a p p r o p r i a t e t o p i c s of g e n e r a l i n t e r e s t w i l l be p r i n t e d i n ' t h e n e w s l e t t e r . Orders f o r new and r e v i s e d software manuals, a d d i t i o n a l Software Performance Report forms, and s o f t w a r e p r i c e l i s t s should be directed t o t h e n e a r e s t DIGITAL f i e l d office or r e p r e s e n t a t i v e . USA customers may o r d e r d i r e c t l y from t h e Software D i s t r i b u t i o n Center i n Maynard. When o r d e r i n g , i n c l u d e t h e code number and a b r i e f d e s c r i p t i o n of t h e software requested. D i g i t a l Equipment Computer Users S o c i e t y (DECUS) m a i n t a i n s a u s e r l i b r a r y and p u b l i s h e s a c a t a l o g of programs as w e l l as t h e DECUSCOPE magazine f o r i t s members and non-members who r e q u e s t it. For f u r t h e r i n f o r m a t i o n , p l e a s e w r i t e to: D i g i t a l Equipment Corporation DECUS Software Engineering and S e r v i c e s Maynard, Massachusetts 01754 OS/8 Industrial BASIC DEC-S8-OSIBA-A-D READER'S COMMENTS Digital Equipment Corporation maintains a continuous effort to improve the quality and usefulness of its publications. To dothis effectively we need user feedback--your critical evaluation of this document. Did you find errors in this document? If so, please specify by page. How can this document be improved? How does this document compare with other technical documents you have read? Date : Job Title Name : Organization: Street: Department: City : State: Zip or Country FIRST CLASS PERMIT NO. 33 BUSINESS REPLY MAIL NO POSTAGE STAMP NECESSARY IF MAILED IN THE UNITED STATES Postage will be paid by: Digital Equipment Corporation Software Information Service Software Engineering and Services Maynard, Massachusetts 01754
Home
Privacy and Data
Site structure and layout ©2025 Majenko Technologies