









                              RPNDEMO PROGRAM


                             -- User's Manual --




                                     by
                                John Kennedy
                           Mathematics Department
                            Santa Monica College
                              1900 Pico Blvd.
                          Santa Monica, CA  90405










                             ABOUT THIS MANUAL



This manual is a User's Manual for the RPNDEMO program.  It is divided into
six sections.  The first part is the INTRODUCTION which simply gives a
general description of the program's capabilities.

The program has two main modes of operation called a Manual Mode and a
Program Mode.  The second part describes the Manual Mode.  The third part
describes the Program Mode.

The fourth part simply lists the syntax and describes all the instructions of
the RPN language.

The fifth part is for experienced HP calculator users.  If you are already
familiar with any HP calculator this part describes the similarity between
RPNDEMO and other HP RPN calculators.

The sixth part contains a listing of sample programs to be used by beginners
learning the RPN language.

The pages in this manual are not of uniform length and the logical numbering
of the pages is only intended to help you quickly locate a desired topic from
either the table of contents or the index.  This format offers a little more
efficient use of paper when a hard-copy of the manual is printed.

It is expected that you will read this manual and run the program in tandem.






"Computers are incredibly fast, accurate, and stupid.  Man is incredibly
slow, inaccurate, and brilliant.  The marriage of the two is a power beyond
calculation."    - Source Unknown -


                                                                        page 1


                                 RPNDEMO PROGRAM

                               -- User's Manual --


                                Table of Contents


About This Manual.............................................1

Table Of Contents.............................................2

INTRODUCTION................................................3-5
   General Operation Observations...........................6-7

Manual Mode................................................8-26
   The Display Screen.........................................8
   Keyboard Commands..........................................9
   Stack Operations...........................................9
   Display Formatting........................................10
   Entering Numbers..........................................11
   Storing & Recalling With The Memory Bank..................12
   The ENTER^ Function.......................................13
   Some RPN Philosophy.......................................14
   One-Number Operations.....................................16
   Error Messages............................................17
   Two-Number Operations.....................................18
   Chain Arithmetic..........................................19
   Keyboard Commands.........................................22
   Other Modes...............................................23
   Manual Mode Summary.......................................24

Program Mode..............................................27-33
   Help......................................................27
   Clearing A Program........................................27
   Loading A Program From A Disk.............................28
   Saving A Program On A Disk................................29
   Running A Program.........................................30
   Changing Fast/Animation Modes.............................30
   Setting the Delay Time....................................30
   Quitting The Program Mode.................................30
   The Program Mode Editor................................31-33

The RPN Language Syntax...................................34-66

For Experienced HP Calculator User's......................67-68

Some Sample Programs......................................69-72
   A First Demonstration (RDEMO1)............................69
   Prime Number Generator (RDEMO2)...........................70
   Selection Without Replacement (RDEMO3)....................71
   Polynomial Evaluation (Synthetic Substitution)(RDEMO4)....72

Function Index...............................................73

INDEX.....................................................74-75


                                                                        page 2


                                   INTRODUCTION


The RPNDEMO Program, What Is It ?

The purpose of the RPNDEMO program is to provide a graphic display of the
inner workings of a numerical computer that operates using the Reverse Polish
Logic system.*   The program should be a practical tool for teaching beginners
how to use an RPN calculator/computer.  This program also provides a
simulation of a programmable machine and this programmable capability serves
two major purposes.

First, it can teach beginning programming concepts that are used in assembly
or machine language.  These concepts are on a slightly higher than normal
level but include many of the standard machine operations of a computer system
designed using a microprocessor for a CPU.  There is both internal and
external memory.  There are instructions for setting, clearing, and testing
flags, conditional and branch instructions that use direct and indirect
addressing, subroutines, internal and external memory swapping and internal
and external arithmetic operations, as well as a host of high-level real
number arithmetic operations.

The implementation of all of these functions is on a sufficiently high level
that the beginning user should not get bogged down in minute technical details
as is usually the case when one studies their first real microprocessor
instruction set.  At the same time the overall operation and instruction set
is primitive enough so that the real flavor of assembly language programming
can at least be imitated.

The second major purpose is to teach beginners how a programmable RPN
calculator works.  The instruction set of the RPN language implemented here
closely resembles that used in Hewlett-Packard's more powerful programmable
calculators.





