Post Reply 
(71B) Basic RPN Program
08-30-2016, 03:46 AM
Post: #1
(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)
Code:
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
Visit this user's website Find all posts by this user
Quote this message in a reply
05-12-2024, 09:34 PM
Post: #2
RE: (71B) Basic RPN Program (see second post)
This is a repost of a basic program for the HP 71B. I received an email from Kenneth who pointed out that line 145 lead to an error. In further testing, this lead to the input routine not working correctly. The following code in today’s repost is a corrected algorithm. Edited lines are 5, 125, and 145.

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)

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 ]

Code:
5 ! SIMPLE RPN, EWS 5/12/2024
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(1)=S(6)
130 GOTO 35
140 ! INPUT NUMBER
145 INPUT "NUMBER:";S(6)
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
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 1 Guest(s)