132 Section 9: Branching and Looping

Keystrokes

Display

 

 

 

(RPN mode)

 

 

 

 

 

 

 

go

003,

43

34

Tests whether number in X-register

 

 

 

 

(income) is less than or equal to

 

 

 

 

number in Y-register (20,000).

gi007

004,43,33,007

If condition is true, branches to

 

 

 

 

program line 007.

:2

005,

45

2

If condition is false, recalls 25%

 

 

 

 

tax rate to X-register.

gi008

006,43,33,008

Branches to program line 008.

:1

007,

45

1

Recalls 20% tax rate to X-register.

b

008,

 

25

Calculates tax.

 

 

fs

–190.22

 

 

Sets calculator to Run mode.

 

 

 

 

(Display shows results of running

 

 

 

 

of previous program.)

ALG program notes: We’ll key the income into the display before running the program. We’ll store it in R9 so it will be available for the examples in the next 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 executed.

Keystrokes (ALG mode)

f[ fs

fCLEARÎ

?9

Display

007,43,33,002 Sets calculator to Program mode. (Display shows program line at which execution was halted at end of preceding example.)

000,

 

Clears program memory.

001,

44

9 Stores income into register R9.

File name: hp 12c pt_user's guide_English_HDPMF123E27

Page: 132 of 275

Printed Date: 2005/8/1

Dimension: 14.8 cm x 21 cm

Page 132
Image 132
HP 12C Financial 12C manual 004,43,33,007, 006,43,33,008, Stores income into register R9