Flags
A flag is like a reminder. If you had to remember to say, pick up dinner on
the way home, you would do something to remeber you, like tie a string to your
finger. OK, you would never do that, but that's a classical example situation,
and I can't think of anything better to say at the moment.
Sometimes a program also needs to remember something. But a program can't tie
string to his finger. Alas, a program doesn't have fingers. But since I hate
anatomy lessons, let's stop that. So, what can he do to remember something?
One solution is to store a value in a variable that can later be compared to
see what he needed to remember. A flag is like such variable. It can contain
two values: set or clear. Like the true/false thing above, isn't it? Yes.
The HP has a little less than 64 flags that are reserved for its use. They
are the system flags. You can change the value of them, like any other, but
that yould change the form the HP operates. For example, system flag 40
(represented by -40 - positive flags will be seen later) contros the clock.
Your program can use it, but if the value of the flag is changed, the clock
visibility will also be changed.
Because of this, there is another kind of flag: the user flags. This
64 flags (represented by 1 to 64, the positive flags) aren't used by
the HP. You can use them without any problem.
OK, but what can I do with the flags? Simple, instead of tying a string to
your finger to remember to pick up dinner, set flag 4. Then, later, see if the
flag is set. If it is set, then you must pick up dinner. A program does that,
but to remember more important things (OK, I know your dinner is important to
you, but the HP does not mind starving.)
There are several commands to work with flags. They set flags, clear flags,
and check wheter they are set or not. Here they are:
SF | Sets the flag specified on level 1 |
CF | Clears the flag specified on level 1 |
FS? | Returns 1 if the flag is set, else 0 |
FC? | Returns 1 if the flag is clear, else 0 |
FS?C | Returns 1 if the flag is set, else 0; also clears flag |
FC?C | Returns 1 if the flag is clear, else 0; also clears flag |
RCLF | Puts a list with the value of all flags on the stack |
STOF | Sets the flags according to the list (generated by RCLF
on the stack) |