Casio CFX-9800G-w Owners Manual - Page 172
Using, Subroutines, Important, Array, Memory
UPC - 079767128685
View all Casio CFX-9800G-w manuals
Add to My Manuals
Save this manual to your list of manuals |
Page 172 highlights
With this program, the first statements specify the unit of angular measurement and clear T to 0. Then the initial velocity is prompted for V and the angle is prompted for S. Lbl 1 identifies the beginning of the repeat calculation. The value stored in. T is incremented by Isz T, and in this program the lsz command is used only for incrementation, without any comparison or decision being performed. Each time T is incremented, the formula is calculated and the altitude is displayed. 12-9 Using Subroutines Up to this point, all of the programs we have seen were contained in a single program area. You can also jump between program areas, so that the resulting executionis made up of pieces in different areas. In such a case, the central program from which other areas are jumped to is called a "main routine". The areas jumped to from the main routine are called "subroutines". Note that you can use either another program stored in the program area or a program stored as a File Editor tile as a subroutine. Main Routine PO r- P3 Subroutines Prog 3 ,,,, ,- 1.- '39 Prog 2 ..„,_,-- Prog 4 "e " ---- Prog 8"-4-----....._ Pro,g 9.... ,,,_ / \_ / \ / • / Level I Level 2 Level 3 Level 4 To ump to a subroutine, use Prog (input using 131E ZEID(Prg)) followed by a program area name (0 to 9, A to Z, r, or 0) or the name of a File Editor file. Examples Prog 2 - Jumps to the program stored in program area number 2. Prog ABC - Jumps to the program stored in a file named "ABC". After the jump to the program you specify, execution continues from the beginning of the subroutine. When end of the subroutine is reached, execution returns to the statement following the Prog command that initiated the subroutine. You can jump from one subroutine to another, a procedure that is called "nesting". You can nest up to a maximum of 10 levels, and an error will- occur (Ne ERROR) if you try to nest an 11th time. If you try to jump to a program area that does not contain a program, an error message (Go ERROR) will appear on the display. Important •The Goto command does not jump between program areas. A Goto command jumps to the label (Lbl) located inside the same program area. -308 - •Subroutines Save Memory Note the following two programs. PO Fix, 3, :, ?, A, :, 2, x,C, 3, x, C . 2, e, 3, x, A, A , 3 P1 Fix, 3, :, ?, A, :, T, 3, x, A, x2,.4, V-, 2, +, 1 2 x A, A, 3 23 bytes 22 bytes If we input these two programs separately, they require a total of 45 bytes. But note that the underlined portions of these two programs are identical. This means that these parts can be stored as subroutines and called by both of the programs. If we use subroutines, we get the following results. Subroutines P9 Fix, 3 A, : , J- , 3, x,. A, x2 P8 C, 2, =, 3, x, A, A, 3 12 bytes. 8 bytes Main routines PO Prog, 9, :, Ans, x, 2, A, Prog, 8 P1 Prog, 9, A, Prog, 8, Ans, ÷, 4 9 bytes 9 bytes As you can see, the number of bytes required to store the two programs and the subroutines is 38, for a saving of 7 bytes. When you execute the program in program area 0, it immediately jumps to P9 and executes the contents of that program area. At the end of P9, execution returns to PO where the result produced by the subroutine in P9 is multiplied by 2 and then displayed. After you press the El key, execution jumps to P8, where the remainder of the program is executed. With the main routine in program area P1, execution jumps immediately to program area P9. At the end of P9 execution returns to P1 where the P9 result is displayed. When you press EL execution jumps again to P8. At the end of P8, execution returns to P1, where the result produced by P8 is divided by 4 and displayed. 12-10 Using Array Memory In addition to the individual value memories, the unit gives you array memory capabilities. Note the following. Value Memories A B C Array Memories A[0] B[ - 1] A[1] B(0] At2I B[1] Note *You cannot use r or 0 value memory as array memory. -309-