Manual / Guide · c. 1980
Sharp PC-1211 Beginner's Textbook for BASIC
Sharp's 52-page introduction to BASIC programming on the PC-1211.
Manual / Guide · c. 1980
Sharp's 52-page introduction to BASIC programming on the PC-1211.
PREFACE This text has been prepared for fast.and easy self-learning of the SHARP Pocket Computer PC-1211. The text begins with the chapter dealing with manual operation and develops further into higher programming techniques and deals with programming of higher frequency as pages go by. Problem, its Solution and Notes are provided in each section and Exercises are also available at the end of each chapter. You can advance to a next page when you are correct in soiving the Problem, or you must go through the Notes if you were to fail to make out proper understanding of the Problem and Solution, and you have to try to make further understanding through Exercises. In each section and Problem are affixed a grade marking according to a level of problem, and those who bound with studying time can proceed omitting some of high grade marks. (Mark with single asterisk ( xx ) denotes a middle grade, the one with double asterisks ( % >*},a high grade and triple asterisks ( x x¢ xx), a special grade. As the keyboard chart of the computer is attached in the Supplement-3 at the end of this text, anyone without the computer at hand may refer to it. Also, “BASIC” instruction sets and their mnemonics are provided in the Supplement—1, and the reader can use the list for convenience. With respect to detailed description of instructions, please refer to the Instruction Manual. TABLE OF CONTENTS Page Foreword Before studying “BASIC”. 1... ee ee 3 Chapter1 Manual operation ©... 0.0... ce ee eee eee ene 4 Section 1 Fundamental operation .. 0.0... . 0 cece ee ee ee eee 4 Section .2 Fundamental operation ... 0.0... eee ee eee 8 Section 3 Memory operation. ©... ee ee eee 10 Section 4 Reservable key operation... - 6... ec ee eee 13 [Exercise] 2... eee eee 15 Chapter 2. Programmed operation (1) 2.2... . eee 17 Section 1 What is the programmed operation? ... 0.0.0... 000 eee eee 17 Section 2 Linear sequence programming (INPUT, LET, PRINT, NEW, RUN, LIST, MEM). ...............00- 17 # Section 3 Various display methods (PRINT, USING, PAUSE)... 0... eee ee et eae 20 {Exercise] oo. eee ee eee 23 Chapter 3 Programmed operation (2) 2.6.6... eee eee 24 wz Section 1 Decision and jumping (IF eee THEN, GOTO)... ee eee 24 ¥ Section 2 Repeated operation (FOR NEXT)... ee ee eee eee 7 ¥ Section 3 Definable key operation... .- 0-0-2 ce eee eet ete eee 28 yeek Section 4 Indirect memory designation (one dimensional arrangement)..........- 29 {Exercise] 0. ee eee teens 30 Chapter4 = External memory (CSAVE, CLOAD, CLOAD?, CHAIN, CHAIN#, INPUT#) ... 0.2.0... 0005 31 Chapter5 Others... 0. eee 34 ve Section 1 Subroutine (GOSUB, RETURN) ...... cee eee eee 34 wz veSection 2 Debugging and others (DEBUG, STOP, CONT, BEEP, REM). .....-.. 00-0 cee cece eee 35 Chapter 6 Solutions and answers to Exercises... . 26... 0c eee eee 39 Supplement-1 List of instruction set... . 0... ee eee 42 Supplement—2 List of error codes... 6... te ee eee 46 Supplement—3 Keyboard chart... .. 0.0... cee ee eee 50 FOREWORD Before studying “BASIC” Recently, the word “BASIC” is often heard not only among computer engineers but among those ranging from elementary school to coliege students and white collars. It is one of computer languages which is the most prevailing among others. Why is it so? The word “BASIC” is the abbreviation derived from ‘Beginner's All purpose Symbolic Instruction Code”, which in itself implies easy understanding by the beginners. The program consists of conversational language without much restriction in its syntax and written in plain English and known for high degree of population because of easy comparison with the flowchart and advantages owing to fairly small numbers of instruction set used. Like human languages such as English, Japanese and German, varieties of languages are used for the computer languages’ and that BASIC is also one of computer ianguages like FORTRAN, COBOL, APL, etc. As there are dialogues in English like western and southern dialogues, there are also dialogues in BASIC as differently developed by each computer manufacturers, But, the fundamentals of the language is all the same. Although such kind of peculiarity may be seen in the BASIC used for PC-1211, it will be more powerfu! and effective as this class of compact computer and it will be welcomed by the users for its ease of operation and substantial functional performances. We are sure that you will appreciate these advantages. We hope use of this computer will help to increase routine efficiencies and, in addition, Knowledge you have acquired with this BASIC will assist you a great deal in using a higher class of machine in future time. As in car driving and golfing, simply reading a book would not help you much. You have to manoeuvre the steering wheel by yourself or swing a gold club by yourself in order to attain progress. It is natural that you can not attain much in the beginning as you can net make a par first time you are on a golf course. Don’t being called awkward or being laughed at, else you will be further delaying your progression. Key to progress is to practice programming and use the machine whenever possible. Well, let's start from the Chapter 1 with determination. Chapter 1 Manual operation Intension of this chapter is to master various fundamentals of operation in the manual mode. Preparation 1: Switch on Depress the key in the first place. Then, the prompt symbol “> will appear on the lefthand side of the display. Preparation 2: | Mode selection When power is on, either one of small indications, DEG, RAD, or GRAD, is brought up on the upper left of the display, and one of DEF, RUN, PRO, or RESERVE is also indicated on the upper right of the display. The former represents an angular mode which is used in the operation of trigonometric function, and the latter represents an operation mode, which will start chang- ing from DEF > RUN > PRO RESERVE > DEF in rotational sequence each time the key is depressed. To perform manual operation, it has to be set to [RUN] mode. NOTE: As the auto power off function is adopted in the computer, the power will be auto- matically turned off if the machine is left unused for approx. 7 minutes with- out performing any computation or key operation. (The power will be instantly shut off when the key is depressed.) A tiny dot symbol ‘+ ” appearing on the upper right of the display is a battery indicator, by which need for battery replacement is called for when this mark disappears from the display. Section 1 Fundamental operation [Problem] Perform the following calculations. () 248x4= @) 5x (€-6)= (3) 5X (-6)47= (4) 86+C14+2)= ats _ ® ss = () 1+20-84+405+4+6(07-8)))= 5x10°+(4x10") = (3) —1.2x€-4)+¢€-5)xX6= @Q) 2ux5= [Solution] () 2+ 4 (ENTER) 14. (2) 5 *~— 6 (ENTER —380. (3) 5%*—6 +7 (ENTER) 28. (4) 867C1+2 ) (ENTE) 12. () (€44+5)/7C 248 ) Ewen 1.8 (6) 1+2*(-8+4*(5+6* (7-8) ) ) (ENR —-13. (7) 5 Ee] 8/4 (Exel — 8 ENTER) 1250000. (3) —12*—-44—5 * 6 (ENTER) —25.2 (9) 27*5 31.41592654 [Notes] © Basic keys Add + Subtract - Multiply * Divide / Symbol +or— Execution (ENTER) © Operational priorities With this pocket computer, everything can be entered through the keyboard according to what the expression indicates including bracket and functions. Decision for sequential priority of data and processing of intermediate results can be automatically handled by the computer itself. Priority of computation takes place in the following sequence: 1. Function (such as sin, cos, etc.) Power calculation Symbol Multiplication & division Addition & subtraction Logical operation (such as >, >=, etc.) OQ PWN 2 NOTE: @ Bracket ‘{ }’’ takes precedence over every operations. ®@ Calculation of a compound function takes place from right to left (i.e. sin cos 30}. © Serial calculation of power is performed from right to left (i.e. 2/\3 /\ 2). © Po not make mistake in entering the bracket in the Problem (5). Compare the followings: 5 445 5 445+8 , pets, At gty © Operational buffer As seen in the Problem (4), number (36), in this case and function (such as /, (etc.) that “can not be calculated at one time is put into memory temporarily and execution takes place from the higher priority. Such a location as to store data temporarily is called a buffer, and the following numbers of stages are provided in this pocket computer. Numerical buffer ........-...005 8 stages Functional buffer ............... 16 stages © Length of formula 80 key operations are possible for an input of one formula (until the [ENTER] key is depressed). © Correction of erroneous key operation Anyone can make mistake. Therefore, the following method should be remembered to cope with erroneous key input. i) Depression of the key makes all display contents deleted with a > symbol appearing on the lefthand side of the display. Then, you can resume the operation from the beginning. ii) When other wrong key is depressed. Keep the [=a] key depressed until the error made sector appears flickering on the display, then make correct key entry. (Continuous depression of the =] or (=<) key makes the cursor moving.) : Ex: When 2+3*4 is entered as 2+3/4 inthe Problem (1), 2+3/4 L iii) When an extra key is depressed unnecessarily. Keep the (=«] key depressed until the unnecessary entry appears flickering on the display, then cancell that entry by depressing the key. Depressing the (DEL) key instead of the key will cause the same effect. (“DEL” stands for ‘‘delete’’.) Ex: When 2+ 3/4 is entered in the Problem (1), 2+3%*/4 L Depress the key, 24+3%*4 L ENTER 14. (correct) Let this portion be flickering, then depress * and [ENTER] . This section flickers on the display. This point flickers on the display. iv) When necessary key entry is skipped. Keep the (=«] key depressed until the skipped portion comes flickering on the display, then depress the [INS] key. (““INS” stands for “‘insert’’.) As there will appear one column of blank on the display, enter the skipped data or function to that blank area. Ex: When 2+ 34 is entered in the Problem (1), Depress the key 2+34 — Flickers Depress the [ins] key 2+304 Flickers Depress the * key 2+3%*4 Flickers Depress the [ENTER] key 14. (correct) © Playback function When either the [=] or [™] key is depressed after the execution of operation with the ENTER] key, it will restore the previous execution on the display. This will be convenient to make confirmation of the executed operation or when the execution is to be utilized successively after making some modifications. Especially, when an error is resulted after the execution with the [ENTE] key termination, it will be much convenient to locate the error portion as it is being flickered on the display. Ex: When an error is occurred with 36/1+2} (ENTER) in the Problem (4). Depress the [=a] key 36/1+2) i Flickering © Execution of continuous computation Depression of the [ENTER) key makes the result shown on the display, but the result can be further utilized in a successive operation. Ex: 142 (ENTER 3. 3 4. dENTER) 12. (execution of 3 x 4) © Cursor An underline “—" appears on the display when the key entry is made or it will appear flickering when error correction is made. This underline shows that the next key entry is placed in this portion. This is called a cursor. ° Error indication (see the List of Error Code in the Supplement—2) Operation error is indicated with “1----++++++e-e+e "on the display. Section 2 Functional operation in this section discussion is given about the performance of functions. [Problem] Perform the following calculations. (1) sin 80° +cos 60° x tan 45° = @ tan 2 = (3) sin( 15°+80°+2)= 4) J B+ = (8) sin? 30° = (6) log5 + 1n5= (7) Convert 30°30’ in sexagesimal notation into decimal notation. (8) Convert 30.5° in decimal notation into sexagesimal notation. [Solution] Set the angle mode to DEG in (1), (3) and (5), and to RAD in (2). (2) SIN380+COS 60* TAN 45 (ENTER) (2) TAN (7/4 ) [ENTER (3) SIN(15+80/72 ) [EMER (4) f C8A2+4+4A2 ) EMER) (5) SIN 802 (Nita) (6) LOG 5+LN 5. ([EnieR) (7) DEG 30.30 (enter (8) DMS 80.5 (ENTER) 0.25 2.808407917 30.5 30.3 [Notes] © Designation of angle mode It is essential to set up the angle mode to one of the following designation when any of trigonometric or inverse trigonometric function is to be processed. Angle mode Set up sequence Note Degree DEGREE (ENTER) A unit with which the right angle is expressed by 90°. Radian RADIAN (ENTER) Aunit with which the right angle is expressed by 20 . Grad GRAD A unit with which the right angle is expressed by | 100. © Outline of functional performance of the PC-1211. Almost all of the scientific calculators are provided with individual function keys such as SIN and COS, but, on the other hand, the most of the BASIC performance pocket computers are designed to enter the function code through the alphabetical keyboard, entering in the sequence of S, |, and N to express SIN, just as though through the typewriter keyboard. Function Symbol! in general Operation by this machine Trigonometric function sin SIN cos cos tan TAN Inverse trigonometric function sin“? ASN cos! ACS tan7! ATN Common logarithm log LOG Natural logarithm In LN Exponential function exp EXP Decimal-to-sexagesimal conversion DMS Sexagesimal-to-decimal conversion DEG Integerization INT Absolute value tx] ABS Square root Vv Jv Sign function SGN © Typewriter keyboard layout Does anybody not familiar with the typewriter keyboard think it is annoying to hit keys like S, | and N, and think it is far much better to use individual keys like and ? No, he is wrong. Operating multiples of keys counted up almost to 100, which are essential to perform varieties of functions, is not an easy practice. There are many instructions such as SIN, GOTO: - +--+, ete., for the operation of computer. It will be a hard job to remember all of key layout for any of individual key operated machine. Apart from this, different key layout is adopted depending on the manufacturer. On the other hand, the typewriter key- board is standardized worldwide under such as ASCII and JIS, and you will be accustomed to Pick up any key once you have been familiar with the typewriter keyboard which is composed of 30 to 40 keys. Being familiar with the typewriter keyboard will help you a great deal when you are to operate an upper class of computer. However, with this pocket computer, a reservable key method (Section 4) and mnemonics (Supplement—1) are provided for avoiding key annoyance. Section 3 Memory operation In this section is discussed memory configuration and its usage. [Problem] Perform the following calculations. (1) (i) Store 3 in the memory A and 4 in the memory B. {ii) Compute VAP +B? and store the result in the memory C. (iii) Check the contents of the memories A, B, and C in turn. (2) (i) Add 1 to each of A and B, above. (ii) Compute \/A? + B® and store the result in the memory C. {iii} Check the contents of the memories A, B, and C in turn. (3) (i) Store the word “SHARP” in the memory D and “PC-1211" in the memory E. (ii) | Recall memories D and E and check their contents through the display. ~10— [Solution] (1) (i) A=8 (ENTER) B= 4 (ENTER) or, A=3, B=4 (ENTER) (i) Caf (A*A+B*B ) (EMER) (iii) A (ENTER) 8. B ENTER! 4, Cc 5. (i) A=A+1 EWR B=B+1 [EtER) or, A=A+1,B=B+1 (MR) li) CHfCA*A+BxB) (iii) A (Wien) 4. B (ENTER) 5. C (ENTER) 6.4038124237 (i) DS="SHARP” _ (ENE) Eg="PC1L211" (ENTER) (ii) DS ENR) SHARP E$ — (Ewrea PC1211 -i1— [Notes] © Memory configuration CPC1211) A, AS, Ag), AX) B, BS , AQ), AS) Fixed : : : : memory 26 memories Z, Z$ ,A(26) A$(26) A(27) A$27) Flexible 178 memories memory or 1424 steps A204), AS(204) (Fig. 1) What is generally called a memory can be divided into the following categories. (In an upper class of machine the data memory is usually called a ‘‘variable’’.) Numerical memory (Numerical variable} Data memory (Variable) Character memory Memory (Character variable) Program memory —12— Memory configuration of this pocket computer consists of the fixed memory and the flexible memory. Fixed memory . Data storage consisting of 26 memories, A through Z. . This memory can be used for both program and data memory. For programming, 8 steps of programs equals one data memory. For instance, if a 16 steps of program is stored, it will reserve 202 data memories, since 16 steps consists of 2 data memories. (204 — 2 = 202) Flexible memory © Storing numerical number to the numerical variable A=3 [ENTER A=At1 As shown above, entry must be made in sequence of ‘numerical variable = formula [ENTER] ”’. (Numerical variable = formula is called a substitution.) ° Storing of character to the numerical variable The numerical variable is represented by affixing a $ {dollar mark) after the variable and up to a maximum of 7 characters can be stored in the numerical variable. “character” (ENTER) , or Character variable = character variable (gNTE) (Such an operation as ‘character variable” = “character” is also called a substitution.) Character variable In the BASIC programming, the character variable is called a string and “A$” is also called as A string or simply A dollar. © Other way of variable designation As shown in Fig. 1, such as B, B$, C, C$ can also be designated as A(2), A$ (2), A (3) and A$ (3). If it were to exceed 26 memory capacity, it has to be designated like A (27), A$ (27), A (28),.A$ (28), using this method. © Cancelling all data memory area Designation of “CLEAR “will clear all the data memory contents. Section 4 Reservable key operation [Problem] (1) Reserve SIN, COS and TAN to A, $, and D keys and compute sin 30°, cos 30° and tan 30°. (2) Reserve ‘’x 0.06 + 365” to the Z key and perform the following computation: 365 X 0.06 + 365 = 100 x 0.06 + 365 = —13— [Solution] (1) (i) Set to the RESERVE mode (depression of the [MQJE} key} {set} A SEN (sHFT) S COS (SHFT} =D TAN [ENTER {ii) Set to the RUN mode (depression of the [KODE] key) A 30 0.5 SHFT] S 30 [ENTER 8.660254038E-01 st] D 80 5.778502692E-01 (2) (i) Set to the RESERVE mode (depression of the [MQDE} key) (HT) Z + 067865 (ii) Set to the RUN mode (depression of the [MODE] key) 865 Z ~~ (ENTER) 0.06 100 (mt Zz 1.6488385616E-02 [Notes] Any constant data or instruction can be reserved through 18 reservable keys on the keyboard (A,S,D-+-+- a So , SPC). How to make reservation {i} Set to the RESERVE mode. (ii) A SIN ENTER Key operation to be reserved Reservation key Reserving frequently used instruction and key operation in any desired reservable key will allow you simple operation ( A, (SHFT) S, etc.). Your pocket computer may become custom tailored when you have reserved often used instructions in reservable keys, and it will give you convenience when you have noted the reservable key assignment on your template. —14— Ex. oO Oo wo sin cos tan Ma 4 & Your template NOTE: Reservation up to a total of 48 steps is possible with 18 reservable keys. [Exercise] 1.061428-456+789= 2.0 5X(-8)44= ~ 4 13xK02= 25 4. 24+3+6= 5. 248 _ g bv 5X5 41x2x8 2x2 9, sin30° + cos30° = 10, sin (80°+45°) = 1. os Bor + 40° _ 12, sin?30° + cos?3 0° = ~15-— 13. sm(—80°) = 2/3 we 14. 2464 15. lg3+ ing = 16. If the consumer price index rises by 7% each year, how many times the consumer price index wili be after ten years? * 17, Store —2, 1 and 3 to memories A, B and C, and compute the following expression. —-B + Jf B’-4AC 2A —~B — /BP-4AC 2A te 18. Assume A=9, B=—10, C= 1 in the equation Y = Ax? +Bx+C, and obtain the value of Y, when x = 0; when x = —2; when x = 3; when x = 0.5; —16— Chapter 2 Programmed operation (1) Section 1 What is the programmed operation? There may be repetition of a same routine in different calculation from time to time. Let's take the Pythagorean theorem for instance. The following routine procedure is observed to obtain the length of a pypotenuse of a triangle of which edges composing the right angle are 3m and 4m. J (8*8+4*4 > FENTER What if the edges composing the right angle are 4m and 5m? J (4 "4455 ) To obtain the hypotenuse, the same process routine is executed, except the parameters which may vary. Fixed routine like this may be stored permanently in the computer for the con- venience of eliminating the repetition of the same routine. The machine can follow the routine process as if performed by human being. To store a certain procedure in the computer is called a programming or called “‘to make a program’. In this chapter, we will discuss the programming. Section 2 Linear sequence programming (INPUT, LET, PRINT, NEW, RUN, LIST, MEM) [Problem] (1) Prepare a program which can produce area by the input of a radius. (2) Prepare a program which can produce length of a hypotenuse by the input of the length of two edges composing the right angle of a right triangle. [Solution] (1) 10 INPUT R 20 LET S=R*R*¥Z 30 PRINT S 40 END (2) 10 INPUT A,B 20 LET Caf (A*A+BxXB) 30 PRINT C 40 END -17-— [Notes] © Set the machine to the PRO mode before preparing a program. (Depression of the key) © With Input of “NEW [ENTER] ”’, the program and data previously stored are ali cleared, except the reserved memory. (The memory memorizing the reservable key (Section 4, Chapter 1) is called a reserve memory.) © Line @ With the BASIC, program is composed of several lines, and statement with various signifi- eances is contained in a single line. @ Line number is accompanied with integer of 1 through 999. @ To make up program in a line, the following procedure is required. — ENTER) (With ENTER! | termination of a line Line number Statement is defined. ) @ As the program takes place from younger line number, line numbers must be written in order starting from low order. However, it is the most common practice to furnish line numbers in an interval of ten considering occasional insertion of an additional line numbers. (i.e. 10, 20, 30----- etc.) © Statement ® Instruction or process formula having a specific significance is called a statement. @ A line may consist of a single statement or several statements. A colon “ : ” has to be inserted between statement when more than two statements are used, © INPUT instruction INPUT instruction is used to designate input of numerical value or character. The numerical variable or character variable has to be written after INPUT. INPUT A (a numerical value is assigned to variable A.) INPUT C$ (a character is assigned to variable C$.) If multiple numbers of numerical values or characters are to be input in succession, the follow- ing type of statement may be preferable. INPUT A,B INPUT C$, D$ © LET instruction LET instruction is used to prepare a substitution. The substitution is to be written after LET like “LET S=R%*R X77,” but LET may be omitted usuaily. © PRINT instruction When a variable is designated after PRINT, the contents of the variable is shown on the display. PRINTA (displays the contents of the numerical variable on right hand 16 columns of the display. However, it will be displayed in exponential expression when exceeds 16 columns capacity.) PRINT A$ (displays the contents of the character variable starting from the left hand side of the 24 display columns.} Character or formula may be written instead of variable. —18— © Correction, insertion, and deletion of program To make correction, insertion or deletion in a program line shown on the display, either the (=) or [™) key is used along with (EL) or [INS] key as we have learned in the chapter of manual operation. To delete a line, ‘line number " should be entered. Line insertion can be done in the following manner. Ex: When “S=R%*R%*7" is omitted in the Problem (1). 1 INPUT R 0 INPU < “S=R*R ¥*z” has to be inserted here. 20 PRINT S 30 END In case a program tine is to be inserted between the line number 10 and 20, pick up any number from 11 to 19 for program implementation. For example, “15 LET S=R*R %*a_ (EMER) “ may be entered. With this the program is corrected in the following manner. (This may explain why the line numbers are assigned by the leap of ten.) 10 INPUT R 16 LET S=R*R¥z 20 PRINTS 30 END NOTE: The program has not necessarily be written in order of low numbers, since the com- puter will rearrange them automatically by itself. NOTE: To change only a line number, use the [<4] key until the respective line number flickers, then change the line number. O Program listing Procedure to check program contents (i) CO key Each time this key is depressed, contents of a line currently on the display is replaced with a contents of a next line. Successive depression of this key causes continuous replacement. (ii) CE) key Each time this key is depressed, contents of a line currently on the display is replaced with a contents of a preceding line. Successive depression of this key causes continuous replacement. (iii) LIST instruction Entry of “LIST (Estes) ‘’ will bring the youngest line on the display. Entry of “LIST (EuTéR] ”’ will bring the indicated line on the display. Line number © How to count up program steps ® 80 key operation inciuding the key is possible in a single line. ® One instruction consists of one step. Although “INPUT” requires five key strokes, it is counted up as one step in the computer. @ Line number is counted as two steps. ®@ The key is counted as one step. ~19-— So, there are 25 steps in the Problem (1) and 32 steps in the Problem (2). © Checking unused program capacity MEM ENTER) Depression of this key displays unused steps in the flexible memory area and its equivalent to data memory is also indicated. When this key is operated after NEW, 1424STEPS 178MEMORIES After the loading of the program in the Problem (1), 1399STEPS 174MEMORIES © Program execution (i) Before the execution of a program, set the machine to the RUN mode. (ii) Then, start execution in the following sequence. RUN (starts execution from the youngest line number.) RUN (starts execution from the designated line number.) Line number {iii) As the machine comes to halt with “ ? " displayed when the machine encounters an INPUT statement, the execution should be resumed after entering {ENTER) , ¥ Section 3 Various display methods (PRINT, USING, PAUSE) [Problem] (1) With reference to the Problem (1) in the last section, Make display of ““RADIUS._;R =” when the radius is to be entered. Bring to indicate the radius on the left half of the display and the area on the right half when the area is output. (2) With reference to the Problem (2) in the last section, Make display of “A = B= ‘when input is to be made for two edges. Display the results ina manner of “A=OOO B=OOO C=O00.00" when the hypotenuse is output. —20— [One example of Solution] (1) 10 INPUT “RADIUS , R=", A 20 S=A*A*Z 30 PRINT A,S 40 END (2) 10 INPUT “A=":A,"B="5B 20 Caf (A*A+Bx*B) 30 PRINT "A="; USING “###"; A; “B=” ; USING “###" > B "C="; USING “SHEE HET 5 C 40 END Note: |, stands fora key in this text. [Notes] (1) Method to display a message at the time of input (i) INPUT “character”, variable Ex: INPUT “A=", A (ii) INPUT “character’’; variable Ex: INPUT “B="", B With (i), entry of numeral causes the message cancelled, but, with (ii), the input data is displayed following to the message, without cancelling the message. (2) Various use of PRINT instruction (i) PRINT formula NOTE: The expression ‘formula’ applies to the expression composed of numerical variable, numericais, numerical expression and numerical! variable. ie. (A) (5) (56) (2% A + 3) Ex: PRINTA (The contents of A is displayed on right hand 16 columns of the display. However, it will be displayed in exponential expression when exceeds 10 digits.) (ii}, PRINT character variable Ex: PRINT AS (Contents of A$ is displayed from the left hand side of the display.) (iii) PRINT “character” Ex: PRINT “SHARP PC-1211" (Character is displayed from the left hand side of the display.) ~2)— (iv) PRINT | formula , formula “character” “character” character variable character variable 24 columns of the display is divided into 12 columns each, and display of data is right justified and characters are left justified within these divisions. {v) PRINT | formula ; | numerical variable | ;--+ ;{ numerical variable “character’” “character” “character” character variable character variable character variable | The contents after the PRINT instruction is displayed in left justified manner within 24 columns. (3) USING instruction With the USING instruction, display format of the numericals is designated. General form of the USING instruction USING “###"" (displays 3 digits of integer including sign.) USING “###." (displays 3 digits of integer including sign and decimal point.) USING “###.##" (displays 3 digits of integer and 2 digits below the decimal point, including sign and decimal point.) USING “##.##/\" (numbers down to 2 digits below the decimal point is displayed in exponential expression.) {2 digits of integer are displayed for mantissa including sign, and 4 digits of exponent (E-OO), including sign, is automatically taken up in this case.) (i) Simple use of USING statement 10 USING “###.##" 20 PRINT A; B; C Display example: When A= 12.345, B = —34.567, C=5, [ 12.34 — 34.56 5.00 uw LoL Space 2 spaces {ii) To use as a PRINT USING statement, containing a USING instruction within the PRINT statement 10 PRINT “A="; USING “###'; A; “_B="; USING “###; B; C="; USING “tH dE” | C Display example: When A=4, B= 10, C = 10.7703, A= 4 B= 10 C= 10,770 | wu LI Lo LJ Spaces —22— (iii) Release of USING designation After designating the display format with the USING instruction, format designation in the successive PRINT instruction wiil be controlled by this designation, Thereby, it has to be released using the above statement when it is not required. (4) PAUSE instruction On the contrary to the PRINT instruction that stops the program execution, the PAUSE instruction acts to hold the display for a certain period (about 0.85 second) and resumes the program execution again. Other details are the same as the PRINT instruction. [Exercise] 1. w 3. Prepare the program which will produce the length of circumference after the input of a radius of a circle. £= 20r . Prepare the program which will calculate interest after the input of principal and period. Whereas, the rate of annual interest is 6% and truncation must be made below the dollar point. 0.06 365 ) (Interest = principal x period x In the above problem, prepare the program which will calculate interest after rounding the figure below the dollar point. . Prepare the program which will produce the area after the input of the length of three edges of a triangle. Heron’s law: Area = Vs (s —a) (s —b) (s —c} a +bte 2 il Where, $ . Prepare the program which will generate the following display layout, using the PAUSE instruction. | SHARRPC1211, HAS | | 1424, STEPS, , 26, ,MEMORIES | | | —23— Chapter 3 Programmed operation (2) In this chapter more sophisticated programming technique will be discussed, Successful com- prehension of the Section 1 will give you almost complete understanding of this pocket com- puter programming. yx Section 1 Decision and Jumping (IF THEN, GOTO) [Problem] (1) Prepare the program which will summarize the total of admission charges after the input of the numbers of audience entering the theater. Where, the ordinary admission fee costs $10 each up to 10 persons, but group discount of $8 is applicable for a group consisting of more than 10 persons. Display the numbers of audience on the left side of the display and the summary of admission charges on the right hand side. I Audience 8 $ 80 [Solution] 10 INPUT “AUDIENCE="; A 20 IF A>=10 THEN 60 30 B=10*A 40 PRINT “AUDIENCE”; USING “###"; A; “LiL $3 USING “HHH 5B 50 END 60 B=8xA: GOTO 40 {Another Solution] 10 INPUT “AUDIENCE ="; A 20 IF A>=10 LET B=8*A:GOTO 40 30 B=10*A 40 PRINT “AUDIENCE” ; USING “###"; A; “1118”; USING “##HHH” 3B 50 END —24— [Notes] O° IF instruction Various decision is made with the IF instruction. IF A>=10 The above statement defines to execute the program described after IF (when the IF state- meni is not satisfied), the prograrn following this line will be executed. Usually, the IF statement is used in the following forms: IF - IF - IF - IF. [Fo XXX lnterrogates if equal XXX Interrogates if larger than XXX interrogates if equal or larger than XXX Interrogates if smaller than XXX Interrogates if equal or smaller than xX X Interrogates if not equal Such instruction as ““THEN 60” is usually used after the IF statement, so as to jump to the line number 60. Sometimes, it will be much easier to understand if a conditional program is placed after the IF statement as shown in the Another Solution. (The substitution immediately after the IF statement must begin with LET without fail.) GOTO instruction Usuafly, the program is executed in order of low line numbers, but execution of this GOTO instruction will cause’ to jump the program to the line number indicated after the GOTO instruction. Ex. GOTO 40 (Jumps to the line number 40.) GOTO 5*8 (Jumps to the line number 40.) GOTOA (Jumps to the line indicated by A. If A = 40, for instance, the program then jumps to the line number 40.) GOTO “A” = (Jumps to the line number which is denoted with the Label A.) Ex: 20 GOTO “A” This causes to jump from the line number 20 to 30 B= 1000*A 40. Jump like this is called a label jump, which lan 7 7 can be designated with character up to 7 40 “A” PRINT “AUDIENCE”; --- chatacters. How to make up a program It is not an easy practice to complete program simply looking over the problem. Ordinally, outline of computation is embodied into a drawing to check programming flow. This drawing of flow is called a flowchart. Perfect completion. Therefore, it is the fastest way for better programming to get familiar with flowcharting in the first place. —25-— With the flowchart in completion, it is the time to decide to which variable the data is to be assigned. Then, program coding is carried out using BASIC instructions. Flowchart of the Problem in this section: Start Input numbers of audience Audience > 10 ? NO Nos. of audience. Admission fee - - - - Admission = nos. | of audience x 8 audience Admission = nos. of x 10 Display nos. of audience and total ad mission. 20 30 40 50 INPUT A IF A>=10 LET B=A *8 : GOTO 40 B=A*,10 PRINT A,B END Although various notations are used in the example, it can be thought as a kind of accessories. It is of a primary importance to prepare the flowchart like the above before writing the program. —26— ¥ Section 2 Repeated operation (FOR, TO, STEP, NEXT) [Problem] Display the results from sin O° through sin 90° in an interval of 2°, with the angle displayed on the left hand side and the value of sine on the right hand side of the display. (Use the PAUSE instruction.) [Solution] 10 FOR A=0 TO 90 STEP 2 20 B=SINA 30 PAUSE USING “FE; A; USING “ERIE. dHABHE" > B 40 NEXT A 50 END [Notes] © General form of FOR NEXT For numerical variable = initial value TO final value STEP interval j NEXT numerical variable The numerical variable will increment by the given interval starting from the initial value and the programs described between FOR and NEXT are repeated until the numerical variable reaches the given final value. © The FOR instruction must be used in pair with the NEXT instruction, and that the numerical variable after FOR must be identical with the numerical variable after NEXT. o “STEP 1” may be omitted when the interval is 1. © Up to 4 stages of programs can be contained in a FOR NEXT statement. © Negative number may be used in defining the interval. If the following statement is filled up in the line number 10 of the Problem, it will display the results from sin 90° to sin O° in an interval of 2°. 10 FOR A=90 TO 0 STEP—2 -27- Section 3 Definable key operation [Problem] Prepare programs which produce the area of a circle and the circumference of a circle, and make them executable with the use of the A and Z keys, respectively. [Solution] 10 “A” INPUT “R=";R 20 S=R*R*Z 30 PRINT “S=",S 40 END 50 “Z" INPUT “R=";R 60 L=2*Rx*Z 70 PRINT “L=",L 80 END [Notes] Up to now, the machine is set to RUN mode and “RUN ENTER) ‘’ is entered to begin execution of program. However, there is another method to start instant execution of program by entering “ (sxet] =A” and such after setting the machine to the DEF mode. If label is assigned to one of 18 reservable keys (A, S,--- =, Z,--+, SPC, etc.), it is possible to start the program by the depression of the key corresponding to the label following to the entry of ‘’ (HFT) ’’ in the DEF mode. When numbers of programs are in the memory, the desired program can be chosen auto- maticaliy with this method. It will be much convenient in operating the computer when kinds of programs and names are inscribed on the template. In this Problem, the following notations shall be given on the template. CB fw Area of circle Z Circumference Template 2 In case the Problem is to be operated under the RUN mode, it is necessary to make selection of program lines. These kinds of decision making is very much troublesome when numbers of programs are to be used in the operation of a single task. RUN (ENTER) RUN 50 CENTER| ye¥Section 4 — Indirect memory designation (one dimensional arrrangement) [Problem] There are 10 kinds of merchandizes. Prepare the program which can summarize total numbers of each merchandize with code output. Whereas, input is merchandize code and quantity. [Solution] 10 “A" INPUT “NO=";Y , “QTY=";Z 20 A(Y) =ACY) +Z 30 GOTO “A” 40 ““Z" FOR Y=1 TO 10 50 PRINT “NO="; USING “dHRE’ > Y > USING "HeREHE. > ACY) 60 NEXT Y 70 END 80 =" CLEAR 90 PRINT “ALL,,CLEAR” 100 END {Operational example] Template [aj (=] Input Clear (Zz Total —29— Set to the DEF mode A vreseseecteeertneaeees Input process es Merchandize code ENTER Repetition Quantity — [ENTER| Zo site eeeeeeeeeeeneeees Output of each summary. _ > Repetition Displays code and quantity ENTER _ (QHFT) ee eteseeeeeeseeeeeeees Clears all [Exercise] vx 1. Prepare the program which can produce the root of the equation “Ax? + Bx +C = 0". Whereas, the parameters A, B, and C are the input (A #0). However, | display two roots on the first and second halves of the display, when B? — 4AC = 0, and display “NO ANSWER”, when B? -- 4AC <0. “ 2. Prepare the program which can solve ‘‘m+(m+1)+(m+2)+--+-+n” after substituting m and n. m and n are integer and m <n. ¥ 3. Prepare the program which can solve “‘nl’’ after the input of n. (n! isa factorial of n. ie. 1x2x3---xn). 4. Prepare the program which can produce the value of sine from sin 0° through sin 90° in an interval of 10°. —30-— Chapter 4 External memory (cassette tape) (1) (2) (3) (4) (5) (CSAVE, CLOAD, CLOAD?, CHAIN, PRINT#, INPUT#) CSAVE “Program file name” CLOAD “Program file name” Computer Cassette tape CHAIN “Program file name’, formula PRINT# “‘Data file name” ; Variable INPUT# “Data file name” ; Variable CSAVE “program file name’” Entire programs in the computer are stored in the cassette tape with their program file names. Up to 7 characters of file name is acceptable. CLOAD “program file name” With this statement, the program with the given program name is automatically searched in the cassette tape to be transferred to the computer. CLOAD? “‘program file name” With this statement, the program in the computer is collated with the program in the cassette tape on the basis of the given program file name. Train yourself to observe this operation whenever CSAVE or CLOAD is executed. (This is mandatory to safely implement your precious program to the computer.) CHAIN “program file name”, formula When this statement is encountered in the midd