Post Reply 
(20S and 21S) RPN Simulator
06-08-2017, 01:03 PM
Post: #1
(20S and 21S) RPN Simulator
This program will allow the user to simulate RPN (Reverse Polish Notation) for five arithmetic functions: addition, subtraction, multiplication, division, and exponentiation (power). All operations take the form of enter Y, press [INPUT], enter X, [XEQ] (appropriate key).

Labels:
XEQ A: Y + X
XEQ B: Y – X
XEQ C: Y * X
XEQ D: Y/X
XEQ E: Y^X
XEQ F: “clears” the stack.

The result shown in the display while the X value is left in the hidden display, which can be accessed by pressing [ LS ] (SWAP).

The key codes for the HP 20S and HP 21S are the same.

Code:

STEP    CODE    KEY
01    61, 41, A    LBL A
02    21, 0    STO 0
03    51, 31    SWAP
04    21, 75, 0    STO+ 0
05    22, 0    RCL 0
06    61, 26    RTN
07    61, 41, B    LBL B
08    21, 0    STO 0
09    51, 31    SWAP
10    21, 65, 0    STO- 0
11    22, 0    RCL 0
12    32    +/-
13    21, 0    STO 0
14    61, 26    RTN
15    61, 41, C    LBL C
16    21, 0    STO 0
17    51, 31    SWAP
18    21, 55, 0    STO* 0
19    22, 0    RCL 0
20    61, 26    RTN
21    61, 41, D    LBL D
22    21, 0     STO 0
23    51, 31    SWAP
24    21, 45, 0    STO÷ 0
25    22, 0    RCL 0
26    15    1/X
27    21, 0    STO 0
28    61, 26    RTN
29    61, 41, E    LBL E
30    21, 0    STO 0
31    51, 31    SWAP
32    14    y^x
33    22, 0    RCL 0
34    74    =
35    21, 0    STO 0
36    21, 26    RTN
37    61, 41, F    LBL F
38    71    Clear
39    71    Clear
40    61, 26    RTN

Example:

In the following examples, 8 will be stored in the hidden register.

7 + 8: 7, INPUT, 8, XEQ A. Result: 15
7 – 8: 7, INPUT, 8, XEQ B. Result: -1
7 * 8: 7, INPUT, 8, XEQ C. Result: 56
7/8: 7, INPUT, 8, XEQ D. Result: 0.375
7^8: 7, INPUT, 8, XEQ E. Result: 5,764,801
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)