Monday, August 29, 2016

HP 71B: Basic RPN Program

HP 71B: Basic RPN Program

The program RPNBASIC puts the HP 71B into RPN mode with arithmetic functions, power, square root, and π.  The program contains room for one independent memory and a four level stack that works like the classic Hewlett Packard RPN calculators.

I have the array S set up for six slots:
Slot 1: X stack (display)
Slot 2: Y stack
Slot 3: Z stack
Slot 4: T stack
Slot 5: Independent memory stack
Slot 6: (temporary memory)

For an idea of how RPN works, check out this tutorial:  http://edspi31415.blogspot.com/2011/09/rpn-basics.html

As a note, this program requires you to press the equals key [ = ] before you enter a number to the stack.

Example:   2 + 3 + 9 = 14
Keys:
[ = ], 2, [END LINE]
[ = ], 3, [END LINE], [ + ],
[ = ], 9,  [END LINE], [ + ]

The keys available during RPNBASIC:
[ = ] Input
[ + ] Add: Y + X
[ - ] Subtract: Y - X
[ * ] Multiplication: Y * X
[ / ] Divide: Y/X
[ g ] [ / ] (^) Exponent: Y^X
[ Q ]  Square Root √X
[ P ] Enter π to the stack
[ M ] Store X in independent memory
[ R ] Recall memory
[ C ] Clear X stack to 0

Stack operations:
[ S ] Swap with X and Y
[ D ] Roll stack down, result { Y, T, Z, X }

Exit the program: press [ E ]

HP 71B Program: RPNBASIC  (828 bytes)
5 ! SIMPLE RPN, EWS 8/29/2016
10 DESTROY S, K\$
15 DIM K\$, S(6)
20 OPTION BASE 1
25 DISP "RPN BASIC" @ WAIT 1
30 DELAY 0,0
35 DISP S(1)
40 K\$=KEY\$
50 IF K\$="+" THEN S(6)=S(1)+S(2) @ GOTO 100
52 IF K\$="-" THEN S(6)=S(2)-S(1) @ GOTO 100
54 IF K\$="*" THEN S(6)=S(1)*S(2) @ GOTO 100
56 IF K\$="/" THEN S(6)=S(2)/S(1) @ GOTO 100
58 IF K\$="=" THEN 140
60 IF K\$="M" THEN S(5)=S(1) @ GOTO 35
62 IF K\$="R" THEN S(6)=S(5) @ GOTO 120
64 IF K\$="P" THEN S(6)=PI @ GOTO 120
66 IF K\$="C" THEN S(1)=0 @ GOTO 35
68 IF K\$="S" THEN 160
70 IF K\$="D" THEN 180
72 IF K\$="Q" THEN S(1)=SQR(S(1)) @ GOTO 35
74 IF K\$="^" THEN S(6)=S(2)^S(1) @ GOTO 100
76 IF K\$="E" THEN 200 ELSE 40
100 ! 2 STACK OPERATION
105 S(1)=S(6) @ S(2)=S(3) @ S(3)=S(4)
110 GOTO 35
120 ! PI/RCL/INPUT
125 S(4)=S(3) @ S(3)=S(2) @ S(2)=S(1) @ S(2)=S(1)
130 GOTO 35
140 ! INPUT NUMBER
145 INPUT "NUMBER:";S
150 GOTO 120
160 ! SWAP
165 S(6)=S(1) @ S(1)=S(2) @ S(2)=S(6)
170 GOTO 35
180 ! ROLL
185 S(6)=S(1)
190 S(1)=S(2) @ S(2)=S(3) @ S(3)=S(4) @ S(4)=S(6)
195 GOTO 35
200 STOP

Examples:

Remember the order of operations!

Example 1:
22.5 - 12.3 * 3.3 = -18.09
[ = ], 12.3, [ END LINE ],
[ = ], 3.3, [ END LINE ], [ * ],
[ = ] 22.5, [ END LINE ], [ S ], [ - ]

Example 2: (5^2 + 1.4^3)/2 = 13.872
[ = ], 5, [ END LINE ], [ = ], 2, [ END LINE ], [ g ], [ / ] (^)
[ = ], 1.4, [ END LINE ], [ = ], 3, [ END LINE ], [ g ], [ / ] (^)
[ = ], 2, [ END LINE ], [ / ]

Example 3: π * 3.12^2 + (3.12 * 1.99) = 36.7903195271
Store 3.12 in memory.
[ = ], 3.12, [ END LINE ], [ M ],
[ = ], 2 , [ END LINE ], [ g ], [ / ] (^),
[ P ], [ * ],
[ R ], [ = ], 1.99, [ END LINE ], [ * ], [ + ]

Enjoy!

Note: this program can be expanded to include additional functions and calculations.

Eddie

This blog is property of Edward Shore, 2016.