home *** CD-ROM | disk | FTP | other *** search
/ GEMini Atari / GEMini_Atari_CD-ROM_Walnut_Creek_December_1993.iso / files / acc / calcs / progcalc.doc < prev    next >
Encoding:
Text File  |  1985-11-20  |  11.7 KB  |  246 lines

  1.      
  2.                CONTENTS
  3.      1.............................Introduction
  4.      2.............................Reverse Polish Notation
  5.      3.............................Functions
  6.      4.............................Sample Calculations
  7.      5.............................Miscellanious
  8.  
  9.  
  10. INTRODUCTION
  11.  
  12.       This program has been released into the public domain. It may not be 
  13. sold, or contained as part of a commercial product that is for sale.
  14.      It is for use with medium resolution.
  15.      This   calculator  is  designed  to  handle  simple   bit   oriented 
  16. calculations  encountered  during programing.  It provides the  user  with 
  17. integer  arithmetic  operations,   Boolean  logic  functions,   and  base 
  18. conversions.
  19.  
  20. REVERSE POLISH NOTATION (RPN)
  21.      If you have used a Hewlett-Packard calculator before you will have  no 
  22. problem using this program.   For those of you who haven't it will take  a 
  23. little getting used to,  but in the end you will agree that it is a better 
  24. way of doing things.
  25.      A  RPN calculator uses a stack to store results of its  calculations.  
  26. All  arithmetic operations are done on the top two numbers on  the  stack.  
  27. This is accomplished by first placing the operands onto the stack and then 
  28. specifying the operation to be performed.  For example the operation would 
  29. be performed in the following steps:
  30.                3+7=   
  31.                                           
  32.                3                      
  33.                ENTER (Push)
  34.                7
  35.                ENTER (Push)
  36.                +    
  37. Upon  pressing the "+" key the top number (7) is popped from  the  stack, 
  38. next  the  number which is now at the top of the stack (3) is  also  popped 
  39. from the top of the stack.  The two numbers are then added and the  result 
  40. is  pushed onto the stack.   On the calculator the "+" functions  executes 
  41. the enter function saving a key stroke, so the sequence is simplified to:
  42.              3 [Enter] 7+
  43. The number which is at the top of the stack is what is displayed at by the 
  44. calculator.  This  is also the result of the calculation thus there is  no 
  45. need for an equal key.
  46.      If  you have never seen this before it may look strange,  but it  will 
  47. become  second  nature with a little practice.   Here is  one,  more  more 
  48. complicated example:
  49.                3(6+2)/(9-2)=?      
  50.                3 [Enter]      (* push 3 onto stack *)
  51.                6 [Enter]      (* push 6 onto stack *)
  52.                2              (*2  is pushed onto  stack  when is hit *)
  53.                +              (* 6+2 now on top of stack *)
  54.                *              (* 3(6+2) on top *)
  55.                9 [Enter]      (* push 9 *)
  56.                2              (* push 2 then subtract *)
  57.                -              (* 9-2 on top of stack *)
  58.                /              (* 3(6+2)/(9-2)       *)
  59. Using  RPN  also  allows the parenthesis to be left  out  which  saves  key 
  60. strokes.   For more examples of RPN look at the sample calculations  shown 
  61. later.  If you are still confused you may try looking at the owners manual 
  62. for an HP calculator.
  63.  
  64. FUNCTIONS
  65.      This  section  will  outline and give an  example  of  the  functions 
  66. included in the calculator.   Each function can be accessed in one of  two 
  67. ways.  First the mouse can be used by placing the pointer on the key to be 
  68. pressed  and  clicking  the mouse button.   Each  key  has  two  functions 
  69. associated with it.   To access the one written on the key press the  left 
  70. button on the mouse, and for the second function which is written above the 
  71. key press the mouses right button.
  72.      Another  way in which the calculator keys can be pressed is  by  using 
  73. the ST numeric key pad,  Backspace,  and delete keys. For most of the keys 
  74. the  layout  of the Calculator Keys and the numeric key pad are  the  same, 
  75. however  there  are  a few differences.   The  second  function  for  each 
  76. calculator  key is accessed by pressing (on the ST keyboard) the sift  key 
  77. while typing the assigned key.
  78.      The following functions are provided by the calculator.
  79.  
  80. Display Modes:
  81. DEC- Display numbers in decimal mode.   Key:.     { on key pad }
  82.      Typing this function will cause all numbers to be displayed  in 
  83. decimal.
  84. [HEX]- "  " Hexadecimal mode              Key:(     { on key pad }
  85. [BIN]- " "  Binary mode                   Key:)     
  86.      Before going on a few comments are in order.  First changing  display 
  87. formats  has no effect on the numbers which are stored in  the  calculator. 
  88. These  functions only effect the way in which the numbers  are  displayed.  
  89. There  are  however  some complications that arise  from  the  display  of 
  90. negative numbers.   To illustrate these lets do the following example.   Do 
  91. the following keystrokes:
  92.                [16b]     {this key explained later}
  93.                [DEC]     {decimal display mode}
  94.                862       {thats three key strokes}
  95.                [HEX]     { $35E is the hex display}
  96.                [BIN]     { %1101011110 is binary for 862}
  97.  
  98. [+/-]- change sign                 Key:[Shift][-]
  99.      Changes sign of display. If the number is outside of the signed 
  100. range  for  the  display mode this keystroke  will  be  ignored.  For 
  101. example try to change the sign of 255 in 8 bit mode ( you can't).
  102. [2CM]- Two's compliment            Key:[Shift][Enter]
  103.      Takes  the  two's compliment of  the  number  displayed.   This 
  104. function  is  done on the magnitude of the number.   The  result  is 
  105. always positive.
  106.  
  107. Continuing with the above example:
  108.                [DEC]     {862 is back on the display}
  109.                [+/-]     {-862}
  110.                [HEX]     {-35E }
  111.                [2CM]     {$FCA2 this is twos comp of 862 }
  112.                [2CM]     {$35E now displayed }
  113.      When dealing with signed numbers (or unsigned it is important to keep 
  114. in mind that the calculator does not flag overflow errors.  For example try 
  115. the following calculation:
  116.                [DEC]
  117.                [8b]      {8 bit mode}
  118.                0[Enter]
  119.                255[-]    {-127 ! }
  120.      In the above example the result of the calculation should have been -
  121. 255 however since the 8 bit signed number range is -128 to 127 the  result 
  122. was  simply truncated.   If the result is greater then 127 the  calculator 
  123. will represent it as an unsigned number for example:
  124.                0[Enter]
  125.                255[+]    {255 is displayed }
  126. [AND]-bit and function                       Key-[Shift]9
  127. [OR]-bit or function                         Key-[Shift]8
  128. [XOR]-Bit Xor function                       Key-[Shift]7
  129. [COM]- Compliment all bits                   Key-[Shift]+
  130.      An example of one the logical functions is shown bellow.
  131.                1[Enter]
  132.                128       {no Enter here}
  133.                [OR]      {displays 129}
  134.                [BIN]     (%10000001}
  135. [LSR]- Logical Shift Right                    Key-[Shift]6
  136.      Shifts  display one Byte to the right.  0's are shifted in  and 
  137. the least significant byte is lost.
  138. [ASL]- Arithmetic Shift Left                 Key-[Shift]*
  139.      Shifts display one Byte to the left.  0's in and most sig. byte 
  140. lost.
  141.      Note  that  to  shift one bit position instead  of  8  the  key 
  142. strokes 2[*] or 2[DIV] can be used.
  143. [Clx]- Clear the display register            Key-[Shift]BackSpace
  144.      Set the number displayed to 0. This function does not alter the 
  145. calculator stack.
  146. [Cld]- Clear low digit                       Key-BackSpace
  147.      Clear low digit of display
  148.  
  149.      The two Cl functions are aids for entering numbers.  An example 
  150. of their use is as follows: Suppose you were entering 354
  151.                [3][5][6] {oops! entered a 6.  356 displayed}
  152.                [Cld]     {35 displayed}
  153.                [4]       {that's better. 354 displayed}
  154.                [Clx]     {got rid of the whole. 0 displayed}
  155. [x|y]- exchange top two numbers on stack     Key-Delete
  156.      Switches  the number displayed with the number that is next  on 
  157. the stack. Does not alter other numbers on stack.
  158.                5[Enter]
  159.                4         {4 displayed}
  160.                [x|y]     {5 now displayed}
  161.                +         {9 displayed}
  162. [hi]- show high word.                        Key-[Shift]Delete
  163.      This function is only used to display the high 16 bits when  in 
  164. 32Bit binary display mode. If not in this mode the key is ignored.
  165.                [HEX]
  166.                [32b]
  167.                FFFFAAAA
  168.                [BIN]     {1010,1010,1010,1010 this is the low word}
  169.                [hi]      {1111,1111,1111,1111, this is the high word
  170.                          note the far right , }
  171.  
  172.  
  173. SAMPLE CALCULATIONS.
  174.  
  175.      As  a  final  example I will present some examples  of  more  complex 
  176. calculations using the calculator.
  177.  
  178.      1  Find the contents of the D register after executing the  following 
  179. segment of 6809 code.  It multiplies the 8 bit number at location NUM1 by 
  180. the 16 bet number at location NUM2 and returns the result on the stack.
  181.  
  182. 1    START     LDA       NUM1      A,B ARE 8 BIT ACCUMUL.
  183. 2              LDB       NUM2+1    LOW BYTE
  184. 3              MUL                 RESULT IN D=A|B
  185. 4              PSHU      D         SAVE PARTIAL PRODUCT
  186. 5              LDA       NUM1
  187. 6              LDB       NUM2      MULT. HIGH BYTE
  188. 7              MUL
  189. 8              ADDB      ,U+       ADD TO PARTIAL PROD. ON STACK
  190. 9              BCC       NOINC
  191. 10             INCA                PROPAGATE CARRY
  192. 11             PSHU      D         3 BYTE RESULT ON STACK
  193. 12             RTS
  194.     Suppose we were to test the above routine by setting [NUM1]=$A8
  195. and  [NUM2]=$73F2  and  single  stepping  through  the   code.    By 
  196. calculating the intermediate results of the multiplication it  would 
  197. be easier to find bugs.
  198.  
  199.                [32b][HEX]          {set up the display mode}
  200.                A8[Enter]
  201.                F2[*]               {$9ED0 should be in D after step 3}
  202.                [Enter]             {just like step 4}
  203.                A8[Enter]
  204.                73[*]               {$4B78 is partial product from step7}
  205.                [Asl]               (*$4B7800 adjusted partial prod. }
  206.                [+]                 {gives us the result that should
  207.                                     be on stack at return}
  208.                
  209. 2 As an example of RPN,  Suppose for some odd reason you wanted to evaluate 
  210. the following expression:
  211.                (  (2*(783+17)*3) XOR (4543 MOD 30)  ) DIV 5 = ?
  212.  
  213.                [16b][DEC]          {decimal word display }
  214.                2[Enter]            
  215.                783[Enter]
  216.                17[+]
  217.                [*]
  218.                3[*]
  219.                4543[Enter]
  220.                30[MOD]
  221.                [XOR]
  222.                5[DIV]              {?=962}
  223.                
  224. 5 Miscellaneous
  225.      Well that about does it.  Was your favorite bit oriented or  programing 
  226. function  not  included?  Well drop me a line including a description  of  the 
  227. function and an example of its use. Also pass along in bug reports to me.
  228.      Will  this program work on a monochrome monitor?  I haven't tried  it.  
  229. If you are interested in getting a monochrome version get in touch with  me. 
  230. Maybe we can make one.
  231.      Lastly donations will be accepted and appreciated.
  232.                Until May 87 my address will be
  233.                          Bruce Mealey
  234.                          704 W 21st #308
  235.                          Austin, Tx 78705
  236.                          512-320-0886
  237.                             Or Post Message to me on Sex. board
  238.                                    512-478-4282
  239.  
  240.                After  May  87  I don't know were I will  be  but  anything 
  241. mailed to the address below will be forwarded to me.
  242.                          Bruce Mealey
  243.                          6215 Hurst La
  244.                          New Orleans, La 70118
  245.  
  246.