*  What is now called "Polish Logic" is a notation for writing expressions in
symbolic logic without using parentheses for grouping symbols.  This system of
notation was developed by Jan Lukasiewicz at the University of Warsaw in 1928,
a date preceding the invention of the modern computer.  Mathematical
expressions can also be written using the same notation, but the ordering is
usually reversed resulting in Reverse Polish Notation (RPN).  It's chief
advantage is in how we think of evaluating complex mathematical expressions on
computers using a stack architecture.  See the file BKGRND.TXT for history
on the Polish notation.

                                                                        page 3


What Software Is Required To Use RPNDEMO ?

The RPNDEMO program is completely self-contained and requires no other
software or systems programs.


What Hardware Is Required To Use It ?

The program is designed to be used with a color graphics card and RGB monitor
but the program can be used with a monochrome adapter/monitor combination.
Although the program does perform some simple animation, the program does not
use any graphics modes, only an 80x25 text mode.  Thus the program is
compatible with both a monochrome adapter card and monochrome monitor.  The
program takes advantage of color if the color card is available.


What Mathematical Background Or Computer Experience Is Required To Use The
Program ?

The program can be used by anyone with a minimal background.  In Manual Mode
the program is a full function scientific calculator.  In this mode it does
not require any computer experience and the mathematical background needed
depends on the kinds of calculations you intend to perform.  Of course the
more background you have the more you will be able to take advantage of the
program's advanced capabilities.

If you intend to write programs using the RPN language then some prior
programming experience with just about any other language would be most
helpful.  Since RPNDEMO is intended to be an educational program to aid those
interested in learning how to program it is perhaps unfair to expect users to
have any prior programming experience.  However, if you have absolutely no
other programming experience then you should first concentrate on learning
most of the Manual Mode instructions before attempting to write your first
program.

The instruction set of the RPN language closely resembles that of the HP-41
calculator.  If you are an experienced HP calculator user then you should be
right at home with RPNDEMO.  In particular, if you are an experienced HP-41
User then you should be able to start programming immediately after learning
how to use the built-in editor.  RPNDEMO is NOT intended to be an HP-41
simulator, but where possible the instruction set matches that of the HP-41
exactly.  With few exceptions RPNDEMO includes most of the programming
capabilities of the HP-41.


                                                                        page 4

What Are The Major Features Of The Program ?


Although RPNDEMO is primarily a demonstration program it uses a very powerful
and complete language capable of performing complex mathematical calculations.
RPNDEMO has two modes of operation.  You can execute instructions directly
from the keyboard in what is called the Manual Mode.  You can also go into a
Program Mode in which you can load, edit and run entire programs.

RPNDEMO provides 100 memory registers and programs can be up to 999 lines in
length.  This memory capacity should be more than adequate for the
demonstration nature of this program.

The built-in program editor performs complete syntax checking of all
instructions.  The RPN language is interpreted and includes full run-time
error checking.  The demonstration nature of RPNDEMO essentially has the
advantages of a single-step mode of operation since it shows how each
instruction is performed at the time it is executed.

RPNDEMO also includes a Help command which displays several screens that
summarize the use of the program editor as well as give a complete summary of
the language syntax with examples.

As part of the Program Mode RPNDEMO contains a complete programming
environment that includes a program editor that can be used to enter, edit,
and save programs on disk, or load programs from disk.  The RPNDEMO screen
editor provides the most convenient means of creating the source code for
programs, but you can also create programs using any word processor that forms
simple lines of ASCII text.

The RPNDEMO language does NOT use line numbers.  However, the built-in screen
editor shows line numbers to indicate the relative position in a program.  The
editor also automatically numbers and re-numbers program lines as lines are
inserted and/or deleted.  The built-in editor performs like a full screen
editor.


                                                                        page 5



                      GENERAL OPERATION OBSERVATIONS



In this manual we will enclose single keystrokes that you would type on the
computer keyboard in square brackets.  So if we asked you to type the first
three letters of the alphabet we would say type [A] [B] [C].  If we ask you to
press the control key, the backspace key, the return key, the alternate key,
or the space bar we will show [CTRL], [BACKSPACE], [ENTER], [ALT], [SPACE].
Each enclosure in square brackets thus refers to exactly one keystroke.  This
convention should make clear exactly how many and which keys you press.

When it is necessary to press two keys simultaneously we will write a
connecting plus symbol between the keys.  For example, [ALT]+[P] means press
the alternate key and key P simultaneously.  As other examples, [shift]+[,]
will yield the "<" character and [shift]+[.] will yield the ">" character.

