106 Section 9: Branching and Looping
Example: The following program calculates income tax at a rate of 20% on
incomes of $20,000 or less and 25% on incomes of more than $20,000. To
conserve program lines, the program assumes that the test value – 20,000 – has
been stored in register R
0
and the tax rates – 20 and 25 – have been stored in
registers R
1
and R
2
, respectively.
Note: If a program requires that certain numbers be in the X- and
Y-registers when instructions such as o are executed, it is extremely
helpful when writing the program to show the quantities in each register
after each instruction is executed, as in the following diagram.
We’ll key the income into the display before running the program so that it will
be in the X-register when the :0 instruction in program line 001 is executed.,
This instruction will place the test value 20,000 in the X-register and (as
explained in Appendix A) move the income into the Y-register. The ~
instruction in program line 002 will exchange the numbers in the X- and
income
income income income income
income
Keys
Line
001
002
003
004
007
Keys
Line
income income income income
tax
# $ % &