HP 9100B Operating & Programming Manual page 101

Hide thumbs Also See for 9100B:
Table of Contents

Advertisement

PROGRAMMING THE 91008
PROGRAM KEYS- CONDITIONAL BRANCHING
The next program illustrates use of the SET FLAG instruction as
a program step. The program calculates an alternating series:
1
-
3
+
5
-
7
+
9········-···00
NOTE
A series with s1mple terms is chosen as this program
s ntended to lllustrate use of the IF FLAG and SET
FLAG to alternately branch to either side of a loop.
The branching technique can
, however,
be easily
a-
dapted to any series with more complex terms
.
ln the program
,
each term (n) of the series is generated and
added to the accumulative total (P). As each term is added
,
one (1) is added to a counter (N)
,
to count the number of terms
.
The
sign of n m ust be a lternated (
+
or
-
); the flag is used to
determine whether to leave n positive or change the sign to
(-
).
This
is shown in the partial flow chart given below:
,--------------
1
I
I
I
I
I
I
I
I
r--1---,
I
Generate
1
I
Next
1
L
I
Value for n
I
__
t
__
_J
I
I
I
I
I
I
I
~(NO)
SET FLAG
CHANGE SIGN
(-
)n
(-
)n
(+
)n
Add (
+
)n to
P
Add
1 to N
L _________
_
__
_
_
...J
lf
the flag
is set:
(a)
positive (
+
)n is added to P;
(b)
the flag
is cleared.
The next time through the flag
is not set:
(a)
negative
(-
)n is added
to
P;
~ES)
(clears flag)
~
(+)n
(b)
the flag
is set [so
that
the next
time through
a
(
+
)n is
added].
91

Advertisement

Table of Contents
loading

Table of Contents