Some characters can be entered in two different ways using different keys.
For example, the plus and minus symbols, "+" and "-" can be made by pressing
the tan keys [+] and [-] on the far right side of the keyboard.  But they can
also be made by pressing keys in the top row just to the right of the number
0.  The plus symbol can be made by [shift]+[=] and the up-arrow symbol, "^",
is made by [shift]+[6] where the [6] and [=] keys are in the top row.

There are also times when we will show in double quotes parts of what you
should see on the display screen.

There are many times when the program will ask you to press the [ENTER] key.
The [ENTER] key is the tan "bent arrow" key that is just to the left of the
keys [7 Home] and [4] on the numeric keypad.  If you are new to the IBM PC
keyboard then you may at first be confused by the several arrow keys that are
on the keyboard.

The [ENTER] key is the large tan key that has a bent left-pointing arrow
which looks as shown below.  This is not to be confused with another tan key
with a straight left-pointing arrow that is the [BACKSPACE] key.  Note the
difference in the tails of the arrows.


                     [ENTER]                [BACKSPACE]
                 +--------------+         +--------------+
                 |              |         |              |
                 |              |         |              |
                 |   /______    |         |   /_______   |
                 |   \          |         |   \          |
                 |              |         |              |
                 |              |         |              |
                 +--------------+         +--------------+


                                                                        page 6


The [BACKSPACE] key is in the top row towards the right and lies just to the
left of the tan key labeled as [NUM LOCK].  The [ENTER] key is the longer key
that lies below the [BACKSPACE] key and just above the tan key labeled
[PrtSc *].

Only manual commands or actual program lines need to be completed by pressing
the [ENTER] key.  You can correct keystroke errors with the [BACKSPACE] key
as long you back up and make the correction before you press the [ENTER] key.
Use the [BACKSPACE] key to back over and erase keystroke errors and then
re-type the correct information.  When the line is correct then press
[ENTER].  You should think of pressing the [ENTER] key as returning control
of the program back to the computer.  Until then, you are in control.

To key in numbers you can use the numeric keypad or you can use the numbers on
the top row of keys.  Some people are more comfortable with the top row of
keys because that is the familiar key layout on a typewriter.  If you are
entering numbers with many digits you may find using the numeric keypad on the
right side of the keyboard to be much faster than using the top row of keys.



                                                                        page 7


                                 MANUAL MODE


The RPNDEMO program should show as the file  RPNDEMO.EXE when you perform a
disk directory.  To run the program simply type

                     [R] [P] [N] [D] [E] [M] [O] [ENTER]

and you should see the program start in its Manual Mode.

The Manual Mode is so described because in this mode you can give and execute
commands one at a time from the keyboard.  You will see the immediate effect
of each operation as it is carried out.

The first screen you see shows the basic internal elements of a simple
calculator.  We assume you have used a calculator before, although our
representation of a calculator probably appears unfamiliar.  We will first
describe all the elements shown in the screen display and then we will give
examples and discuss all the keyboard commands.


                              THE DISPLAY SCREEN


The left side of the screen shows five letters of the alphabet  T,Z,Y,X, and
L  in that order from top to bottom.  Each of these letters indicates the
position of a register.  A register is just a memory location in a computer
that is capable of holding one complete number.  The five registers labeled T,
Z,Y,X, and L collectively form what is called the operational stack of our
computer.  When RPNDEMO is first run all five stack positions are initialized
with the number 0.

The position labeled as X is really the key register of all the stack
registers.  If this were a normal shirt-pocket calculator the X-register would
correspond to the display.  The number in the X-register would be the number
shown in the calculator display.  When you key in a new number from the
keyboard, that number goes into the X-register.

The middle portion of the display shows 10 more registers labeled R00 through
R09.  These are part of the storage memory of our computer which has 100 such
memories.  The computer display screen is not large enough to show all 100
memories at a time, but all 100 memories are always available and always have
something in them.  All 100 memories also contain the number 0 when the
program is first started.



                                                                        page 8

Whenever you reference a storage memory by either storing something in it or
recalling something from it the screen will automatically perform what is
called bank switching and will show the group or bank of 10 registers which
includes the particular memory register you used.  So you can expect the
numbering to change to anything in the range from R00 to R99.  The T,Z,Y,X,
and L registers always keep their same labels and relative positions although
the numbers shown in the corresponding positions move around on the screen.

The far right side of the screen is used to display some of our calculator's
functions and the corresponding keys on the keyboard which will execute those
functions in Manual Mode. The purpose of this portion of the User's Manual is
to explain how all of these functions work, but especially the stack
operations.

