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

  1. =================================================================
  2.  
  3.                                H P
  4.  
  5.               A Programmer's Integer RPN Calculator
  6.  
  7.                   Version 1.1    July 20, 1989
  8.  
  9.                        Copyright (c) 1989
  10.                                by
  11.                            Terry Hazen
  12.                       21460 Bear Creek Road
  13.                        Los Gatos, CA 95030
  14.  
  15.                  Voice.......... (408) 354-7188
  16.                  Saratoga RBBS.. (408) 354-5934
  17.                  Zee-Machine.... (408) 245-1420
  18.  
  19.  
  20.   HP11 and its documentation may not be circulated in any
  21.   incomplete or modified form without written permission of the
  22.   author.  Any commercial use of HP11 where the user receives
  23.   revenue by duplicating or distributing HP11 by itself or in
  24.   conjunction with any hardware or software product is expressly
  25.   prohibited unless authorized in writing by the author.  All
  26.   rights reserved.
  27.  
  28. =================================================================
  29.  
  30.  
  31. Introduction
  32. ------------
  33.  
  34. HP11.COM is a simple and very useful programmer's integer
  35. calculator modeled after a Hewlett-Packard calculator with RPN
  36. notation.  It is an extensive upgrade of Eric Meyer's HP10 and
  37. was rewritten and enhanced to reduce code size, to increase the
  38. number of memory storage registers, to add stack roll and last-x
  39. functions, and to improve the user interface and input error
  40. trapping.
  41.  
  42. If you are not familiar with RPN notation, you should review the
  43. file RPN.DOC for more information on RPN.  RPN.DOC also has more
  44. detail on how HP11 uses its stack during stack and numeric
  45. operations.
  46.  
  47. HP11 can operate in any of four display modes:  hexadecimal,
  48. decimal, binary, and character, making it very useful for quickly
  49. converting integer numbers from one base to another.  It can do
  50. integer addition, subtraction, multiplication, division,
  51. exponentiation and bitwise logical AND and OR operations.  It has
  52. a 4 level stack and 6 memory storage registers.
  53.  
  54. All HP11 internal storage and arithmetic is unsigned 16 bit.
  55. Thus 65537 becomes 00001, -1 becomes 65535, and so on.
  56. Multiplication and exponentiation overflow and division by 0 will
  57. generate errors.  In binary and character modes, the display
  58. shows only the lowest 8 bits of 16, so 8-bit overflow does not
  59. usually cause an error.
  60.  
  61.  
  62. HP11 CP/M 2.2 RSX version
  63. -------------------------
  64.  
  65. The utility HPRSX.COM will install a version of HP11.COM into
  66. memory as a CP/M 2.2 resident system extension (RSX).  The RSX
  67. remains resident in memory and can be called from the command
  68. line or from within other programs.  The RSX version of HP11
  69. operates just like HP11.COM.  See the file HPRSX.DOC for more
  70. information on the HP11 RSX.
  71.  
  72.  
  73. Running HP11
  74. ------------
  75.  
  76. When you invoke HP11, it will display its single operating line
  77. and wait for your input:
  78.  
  79.   A0>hp11
  80.   HP 1.1 - T.Hazen 7/89           H>     0000
  81.  
  82. The 'H>' indicates hexadecimal display mode (the default display
  83. mode), and '0000' is the four digit hex calculator display of
  84. register X, which is the register always displayed.  The HP11
  85. stack and memory are initialized to zero when HP11 is first
  86. loaded from disk.
  87.  
  88.  
  89. Exiting HP11
  90. ------------
  91.  
  92. Use control-C (^C) to exit HP11.  If you operate under ZCPR3, you
  93. may use the ZCPR3 'GO' command after exiting HP11 and before any
  94. other command is executed and it will return you to HP11 exactly
  95. where you left off.
  96.  
  97.  
  98. Changing Display Modes
  99. ----------------------
  100.  
  101. To change the display mode, use the escape key (<ESC>) followed
  102. by the first letter of the desired mode.  Either upper or lower
  103. case letters may be used to select the mode.  The display
  104. indicates which mode is currently being used, and the number in
  105. the X register will be displayed in the current mode.  You may
  106. translate numbers from one base to another by simply changing
  107. display modes.
  108.  
  109.  
  110. Hex Display Mode:
  111.      To select the hex display mode, enter <ESC>H.  In hex mode,
  112.      numbers display as four hex digits from 0000-FFFF.
  113.  
  114. Decimal Display Mode:
  115.      To select the decimal display mode, enter <ESC>D.  In
  116.      decimal mode, numbers display as five decimal digits from
  117.      00000-65535.
  118.  
  119. Binary Display Mode:
  120.      To select the binary display mode, enter <ESC>B.  In binary
  121.      mode, the least significant byte of the number displays as 8
  122.      binary digits, 00000000-11111111.
  123.  
  124. Character Display Mode:
  125.      To select the character display mode, enter <ESC>C.  In
  126.      character mode, the least significant 7 bits of the number
  127.      display as an ASCII character.  Control characters are
  128.      indicated by a '^' prefix.  For example, 03H will display as
  129.      '^C' and DEL (7FH), will display as '^?'.
  130.  
  131.      All non-command characters can be directly entered as data
  132.      in the character display mode.  Characters that have command
  133.      functions such as 'L', '/', '=', ^C, <RET> (^M), etc, can be
  134.      entered as data in the character mode by prefixing them with
  135.      the <ESC> character.  See the section on Entering Special
  136.      Characters for more information.
  137.  
  138.  
  139. The HP11 Stack
  140. --------------
  141.  
  142. The structure of HP11's 4 level stack is shown below:
  143.  
  144.                T -> 0000      Stack register 4
  145.                Z -> 0000      Stack register 3
  146.                Y -> 0000      Stack register 2
  147.                --------------------------------------------
  148.                X -> 0000      Stack register 1 <- Displayed
  149.  
  150. HP11 always displays the contents of the X register and all
  151. values entered are entered into the X register.  When a number is
  152. entered into the X register, the previous contents of the X
  153. register are automatically moved up to the Y register, the
  154. previous contents of the Y register are moved up to the Z
  155. register, etc.  See the section on Stack Operations for more
  156. information on how HP11's operations use the stack.
  157.  
  158.  
  159. Entering Numbers
  160. ----------------
  161.  
  162. Invoke HP11 and try entering the following sequence of keys:
  163.  
  164.                ^X  <ESC>D  1 <RET>  2  +  4  *
  165.  
  166. You have cleared the stack, selected the decimal mode, entered
  167. the decimal numbers '1' and '2', added them, entered '4' and
  168. multiplied 4 times the previous result.  The display should show
  169. '00012', which is (1+2)*4.
  170.  
  171. Your <ENTER> or <RET> key corresponds to the HP <ENTER> key.  It
  172. is used to separate two numbers as they are being entered one
  173. after the other or to copy the number in the displayed X register
  174. into the Y register.  You normally key in a string of digits,
  175. then press <RET> to enter the number in the displayed X register.
  176. You do not need to use <RET> after every number entry, however,
  177. as the use of the function keys also automatically terminates
  178. digit entry.
  179.  
  180. Depending on the current display mode, a maximum number of digits
  181. can be entered into the display, after which the leading digits
  182. will begin to be discarded.  HP11 accepts a maximum of four
  183. digits in the hex display mode, five digits in the decimal
  184. display mode, eight digits in the binary display mode and one
  185. digit in the character display mode.  The console bell will ring
  186. if you enter a character that is not acceptable in the current
  187. display mode.
  188.  
  189.  
  190. Correcting Entries
  191. ------------------
  192.  
  193. The backspace key (^H) works like the left arrow '<--' key on an
  194. HP calculator.  It has two functions.  During digit entry, it
  195. will delete the last digit typed.  Otherwise it will clear the X
  196. register and leave the stack lift disabled.
  197.  
  198.  
  199. Entering Special Characters
  200. ---------------------------
  201.  
  202. The <ESC> key may be used as a prefix in the character display
  203. mode to allow you to enter as a digit those characters that would
  204. otherwise be interpreted by HP11 as calculator functions:
  205.  
  206.                        +-*^/&|~=lLsSrR<>.,
  207.  
  208. as well as the control characters ^X, ^C and <RET> (^M).
  209.  
  210. To enter the character 's', for example, enter '<ESC>s' instead
  211. of 's', since entering 's' initiates a store to a memory
  212. register.
  213.  
  214.  
  215. Numeric Functions
  216. -----------------
  217.  
  218. HP11's integer numeric functions and the keys to invoke them are:
  219.  
  220.      +    Addition, Y+X
  221.      -    Subtraction, Y-X
  222.      *    Multiplication, Y*X
  223.      ^    Exponentiation, Y^X  (Y to the Xth power)
  224.      /    Integer quotient, INT(Y/X)
  225.                - Remainder, X*(Y/X-INT(Y/X)) -> Register R
  226.      &    Bitwise AND, X&Y
  227.      |    Bitwise OR, X|Y
  228.      ~    Negation [2's complement], ~X
  229.  
  230. Negation affects only the X register.  The other operations use
  231. the numbers in the first two registers X and Y as operands, and
  232. display the result in the X register, dropping the stack.
  233.  
  234. When an integer division is performed, you are often interested
  235. in both the quotient and the remainder.  To obtain both values
  236. with HP10, the operations had to be performed separately.  With
  237. HP11, the remainder is saved in the special reserved memory
  238. register R during the division operation.  Memory register R is
  239. accessed just like any of the regular memory registers 0-5.  It
  240. may also be used to store numbers, but any contents will be
  241. overwritten by the remainder during integer division operations.
  242.  
  243. The console bell will ring if an undefined key is pressed as an
  244. operator.  It will also ring and the current multiplication (*),
  245. division (/) or exponentiation (^) function will not operate if
  246. 16-bit overflow occurs or if division by 0 is attempted.  The
  247. stack is left unchanged.  Use the backspace key to delete the
  248. offending operand if you wish to try again.
  249.  
  250.  
  251. Stack Operations
  252. ----------------
  253.  
  254. See the file RPN.DOC for more detail on how HP11's functions
  255. affect the stack registers.
  256.  
  257. Entering a Number:
  258.      <RET> lifts the stack, copying the number in register X
  259.      into register Y.  The number being entered is then placed in
  260.      register X.  Stack lift is disabled.
  261.  
  262. Clearing the Stack:
  263.      You can clear the entire stack with Control-X (^X) at any
  264.      time.  Memory and Last-X registers are not affected.
  265.  
  266. Exchanging X and Y:
  267.      You can exchange the contents of the two lowest stack
  268.      registers X and Y with the '=' function (X<>Y).  No other
  269.      registers are affected.  This function is useful when you
  270.      need to reverse the order of operands before performing a
  271.      function sensitive to operand order such as subtraction,
  272.      divison or exponentiation.
  273.  
  274. Last-X:
  275.      When a numeric function is executed, a copy of the last
  276.      value in the X register before the function is executed is
  277.      saved in the Last-X register.  That value can be restored to
  278.      the X register using the 'L' (or 'l') key.  The stack is
  279.      lifted, moving the current contents of the X register to the
  280.      Y register, etc, unless stack lift has been disabled by the
  281.      <RET> or backspace key.  The value in the Last-X register is
  282.      not affected.  The Last-X function saves you from having to
  283.      reenter numbers you wish to use again and can assist you in
  284.      error recovery.
  285.  
  286.  
  287. Stack Roll:
  288.      You can roll the stack by using '>' (or the unshifted
  289.      equivalent '.') to roll it up one level and '<' (or ',') to
  290.      roll it down one level.  When the stack is rolled up, the
  291.      contents of all stack registers are moved up one level and
  292.      the value in the top stack register is moved down to the X
  293.      register.  When the stack is rolled down, the contents of
  294.      all stack registers are moved down one level and the value
  295.      in the X register is moved up to the top stack register.  No
  296.      stack values are lost as a result of stack roll operations.
  297.  
  298.  
  299. Memory Storage Registers
  300. ------------------------
  301.  
  302. There are 6 memory storage registers numbered 0-5 that may be
  303. used to store constants or intermediate values during
  304. calculations, for recalled as needed later.  The contents of
  305. memory registers are not affected by the clear stack (^X)
  306. operation.  Either upper or lower case letters may be used to
  307. specify memory register Store or Recall functions.
  308.  
  309. Storing a Number:
  310.      The number in the X register may be stored in any of the
  311.      memory registers using the command 'S' followed by the
  312.      number of the desired memory register.  The previous
  313.      contents of the memory register will be overwritten, but the
  314.      number in the X register will not be affected.  For example,
  315.      to store the number in register X in memory register 2,
  316.      enter 'S2'.
  317.  
  318.  
  319. Recalling a Number:
  320.      Numbers may be recalled from a memory register to register X
  321.      using the 'R' command followed by the number of the memory
  322.      register.  The stack will be lifted, putting the previous
  323.      contents of register X into register Y, but the number in
  324.      the memory register will not be affected.  For example, to
  325.      recall memory register 0 to register X, enter 'R0'.
  326.  
  327. Remainder Register:
  328.      An additional memory register R is used by the division
  329.      operation to store the remainder.  It may also be used to
  330.      store and recall numbers, but any contents will be
  331.      overwritten during a division operation.  The command 'RR'
  332.      (Recall Remainder) after a division operation will store a
  333.      copy of the remainder in register X and put the quotient in
  334.      register Y.  An exchange (=) operation will swap them if
  335.      desired.
  336.  
  337.  
  338. Examples
  339. --------
  340.  
  341. Try the following sample calculations.  Press the keys shown, and
  342. see whether the answer you get matches the example and if you
  343. understand the process.  In the sample problems, the 'h' suffix
  344. indicates a hex number.
  345.  
  346. 1)  Whatis(122+31)*8 ?
  347.           KEYSTROKES:  <ESC>D122<RET>31+8*
  348.           ANSWER:  D>    01224
  349.  
  350. 2)   How many 128-byte records are there between addresses D000h
  351.      and E100h?
  352.           KEYSTROKES:    <ESC>H E100<RET> D000 - <ESC>D 128 /
  353.           ANSWER:   D>    00034    (E100h-D000h)/128d
  354.  
  355. 3)   What character results from 'w' AND 5Fh ?
  356.           KEYSTROKES:  <ESC>Cw <ESC>H5F& <ESC>C
  357.           ANSWER:  C>   W    ('w'&5Fh)
  358.  
  359. 4)   Whatdoes-115looklikeinbinary?
  360.           KEYSTROKES:  <ESC>D115~<ESC>B
  361.           ANSWER:  B>10001101
  362.  
  363. 5)  Whatis5tothe4thpower?
  364.           KEYSTROKES:  <ESC>D5<RET>4^
  365.           ANSWER:  D>    00625
  366.  
  367. 6)   What is 6+7+8+9 ?
  368.           KEYSTROKES:    6<RET> 7<RET> 8<RET> 9 + + +
  369.           ANSWER:   H>     001E    (What is that in decimal?)
  370.  
  371. 7)   What is 1+2+3+4+5+6+7 ?  (Why can't you do it exactly the
  372.      same way as in example 6?)
  373.           KEYSTROKES:    <ESC>D 1<RET> 2<RET> 3<RET> 4 + + +
  374.                          5<RET> 6<RET> 7 + + +
  375.           ANSWER:   D>    00028    (The stack has 4 levels)
  376.  
  377.  
  378. Acknowledgements
  379. ----------------
  380.  
  381. HP11 is based on HP10, copyright (c) 1984 by Eric Meyers, and was
  382. upgraded with his kind permission.  Eric's many contributions to
  383. CP/M include the famous Video Display Editor (VDE), recently
  384. upgraded to the amazing ZDE by Carson Wilson.
  385.  
  386. My original intention was to write a CP/M 2.2 RSX version of
  387. HP10, following the conventions set by Bridger Mitchell, so that
  388. I could access the calculator from within programs such as text
  389. editors and patchers (Eric had already written the HP+ RSX for
  390. CP/M 3.0).
  391.  
  392. Along the way, however, I got inspired by recent articles in The
  393. Computer Journal by Hal Bower and Cameron Cotrill on ZSDOS and
  394. Lee Hart on Programming for Performance as well as Bridger
  395. Mitchell's columns on Advanced CP/M (including his columns on
  396. relocation and CP/M 2.2 RSX's) and Jay Sage's ZCPR3 Corner
  397. columns on the Z-System (including his column on PRL files).  So
  398. I decided to extensively reorganize and rewrite HP using some of
  399. the code size reduction and other programming techniques I was
  400. learning.
  401.  
  402. The result was a new and smaller (less than 1200 bytes) utility
  403. that has more functions and an improved user interface, including
  404. better input error trapping.  Plus it makes a really great RSX!
  405.  
  406. Thanks to all of you for the inspiration and the shared
  407. knowledge!
  408.  
  409. =================================================================
  410.