home *** CD-ROM | disk | FTP | other *** search
/ Oakland CPM Archive / oakcpm.iso / cpm / calculat / hp11.lbr / RPN.DZC / RPN.DOC
Text File  |  1989-07-20  |  9KB  |  230 lines

  1. =================================================================
  2.  
  3.  
  4.                               R P N
  5.  
  6.  
  7. RPN Notation
  8. ------------
  9.  
  10. Reverse Polish Notation (RPN), also called postfix notation, is
  11. a simple but powerful stack oriented notation commonly used in
  12. Hewlett-Packard calculators.  You first enter the two numbers you
  13. wish to operate on, using the <RETURN> key to separate the two
  14. numbers you are entering and then you enter the function you wish
  15. to perform.  The numbers you enter are pushed onto a stack and
  16. the function performed on the numbers in the stack.  The result
  17. is displayed immediately after the function is entered.
  18.  
  19. Within it's limits, HP11 follows the RPN conventions used by
  20. Hewlett-Packard in their line of RPN calculators.
  21.  
  22. For example (assuming the decimal display mode):
  23.  
  24.      To Solve  Function            Keystrokes   Display
  25.      --------  -----------------   ----------   -------
  26.      9+3=12    9 plus 3            9<RET>3+        12
  27.      9-3=6     9 minus 3           9<RET>3-         6
  28.      9*3=27    9 times 3           9<RET>3*        27
  29.      9/3=3     9 divided by 3      9<RET>3/         3
  30.      9^3=729   9 to the 3rd power  9<RET>3^       729
  31.  
  32.  
  33. Stack
  34. -----
  35.  
  36. RPN is based on the stack.  A number is entered onto the stack by
  37. keying in the digits, ending with <RET>.  Each subsequent number
  38. keyed in will push the existing contents of the stack one level
  39. higher.
  40.  
  41. The structure of HP11's 4 level stack is shown below:
  42.  
  43.                T -> 0000      Stack register 4
  44.                Z -> 0000      Stack register 3
  45.                Y -> 0000      Stack register 2
  46.                --------------------------------------------
  47.                X -> 0000      Stack register 1 <- Displayed
  48.  
  49. HP11 always displays the contents of the X register.  When the
  50. stack is lifted, the contents of each stack register are moved up
  51. one level, the contents of register X are copied into Y and the
  52. contents of register T, the topmost register, are lost.
  53.  
  54. When the stack is dropped, the contents of each stack register
  55. are moved down one level and the contents of the T register are
  56. copied into register Z.  The result of the calculator operation
  57. is placed in register X.
  58.  
  59. By entering a number 4 times to copy it into each stack register,
  60. that number becomes a 'constant' in the Y register for subsequent
  61. chain operations.  Each subsequent operation will drop the stack,
  62. restoring the same 'constant' value to the Y register for the
  63. next operation.
  64.  
  65.  
  66. Stack Functions
  67. ---------------
  68.  
  69. HP11 has several functions that affect only the stack.  In each
  70. of these examples, each stack register starts out loaded with the
  71. number of that register.
  72.  
  73.  
  74. Clearing the Stack (^X):
  75.      Control-X clears the entire stack.  The values contained in
  76.      the LAST-X and memory registers are not affected.  HP11
  77.      starts with a clear stack when loaded from disk.
  78.  
  79.                T -> 4         T -> 0
  80.                Z -> 3         Z -> 0
  81.                Y -> 2         Y -> 0
  82.                -------------------------------------
  83.                X -> 1         X -> 0    <- Displayed
  84.                ------         ------
  85.                     Key: ^X             (Clear stack)
  86.  
  87.  
  88. Entering a number (<RET>):
  89.      <RET>, used as the ENTER key, terminates entry of a number
  90.      and places it on the stack.  It also separates two numbers
  91.      entered one after the other.  <RET> lifts the stack and
  92.      copys the number in the X register to the Y register,
  93.      replacing it with the number that has just been keyed in.
  94.      The value in the top stack register, register T, is lost.
  95.  
  96.                T -> 4         T -> 3    Previous T (4) lost
  97.                Z -> 3         Z -> 2
  98.                Y -> 2         Y -> 1
  99.                -------------------------------------
  100.                X -> 1         X -> 789  <- Displayed
  101.                ------         --------
  102.                     Key: 789<RET>       (Enter 789)
  103.  
  104.  
  105. Stack drop:
  106.      A numeric function will drop the stack one level and replace
  107.      the value in X with the numeric result.  The value in
  108.      register T is copied down to register Z whenever the stack
  109.      is dropped.
  110.  
  111.                T -> 4         T -> 4    Value in T copied to Z
  112.                Z -> 3         Z -> 4
  113.                Y -> 2         Y -> 3
  114.                -------------------------------------
  115.                X -> 1         X -> 3    <- Displayed
  116.                ------         ------
  117.                     Key: +              (X+Y)
  118.                          (2+1=3)
  119.  
  120.  
  121. Roll stack up (>) or down (<):
  122.      When the stack is rolled up, the stack is lifted one level
  123.      and the previous value of T is moved down to X.  When the
  124.      stack is rolled down, the stack is dropped one level and the
  125.      previous value of X is moved up to T.  No values are lost.
  126.  
  127.                T -> 4         T -> 3    Value from T moved
  128.                Z -> 3         Z -> 2         down to X
  129.                Y -> 2         Y -> 1
  130.                -------------------------------------
  131.                X -> 1         X -> 4    <- Displayed
  132.                ------         ------
  133.                     Key: >              (Roll Up)
  134.  
  135.  
  136.                T -> 4         T -> 1    Value from X moved
  137.                Z -> 3         Z -> 4         up to T
  138.                Y -> 2         Y -> 3
  139.                -------------------------------------
  140.                X -> 1         X -> 2    <- Displayed
  141.                ------         ------
  142.                     Key: <              (Roll Down)
  143.  
  144.  
  145. Exchange contents of X and Y (=):
  146.      The contents of registers X and Y are exchanged.  No other
  147.      registers are affected.  This function is useful when you
  148.      need to reverse the order of the operands before you perform
  149.      an operation sensitive to the order of the operands, such as
  150.      subtraction, division, or exponentiation.
  151.  
  152.                Y -> 2         Y -> 1
  153.                -------------------------------------
  154.                X -> 1         X -> 2    <- Displayed
  155.                ------         ------
  156.                     Key: =              (X<>Y)
  157.  
  158.  
  159. Last X (L):
  160.      When a numeric function is executed, a copy of the last
  161.      value in the X register before the function is executed is
  162.      saved in the Last-X register.  That value can be restored to
  163.      the X register using the 'L' key.  The stack is lifted,
  164.      moving the current contents of the X register to the Y
  165.      register, etc.  The value in the Last-X register is not
  166.      affected.
  167.  
  168.                T -> 3         T -> 3         T -> 3
  169.                Z -> 2         Z -> 3         Z -> 2
  170.                Y -> 1         Y -> 2         Y -> 9
  171.                -------------------------------------------------
  172.      Last-X -> X -> 8         X -> 9         X -> 8 <- Displayed
  173.                ------         ------         -----
  174.                     Key: +         Key: L           (Last-X)
  175.                          (1+8=9)
  176.  
  177.  
  178. Numeric Functions and the Stack
  179. -------------------------------
  180.  
  181. When you want to key in two numbers, one after the other, you use
  182. the <RET> key between entries to separate the numbers.  When you
  183. want to key in a number and execute a function that uses the
  184. value already in the X register as the other operand, you don't
  185. need to use the <RET> key.  Instead, you enter the second operand
  186. directly followed by the desired operation key.
  187.  
  188.                T -> 4         T -> 3         T -> 3
  189.                Z -> 3         Z -> 2         Z -> 3
  190.                Y -> 2         Y -> 1         Y -> 2
  191.                -------------------------------------------------
  192.                X -> 1         X -> 5         X -> 6 <- Displayed
  193.                ------         ------         ------
  194.                     Key: 5         Key: +           (X=X+5)
  195.                                         (1+5=6)
  196.  
  197.  
  198. The functions <RET> and ^X (clear stack) disable the automatic
  199. stack lift when the next number is keyed in.  When any other
  200. function is used, the stack lift is enabled, causing the stack to
  201. automatically lift when the next number is keyed in.  This effect
  202. is very natural and you probably won't have to think about it.
  203.  
  204.  
  205. One-Number Function:
  206.      Negation (two's complement) is HP11's only one one-number
  207.      function.  It operates on the current value in the X
  208.      register, placing the result in the X register.  The rest of
  209.      the stack is unaffected.
  210.  
  211.  
  212. Two-Number Functions:
  213.      The remainder of HP11's numeric functions use the values in
  214.      both the X and Y registers.  In operations such as
  215.      subtraction or division, the last number keyed in is the
  216.      number you are subtracting or dividing by.  If you have the
  217.      numbers entered in the wrong order, use the '=' key to
  218.      exchange the values of the X and Y registers.
  219.  
  220.                T -> 3         T -> 2         T -> 2
  221.                Z -> 2         Z -> 1         Z -> 2
  222.                Y -> 1         Y -> 8         Y -> 1
  223.                -------------------------------------------------
  224.                X -> 8         X -> 4         X -> 2 <- Displayed
  225.                ------         ------         ------
  226.      Key: 8<RET>    Key: 4         Key: /           (Y/X)
  227.                                         (8/4=2)
  228.  
  229. =================================================================
  230.