The bottom portions of the screen below all the registers are used to display
various messages and show the status of various states of our computer as it
is carrying out its operations.


                              KEYBOARD COMMANDS


Let's begin by entering the number PI and storing this number in the register
R25.  Press key [P] on the keyboard and then look at the X-register position
and you should see it filled with the digits of the number 3.1415926536.
Next press key [S] and note the cursor jumps to a position under the label
Current Command.  You should see  "Store --"  with the cursor blinking in the
position of the first dash.  Next press [2] and then [5] and watch the display
change as the number PI moves from the X-register into the position occupied
by memory R25.  The current bank of registers will show R20-R29 and you should
see a copy of PI in R25.  The number for PI also remains in the X-register
position.

Congratulations!  You have just completed your first computer operation.
Essentially all that is left is to understand how to store and recall numbers
using various registers and how to perform operations on those numbers.


                               STACK OPERATIONS


Next we will perform some stack register manipulations.  Press key [X] on the
keyboard and watch the screen exchange the numbers in the X and Y positions.
This RPN language command is called "X exchange Y" and the command is written
as  X<>Y  in the syntax of the language.  Press [X] again and you should see
the numbers in the X and Y registers restored to their original positions.


                                                                        page 9


Next we will perform some stack rotations.  The numbers in the 4 stack
registers X,Y,Z, and T can be cyclically rotated.  These rotations are called
"roll up" and "roll down" and they can be performed in Manual Mode by simply
pressing keys [U] (up) and [D] (down) on the keyboard.  Press these keys
several times and watch the screen until you understand their effect.  The
names roll up and roll down describe these operations since the majority of
the stack registers shift their contents up or down.  The RPN language syntax
for roll up is  R^  and that for roll down is RDN.  The stack register L does
not participate in these stack rotation operations.

Another function that can be performed in Manual Mode is called "clear X" and
this is the same as a clear function on a calculator.  The language command
syntax is  CLX  but if you just press key [C] on the keyboard you will see the
number in the X-register cleared to all 0's which is eventually displayed as
0.  Beginners should note that it is usually not necessary to clear the
X-register before beginning a new calculation.  The reason will be explained
later.

You should also notice a status change on the left side of the screen.  The
words  "Overwrite X"  will remain on the screen.  The meaning of this status
indicator is that if you next key in the digits of a number from the keyboard
then those digits will overwrite the digits of any number that is in the
X-register.  We will explain this idea more completely when we discuss the
philosophy of RPN.  For now you should just try to understand the effect of
each operation.  Understanding when to use them and why they do what they do
will be explained later.


                              DISPLAY FORMATTING


Now is probably the proper time to discuss number formats.  The RPNDEMO
program calculates and manipulates numbers with up to 11 significant digits.
Numbers can be entered in scientific notation but numbers are normally
displayed in ordinary decimal notation unless they are too small or too large
to be displayed in that manner.  Then they will be displayed in scientific
notation.  The dynamic range is from 3.4E-4932 to 1.1E+4932 where the letter
E denotes an exponent or a power of 10.

Trailing zeros, significant or not, will not be shown.  For example, the
number 721.34000 will always be displayed as 721.34 and the number
0.00000000023465000 will be shown as 2.3465E-10.  RPNDEMO automatically
switches to and from scientific notation as necessary.  Unfortunately, you
have no control of this display formatting.  You will always see all
significant nonzero digits since RPNDEMO never hides anything from you.


                                                                       page 10


                               ENTERING NUMBERS


You can key in a number from the keyboard anytime the status message "Please
Wait" is not showing.  You can use the numbered keys in the top row of keys
or you can use the numbers in the numeric keypad on the right side of the
keyboard.  When keying in a new number the digits of the new number will
either overwrite the X-register number or your new number may force the stack
to lift before the X-register will start accepting the digits you type from
the keyboard. If the stack lifts you will see the message "Please Wait" and
you will see the T,Z,Y, and X numbers move vertically up in the stack one at
a time.

WARNING:  WHEN THE STACK LIFTS AS YOU START KEYING IN A NEW NUMBER BE PATIENT
AND OBEY THE "Please Wait" MESSAGE.  AFTER THE STACK HAS LIFTED YOU CAN
RAPIDLY ENTER THE 2ND AND SUCCEEDING DIGITS OF YOUR NUMBER.

When entering the digits of a number you may make a mistake and so you need to
know about the [BACKSPACE] key.  The [BACKSPACE] key can be used to correct
keystroke errors.  The [BACKSPACE] key is located in the top row on the right
side of the keyboard and just to the left of the key labeled as [NUM LOCK].
The [BACKSPACE] key is the tan key with a straight left-pointing arrow.  Use
this key to back over and erase keystroke errors.

