• | Friday, 2021-07-23T13:27:07-05:00
• Home

# rpn

```		     A Brief Introduction to RPN

This document very briefly describes the traditional, 4-level stack
based RPN entry system.  It does not describe RPL as used by the -28*
and 48* calculators.

ENTRY

To evaluate an expression using RPN, just enter it as you would do it.
To add 1, 2, and 3, do:

1 Enter 2 + 3 +

To evaluate:

(1 * 4) + (5 / 7)

do:

1 Enter 4 * 5 Enter 7 / +

Note that you only press Enter to separate two numbers.

DATA ORGANIZATION

Dats is organized into a 4-level "stack," which is typically drawn as:

T: t
Z: z
Y: y
X: x

Where the UPPERcase letters refer to the names of the registers and
the lowercase letters refer to the contents.  In addition, there are:

- an unnamed data entry register
- a "last x" register:

L:l

- numbered storage registers
- a "stack lift enabled" bit

SIMPLE OPERATIONS

Before:

L: l

T: t
Z: z
Y: y
X: x

You type in a number (10) and press the Enter key.  One of two results:

Stack lift enabled:

L: l

T: z
Z: y
Y: x
X: 10

Stack lift disabled (not enabled):

L: l

T: t
Z: z
Y: y
X: 10

Let's assume that stack lift is always enabled for now.  Let's type in
three more numbers (20, 30, 40):

L: l

T: y
Z: x
Y: 10
X: 20

L: l

T: x
Z: 10
Y: 20
X: 30

L: l

T: 10
Z: 20
Y: 30
X: 40

Now, press a simple one-operand function (say, x^2):

L: 40

T: 10
Z: 20
Y: 30
X: 1600

Note that the previous value of X was copied to L (not surprizing,
given its name).  X now contains the result of the operation.  Again,
not surprizing.  All one-operand functions work this way.

Now press a simple two-operand function (say, +):

L: 1600

T: 10
Z: 10
Y: 20
X: 1630

The result is the sum of the two numbers in X and Y.  Again, the old X
is copied to L.  The rest of stack is dropped one level, with the
value in T being duplicated.  Note that the operand order is Y op X.

Percent is a special case.  It doesn't drop the stack.  Thus, you can do:

10 Enter 20 % -

to subtract 20% of 10 from 10.

There are two other often-used operations: swap and roll down.  They
do the obvious (see later table).

Clearing (CLx) zeros the X register and clears stack lift enable
(disables stack lift).  This means that you can type in the
(presumably) correct new value.

STACK LIFT

Most functions leave stack lift enabled (% and \GS+,\GS- are
exceptions).  However, clearing and entering don't.

For the most part, you don't need to pay attention to this detail.  If
you just type your operations in the way that you expect, they just
work.

OH, YES

More recent RPN calculators -- in particular, those designed around
screens larger than one number -- separate the data entry memory from
the X register.  For the most part, operation is identical to older
machines.  However, you can get into trouble if you press Enter extra
times.

Examples of such new machines are the 17BII, 19BII, calculator modes
in the 95LX*, 100LX*, and 200LX*, and other programs such as the Loki
calculator.

GENERAL FORMS

stack lift
10 Enter:		enabled		disabled

L: l		L: l		L: l

T: t		T: z		T: t
Z: z		Z: y		Z: z
Y: y		Y: x		Y: y
X: x		X: 10		X: 10	stack lift disabled

One-operand:

L: l		L: x

T: t		T: t
Z: z		Z: z
Y: y		Y: y
X: x		X: f(x)

Two-operand:

L: l		L: x

T: t		T: t
Z: z		Z: t
Y: y		Y: z
X: x		X: f(x,y)

%:

L: l		L: x

T: t		T: t
Z: z		Z: z
Y: y		Y: y
X: x		X: x * y / 100

Swap (x<>y):

L: l		L: l

T: t		T: t
Z: z		Z: z
Y: y		Y: x
X: x		X: y

Roll Down (RDN, Rv):

L: l		L: l

T: t		T: z
Z: z		Z: y
Y: y		Y: x
X: x		X: t

Clear X:

L: l		L: l

T: t		T: t
Z: z		Z: z
Y: y		Y: y
X: x		X: 0	stack lift disabled

```