Using Flags
Flags give you a way to retain information about the state of the calculator or the status of a variable for later use. For example, you might set a flag if the value of an intermediate result is negative. Later, you can test the flag to see if the number was negative, even though the number itself is no longer available.
What Is A Flag?
You can think of a flag as a two-position switch that is either set or reset. You can:- Set a Flag.
- Reset (or clear) a Flag
- Test whether a flag is set.
- Test whether a flag is reset.
After you set or reset a flag, that setting is retained until you change it. Although you can set or reset flags from the keyboard or in a program, you can test a flag only in a program.
User Flags
The RPD-95 has 16 user flags, numbered 00 through 15, that you can use. Additional flags used by the calculator and by library cartridges are discussed in Appendix C.Flags 00-14 can be used as needed in a program.
Flag 15 is the halt-on-error flag. When this flag is set, any error condition that occurs while a program is running causes the program to halt.
When flag 15 is reset (the default condition), the following errors do not stop the program.
- OVERFLOW
- INVALID ARGUMENT
- AOS STACK FULL
- I/O ERROR nnn
By executing the LS ( list status ) instruction and then examining the numeric display register, the program test whether any of these errors has occurred and can handle the error as you prefer.
The Flag Functions Menu
When you press [ FLAGS ], the following menu is displayed.This menu enables you to select the following flag instructions.
{ CF } - Clears (resets) user flags 00-14. The instruction mnemonic for this is CF.
{ SF } - Sets a specified flag.
{ RF } - Resets a specified flag.
{ TF } - Tests whether a specified flag is set.
[ INV ] { TF } - Tests whether a specified flag is reset.
The { SF }, { RF }, { TF }, and [ INV ] { TF } instructions are followed by a two-digit numeric field that specifies the flag. For example, { SF } 01 sets flag 01.
Testing a Flag
A test flag instruction affects program control in the same manner as a comparison or DSZ test.Example
The following program uses flag 00 to record your response to a Y/N test. The program then executes a loop that sums entered values to register A. On each pass through the loop, the program tests the flag to determine whether is should display the subtotal. Notice that the examples uses CF at the beginning of the program to make sure all flags are in a known state.PC = | Program Mnemonics | Comments |
---|---|---|
0000 | 0 STO A | Initializes register A |
0003 | CF | Clears flags |
0004 | `DISPLAY SUM?` | Creates message |
0016 | Y/N | YES/NO Test |
0017 | SF 00 | { YES } - set flag 00 |
0019 | CLR | Clears message |
0020 | LBL BB | Begins loop |
0023 | BRK | Waits for entry |
0024 | ST+ A | Sums entry to A |
0026 | TF 00 | Is flag 00 set? |
0028 | RCL A | { YES } -display subtotal |
0030 | GTL BB | Repeats loop |
Running the Example
Run the program and display the intermediate results.Procedure | Press | Display |
---|---|---|
Start the program | [ RUN ] { PGM } | |
Specify YES | { YES } | |
Enter values | 25 { GO } | |
50 { GO } | ||
6 { GO } |
☚ Back