To enter a negative number you key in the digits as a positive number and then
press key [N] which represents the RPN language command "Change Sign" and the
language syntax is CHS.  Since we are already using key [C] for the CLX
function, key [N] has been assigned the roll of performing a sign change or
negation or negative operation.  Try keying in -10 by pressing [1] [0] [N].

To enter a number in scientific notation, key in the mantissa digits and then
press key [E] to begin entering the digits of the exponent.  Immediately after
you press [E] for the exponent you will see "E+" indicating a partial positive
exponent.  To make the exponent negative press key [N] AFTER you press key
[E].  The [N] key will now change the sign of the exponent from "E+" to "E-"
or from "E-" to "E+".

WARNING:  YOU SHOULD ONLY KEY IN EXPONENTS IN THE RANGE FROM E-4932 TO E+4932.
IF YOU KEY IN A LARGER OR SMALLER EXPONENT RPNDEMO WILL DETECT AN INVALID
NUMBER AND IT WILL AUTOMATICALLY CHANGE YOUR ENTRY TO ZERO.  BE CAREFUL ABOUT
EXCEEDING THE DYNAMIC RANGE WHEN ENTERING NUMBERS IN A SCIENTIFIC FORMAT.


                                                                       page 11


To key in a negative number with a negative exponent, enter the beginning
digits, then press [N] to make the mantissa negative, then press [E] for the
exponent and then press [N] a second time to make the exponent negative.
First press key [C] to clear the X-register and then try entering the number
-3.141E-23.

        Press  [3]  [.]  [1]  [4]  [1]  [N]  [E]  [N]  [2]  [3]

After a little experimentation you should be able to enter any number in
scientific format.  Note that if you don't key in any starting digits but
start by pressing the enter exponent key [E] then the program will show
"1.0E+", just as if you keyed [1]  [.]  [0]  [E]

Also note that since PI=3.1415926536 is a frequently used number we can simply
enter PI by pressing key [P] on the keyboard.  This is just a convenience
feature because we could also key in all 11 digits manually.  But of course
pressing [P] is faster and less prone to error.


                   STORING AND RECALLING WITH THE MEMORY BANK


You should now be able to key in any number from the keyboard and have that
number appear in the X-register.  The next operations to be learned are
storing and recalling numbers using the computer's memory bank of 100
registers.  The computer's memory bank of 100 registers are named R00 through
R99.  We need to distinguish between the number which names a register and the
number which may be contained in a register.

From the keyboard you can press key [S] to store or key [R] to recall.  In
each case you will be prompted by two dashes representing a register number
in the range 00-99 to be keyed in.  When the second dash is filled with a
number the operation is automatically performed.   When either storing or
recalling the transfer always involves the X-register.  For example, press [S]
and then [5] and [0] and a copy of the current number in the X-register should
be deposited in register R50.

One of two options will automatically be executed when you perform a recall.
If you see the status message "Overwrite X" at the time you perform a recall
then the number moved into the X-register position will simply overwrite the
digits of the number in the X-register.  To see this action, press key [C] to
clear the X-register and then press [R] and when prompted by the message
"Recall --"  key any two-digit number.

The message "Overwrite X" will be turned off after performing a recall
operation.  To see the second kind of recall action press [R] again and key
in any two-digit number.  This time you should see the stack registers lift
upward just before the recalled number moves into the X-register position.
This is the same lifting action of X,Y,Z, and T that occurs when you enter a
new number from the keyboard.


                                                                       page 12


So whatever new number is moved into the X-register, that number will
overwrite the existing number if the "Overwrite X" message is on and otherwise
the stack will be lifted up if the "Overwrite X" message is off.  You can
deposit a new number in the X-register essentially only by keying in a number
from the keyboard or by recalling a number from some other register.  There
are also several different kinds or variations of the basic store and recall
operations that you will learn about in the section on programming.


                            THE ENTER^ FUNCTION


Next we explain the effect of the ENTER^ operation.  Either the space bar,
[SPACE], or the [ENTER] key can be used as a single-key keyboard operation
that in the RPN language is called ENTER^.  When you perform this operation
the following  actions take place.


   1. The number in the T-register is lifted upward and is lost off the
      top of the stack.

   2. The number in the Z-register is lifted upward into the T-register
      position.

   3. The number in the Y-register is lifted upward into the Z-register
      position.

   4. The number in the X-register is copied into the Y-register position.

   5. A copy of the original X-register remains in the X-register and the
      "Overwrite X" status indicator is turned on.


