Itis
good
practice
in a
program
to
make
sure
that
any
conditions
you
will
be
testing
start
outina
known
state.
Current
flag
settings
depend
on how
they
have
been
leftby
earlier
programs
that
have
been
run.
You
should not
assume
that any given flag is
clear,
for instance, and
that it willbe set
only
if
something
in the
program
setsit.
You
should
make
sure
of this by
clearing
the
flag
before
the condition
arises
that
might set it. See the example
below.
Example: Using Flags. The "Quadratic Equation" program on page
191
in part 4
uses
flag
0 in
conjunction
withthe x
<©?
comparison
to
remember the signof
B.
Note that line
Qll
clears
flag
0 to makesure
that it will be set for
only
the condition desired.
Qll
CF 0 Makes sure that flag 0 is clear.
Q12x<0?
IsB(in
X-register) negative?
Q13 SF 0 Sets flag 0 if B is negative.
Q23 FS? 0 Is flag 0 set (is B negative)?
Q24
+•-
If yes, change sign.
Q25
+
In
either
case,
add.
Other
programs
in part 4 that
make
use of
flags
are
"Curve
Fitting"
and "UnitConversions." Theyboth use
flags
to remember which con
dition the user wants solved (which type of curve, which type of
conversion), thereby affecting which options or calculations are
chosen.
Loops
(GTO,
LOOP)
Branching backwards—that is, to a labelin a previous line—makes it
possible
to
execute
part of a program more than
once.
This
is
called
looping.
6:
Programming
Techniques
99