134 Section 9: Branching and Looping
ALG program notes: We'll key the income into the display before running the
program. We'll store it in R
chapter. By keying the income into the display before running the program, we
ensure that it will be in the X-register when the :0 instruction in program line
002 is executed. This instruction will place the test value 20,000 in the X-register
and move the income into the Y-register. The ~ instruction in program line 003
will exchange the numbers in the X- and Y-registers: that is, it will place the income
back into the X-register and place the test value into the Y-register. This is
necessary because when either the :2 instruction in line 007 or the :1
instruction in line 009 is executed, the number in the X-register is moved into the
Y-register; if the ~ instruction were not included, the test value 20,000, rather
than the income, would be in the Y-register when the b instruction in line 010 is
004,43, 33, 007
006,43, 33, 008
so it will be available for the examples in the next
007,43, 33, 002
Tests whether number in X-register
(income) is less than or equal to
number in Y-register (20,000).
If condition is true, branches to
program line 007.
If condition is false, recalls 25%
tax rate to X-register.
Branches to program line 008.
Recalls 20% tax rate to X-register.
Sets calculator to Run mode.
(Display shows results of running
of previous program.)
Sets calculator to Program mode.
(Display shows program line at
which execution was halted at
end of preceding example.)
Clears program memory.
Stores income into register R