The ENTER^ operation tends to be over-used by beginners learning the RPN
system.  Although it has some programming applications not related to its
original purpose, we state very simply at the outset that ENTER^ is designed
to separate the digits of two numbers that would normally be keyed in from the
keyboard, one right after the other without any intervening operations.

We also point out that in actual practice the ENTER^ key is rarely used.  When
evaluating the most complex kinds of mathematical formulas or expressions it
often happens that the ENTER^ key is never used.


                                                                       page 13


As an example of when to use the ENTER^ key let's attempt the simple problem
of adding 3 and 4.  We begin by keying in the number 3.  Press [3].  Now if we
were to key in the number 4 immediately afterwards the X-register would
contain the number 34.  Press [4] to see this.  We want to key the two numbers
3 and 4 separately into the stack, not the single number 34.  However, we can
only key one number into the X-register at a time.

To avoid this possible confusion of digits let's start the problem all over
again.  First press key [C] to clear the X-register of its current number.
Then press key [3] to put the number 3 in the X-register.  This time press
ENTER^ ([SPACE] or [ENTER]) and you will see the stack lift as a copy of 3 is
pushed up into the Y-register.  Note also that the "Overwrite X" indicator is
turned on.  Next press [4] and the number 4 will overwrite the number 3 in X.

Now that we have the numbers 3 and 4 in the stack we can add them.  Press the
[+] key and the stack will re-arrange itself but eventually the answer 7 will
be deposited in the X-register.

We will need to explain all of the stack movements which take place when you
perform a two-number operation like addition.  In fact let's discuss the basic
four operations add, subtract, multiply, and divide and the philosophy of RPN.


                            SOME RPN PHILOSOPHY


It may sound somewhat biased but RPN provides the simplest, most efficient,
and most consistent method for performing mathematical computations.  For
beginners it is a new and versatile approach to problem solving.  This system
offers the following advantages over the traditional algebraic calculator
logic.


   1) Pressing an operation key immediately executes that operation.

   2) You never work with more than one or two numbers at a time.

   3) You don't have to re-structure and think the problem through ahead
      of time.  All problems are worked in the same consistent manner.

   4) Intermediate results are displayed as they are calculated.

   5) Intermediate results are automatically inserted into the problem
      on a last-in first-out basis.  Special movements automatically
      store, position, and recall intermediate results as they are needed.

   6) Since no parentheses are used, fewer keystrokes or operations are
      required than if using an algebraic logic system.


                                                                       page 14

To fundamentally understand RPN, contrast the first item in the above list
with traditional algebraic calculator logic.  The problem is to calculate
2*3+4.  On an algebraic calculator you would press the keys

                        [2]  [*]  [3]  [+]  [4]  [=]

Now think of what happens inside the calculator when you press the keys.
First note that when you press [*] the calculator does NOT multiply.  At the
time you press [*] you haven't keyed in the number 3 yet, so the calculator
cannot possibly multiply.  Now think of what an algebraic calculator does when
you press the [+] key.  It certainly doesn't add, in fact, it multiplies!
How confusing!

An RPN logic calculator operates by the simple rule that when you press an
operation key that operation is immediately executed.  There are no exceptions
to this rule.  If you are performing a two-number operation then RPN requires
that both numbers be positioned in the stack before you execute the operation.

The RPN language provides six two-number operations.  When performing any of
these the X and Y registers contain the two initial inputs and the final
output is also left on the stack.  Since addition and multiplication are
commutative the order in which the numbers are positioned in X and Y is
usually not important.  For division and subtraction however you must have the
correct order.  RPN performs subtraction and division in the order  Y-X  and
Y/X.

The simplest way to remember the order for subtraction and division is to
think of the order you would write on paper.  To subtract 10 from 50 or to
divide 50 by 10 the order written on paper would be:


                                  50      50
                                - 10     ----
                              --------    10


The stack order is of course Y on top and X underneath.  Now you can
understand why we have the  X<>Y  function.  If the two numbers in X and Y
are out of order then performing  X<>Y  to exchange X and Y will reverse the
order and give the numbers the correct orientation.


                                                                       page 15


                           ONE-NUMBER OPERATIONS


