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.
D_JRA8iz
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.
tf00invtf00

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 AInitializes register A
0003 CFClears flags
0004 `DISPLAY SUM?`Creates message
0016 Y/NYES/NO Test
0017 SF 00{ YES } - set flag 00
0019 CLRClears message
0020LBL BBBegins loop
0023 BRKWaits for entry
0024 ST+ ASums entry to A
0026 TF 00Is flag 00 set?
0028 RCL A{ YES } -display subtotal
0030 GTL BBRepeats loop


Running the Example

Run the program and display the intermediate results.

Procedure

Press

Display

Start the program[ RUN ]
{ PGM }
D_BFMVxf
Specify YES{ YES }D_4v9w0z
Enter values25 { GO }D_o8KdYL
50 { GO }D_QXHI6D
6 { GO }D_umOOEf


Back