Using Flags - HP -11C Owner's Handbook Manual

Hide thumbs Also See for HP-11C:
Table of Contents

Advertisement

116
Section 7: Program Decisions and Control
Using Flags
Like the x: y and x:0 conditional tests, flags give you the capability
to either skip or execute individual lines in program memory.
However,
while
the x:y
and
x:0 conditionals
function
by
comparing values, flags function by telling the calculator status.
That is, if a set flag ((9](SF]n) instruction is placed in a program
branch, testing that flag elsewhere ((¢]
n) can tell the
calculator whether or not that branch has been executed.
Example.
The
following
program
closely approximates
the
conversion of an input in miles to kilometers ((f] [A]), or the
conversion of an input in kilometers to miles ({f)[B)). The calculator
uses the status of flag 0 to decide whether to convert a user input to
kilometers (multiply input by conversion factor) or to miles (divide
input by conversion factor).
Key in
kilometers.
Start
Set flag.
Place
1.6093
in X-register.
~~
~~
eee
ee
ee
ee
Section 7: Program Decisions and Control
117
Keystrokes
Display
((F7R
000-
Sets HP-11C to Program
mode.
(ACLEAR [PRGM
000-
Clears program memory.
LBLI[A
001-42,21,11
Program begins with
input in miles.
(s){cFEJo
002-43,
5, 0 Flag Ocleared
("remembers" miles input
for later program control).
Gro}!
003-
22
1
Unconditional branch to
LBL)1.
(eC) (B)
004-42,21,12
Program begins with
input in kilometers.
9 )(SFJO
005-43,
4, 0
Flag 0 set (''remembers"
kilometers input for later
in program).
(cet) 1
006-42,21,
1
((BL)1 begins
calculation portion of
program.
1
007-
1
QO
008-
48
6
o0g-
6 \ Place conversion factor
0
010-
O
(in X-register.
9
011-
9
3
012-
3
9)(F)0
013-43,
6, O Flag test. If true (kilo-
GTO|2
014-
22
2 = meters input), go to(LBL)2.
x
015-
20 = If flag test false (miles in-
9 )(RTN
016-
4332
put), calculate conversion
to kilometers and halt
program.
(LBL) 2
017-42,21,
2
Calculate conversion to
&
018-
10
miles and halt program.
Ca) (RIN
019-
4332
9 |[P/R
Sets HP-11C to Run mode,
Run the program to convert 26 miles into kilometers; to convert 1.5
kilometers into miles.

Advertisement

Table of Contents
loading

Table of Contents