Before discussing the complete action of the stack registers when a two-number
operation is performed we will first discuss the one-number operations which
are simpler.  The distinction between what are called one-number operations
and two-number operations is the number of numbers that are required as input
to the operation.  The basic four operations add, subtract, multiply, and
divide are all examples of two-number operations.  On the other hand, examples
of one-number operations are square root, cosine, logarithm, and reciprocal.

Listed below are RPNDEMO's mathematical one-number functions and the keys used
to execute those functions in Manual Mode.  The RPN language syntax is shown
in the middle column.


                 RPN
                Manual      Language
              Mode Keys      Syntax     Description
              ---------     --------    -----------

                   [F4]       1/X       Reciprocal
           [shift]+[F3]       10^X      Power of 10
                   [F8]       ABS       Absolute Value
           [shift]+[F7]       ACOS      Cosine Inverse (ArcCosine)
           [shift]+[F5]       ASIN      Sine Inverse (ArcSine)
           [shift]+[F9]       ATAN      Tangent Inverse (ArcTangent)
                   [N]        CHS       Change Sign (Negation)
                   [F7]       COS       Cosine
           [shift]+[F1]       E^X       Power of e=2.7182818285
                   [F1]       LN        Natural Logarithm (Base e)
                   [F3]       LOG       Common Logarithm (Base 10)
                   [F5]       SIN       Sine
                   [F2]       SQRT      Square Root
                   [F9]       TAN       Tangent
                   [F10]      X^2       Square


Note that in all cases the shifted function key performs the inverse of the
function associated with the unshifted key.

Except for the CHS operation all of these one-number mathematical functions
can be executed by using the function keys on the left side of the keyboard.
Note that the upper-right side of the display screen shows the correspondence
between the function keys and their related operations.

All one-number functions operate using the X-register to receive their
argument and deposit their result.  Except for the negation operation,
whenever a one-number operation is executed the X-register is first saved in
the L-register.  Then the function value is calculated and replaces the value
in the X-register.


                                                                       page 16


As an example, let's calculate the square root of 50.  Key  [5]  [0]  [F2]

When you finish the L-register contains 50 and the X-register contains the
square root answer 7.0710678119.

The L designator for the L-register is for LASTX which is another stack
function.  Many times we perform multiple operations using a single number and
the purpose of the L-register is to always save a copy of the last number we
worked with.  The LASTX function simply recalls the number from L and stores
it up in X.  Key [L] executes this LASTX function.

As a simple example of the convenience of having the L-register, suppose you
needed to add the reciprocal of 17.2361458 to the square root of the same
number, 17.2361458.  Begin by keying in the number

              [1]  [7]  [.]  [2]  [3]  [6]  [1]  [4]  [5]  [8]

Then press  [F4]  to obtain the reciprocal.

Now instead of keying in the number 17.2361458 again, simply press [L] to
recall the L-register up to the X-register.

Note that the reciprocal result is lifted up in the stack when the original
number is recalled from L to X.  Now press  [F2]  to calculate the square root
of 17.2361458.  At this point you should have the reciprocal in the Y-register
and the square root in the X-register.  Just press  [+]  to add the two
partial results to get the final answer  4.2096613576  in X.

Especially in programming, but also in Manual Mode, you will find the LASTX
function provides simple and sometimes clever efficiency.  But of course you
have to be aware of the contents of the L-register to take advantage of it.
If beginners tend to over-use the ENTER^ function they also tend to under-use
the LASTX function.


                               ERROR MESSAGES


Whether executing a one- or two-number mathematical function, if you should
attempt an illegal operation then RPNDEMO will immediately halt and show you
a corresponding error message in the space under Current Command.  The error
message should explain why the error occurred.  The operation that caused the
error will be shown under the Last Command designator.


                                                                       page 17


Examples of illegal operations are square roots of negative numbers,
logarithms of either zero or negative numbers, division by zero, reciprocal of
0, arccosine or arcsine of numbers whose absolute value is larger than 1, and
nonintegral powers of negative numbers.  If you haven't generated an error
message yet then you might try calculating the reciprocal of 0 by pressing [C]
and then [F4].

You should now be able to execute any one-number function.  Only the contents
of X and L change.  The desired answer is left in X and the previous X is left
in L.  You may wish to practice executing various functions using the function
keys on the left side of the keyboard.

Another keyboard function related to the one-number trigonometric functions is
the selection of the angle mode.  You will note that the bottom middle part of
the screen shows the current angle mode.  RPNDEMO only uses two angle modes,
Degrees and Radians.  When RPNDEMO is first started it is in Degrees mode.

To change the angle mode you need only press key [A].  Whatever the active
mode at the time you press [A], after pressing [A] the angle mode changes to
the other mode.  This type of action is called a switch toggle.  So changing
angle modes is simple and automatic.

You should also know that in the RPN language you select the angle mode with
either  DEG  or  RAD  which are the Program Mode functions for changing the
angle mode.  If you use any of the six trigonometric functions, sine, cosine,
tangent, or their inverses, remember to set the desired angle mode.


                            TWO-NUMBER OPERATIONS


Now back to two-number operations.  In addition to + - * /  RPNDEMO has a
power function Y^X.  For example, 3^2=9 and 2^3=8.  So the X and Y stack order
is important for Y^X just like it is with subtraction and division.  The
notation of the function Y^X suggests that Y is the base and X is the
exponent.

After properly positioning the base and exponent in Y and X you can execute
Y^X any time by pressing [F6].  Normally the base Y should be positive,
however, Y may be negative provided X is an integer.  X can be positive,
negative, or zero.

The stack changes which take place when you execute one of + - * /, or Y^X
are:

   1) Both numbers in the Y and X registers are removed from the stack.

   2) The number that was in the X-register drops down and is saved in
      the L-register.

   3) The answer to the operation using X and Y is calculated and is put
      back on the stack in the X-register.

   4) The Z-register number drops down and is stored in the Y-register.

   5) The T-register number stays in the T-register but a copy of the
      T-register drops down and is stored in the Z-register.

   6) If the "Overwrite X" message was visible at the start of the
      two-number operation it will be turned off at the conclusion.


                                                                       page 18

To become proficient using RPN you must be able to

      1) Enter numbers into the stack.

      2) Perform one- and two-number operations on numbers that are on
         the stack.

      3) Manipulate the stack contents.


                              CHAIN ARITHMETIC


Although the basics for entering numbers, performing operations, and
manipulating the stack contents have been covered there is still more to be
understood regarding chain arithmetic and automatic stack movements.

One reason previously given for using the ENTER^ function was to tell the
computer that we were through entering the digits of one number and that the
next digits keyed in would be the digits of another number.  However, many
times the computer doesn't need to be told that the next digits are for a new
number.

For example, it knows that after completing an operation any new digits keyed
in must be part of a new number.  Hence after any one- or two-number operation
or stack manipulation the "Overwrite X" message is turned off and the stack
automatically lifts when a new number is keyed in.  It is not necessary to
press ENTER^ or to clear anything when beginning a new operation.

The concept of number building keys and number terminating functions may help
clarify this.  All the keyboard keys fall into one of two classes; number
building keys and number terminating keys.


                                                                       page 19


The number building keys are the digits [0]-[9], the decimal point [.], [N]
(Change Sign CHS) and [E] (enter exponent).  All other keys are number
terminating keys since after they are pressed the computer knows any new
digits keyed in must be part of a new number.

If a number is terminated by pressing a number terminating key then the
"Overwrite X" message is turned off and the stack lifts upon entry of new
digits.  The only two number terminating functions which are exceptions to
this rule are ENTER^ and CLX.  Both of these functions turn on the
"Overwrite X" message and make stack lift unnecessary if the following
operation puts a new number in X.

Because of the automatic lifting action of the stack it is usually unnecessary
to clear the contents of the stack registers before beginning a new
calculation.  This fact may seem unintuitive to beginners.

The stack not only lifts automatically when a new number is keyed in, it also
drops after a two-number operation involving the X and Y registers.  This fact
was stated in telling how the stack changes when a two-number operation is
performed.  We will now work an example in two different ways to illustrate
the automatic stack lift and stack drop.  It is these automatic movements that
give RPN its tremendous computing power.

Suppose we wish to add the four numbers 37,12,25, and 19.  One solution is to
add 37 and 12.  Then add 25 to that first result and then finally add 19.  A
second solution would be to enter all 4 numbers in the stack first and then
take advantage of the automatic stack drop by performing 3 consecutive
additions.  Contrast the following two solutions.

One solution is:

           Key [3] [9] [ENTER] [1] [2] [+]
           See 49 in X as a partial result.
           Key [2] [5] [+]
           See 74 in X as the next partial result.
           Key [1] [9] [+]
           See 93 in X as the final answer.

A second solution is:

           Key [3] [7] [ENTER] [1] [2] [ENTER] [2] [5] [ENTER] [1] [9]
           The stack should now contain the four numbers 37,12,25, and 19.
           Key [+]
           Key [+]
           Key [+]
           See 93 in X as the final answer.


                                                                       page 20

