home *** CD-ROM | disk | FTP | other *** search
/ Falcon 030 Power 2 / F030_POWER2.iso / ST_STE / MAGS / ICTARI10.ARJ / ictari.10 / ASSEMBLY / FLOAT_PT / FP_STOS.DOC < prev    next >
Text File  |  1994-05-29  |  15KB  |  311 lines

  1.  
  2.           Using STOS Floating Point Routines in Machine Code Programs
  3.           ===========================================================
  4.  
  5.                                 By Peter Hibbs
  6.  
  7.     It is sometimes useful to  have  floating  point arithmetic routines in
  8.     machine code, unfortunately these are very difficult to write and there
  9.     is very little information available  on  how  to  write them. The STOS
  10.     Basic language has an extension library called FLOAT.BIN which contains
  11.     all the main floating point arithmetic  routines as a binary file which
  12.     can be linked into STOS Basic when required. This document shows how to
  13.     use these routines in your  own  machine  code programs. (Note that the
  14.     FLOAT102.BIN file which is on the ST  User cover disk of Sept 1993 does
  15.     not work as it is a different version).
  16.  
  17.     The routines available are as follows :-
  18.  
  19.     1   Add two floating point numbers.
  20.     2   Subtract one floating point number from another.
  21.     3   Multiply two floating point numbers together.
  22.     4   Divide one floating point number into another.
  23.     5   Return the sine of a floating point number.
  24.     6   Return the cosine of a floating point number.
  25.     7   Return the tangent of a floating point number.
  26.     8   Return the exponential of a floating point number.
  27.     9   Return the naperien log of a floating point number.
  28.     10  Return the base 10 log of a floating point number.
  29.     11  Return the square root of a floating point number.
  30.     12  Convert an ASCII string into a floating point number.
  31.     13  Convert a floating point number into an ASCII string.
  32.     14  Convert a floating point number into an integer.
  33.     15  Convert an integer value into a floating point number.
  34.     16  Tests if two floating point numbers are equal.
  35.     17  Tests if two floating point numbers are not equal.
  36.     18  Tests if a floating point number is greater than another one.
  37.     19  Tests if a fp number is equal to or greater than another one.
  38.     20  Tests if a floating point number is less than another one.
  39.     21  Tests if a fp number is less than or equal to another one.
  40.     22  Return the arc sin of a floating point number.
  41.     23  Return the arc cos of a floating point number.
  42.     24  Return the arc tan of a floating point number.
  43.     25  Return the hyperbolic sin of a floating point number.
  44.     26  Return the hyperbolic cos of a floating point number.
  45.     27  Return the hyperbolic tan of a floating point number.
  46.     28  Return the integer part of a floating point number.
  47.     29  Return the value of a number raised to the power of another one.
  48.  
  49.     The floating point operations use  numbers  in  the  IEEE 64 bit format
  50.     with a numerical range of 10E-307  to  10E+308. For more information on
  51.     the mathematical use of these  routines  please  consult your STOS User
  52.     Guide.
  53.  
  54.     To use the  binary  file  in  your  own  program  first  copy  the file
  55.     FP_STOS.S into your source code  and  the  file FLOAT.BIN from the STOS
  56.     language disk into your library folder  on your hard disk/working disk.
  57.     The STOS library file is 'included' in the source file as a binary file
  58.     using the 'incbin' pseudo-op and is  labelled  as fp_data. You may also
  59.     need to set up the pathname  of  the 'incbin' pseudo-op as appropriate.
  60.     Note that  the  ninth  instruction  in  the  'float_point'  sub-routine
  61.     locates the function look-up table by adding $398C to the start address
  62.     of the data file. I don't  know  if  there  is more than one version of
  63.     this file in existence but  if  there  is,  this  value  may need to be
  64.     changed. The FLOAT.BIN file I am using has a size of 15976 bytes.
  65.  
  66.     The FP_STOS.S file contains  two sub-routines, 'init_float' initialises
  67.     the binary file by changing the  longword addresses in conjunction with
  68.     the re-location table at the end  of  the  data. This routine should be
  69.     called near the start of the program once to set up these addresses.
  70.  
  71.     The 'float_point' sub-routine  is  called  each  time  a floating point
  72.     operation is required. In  most  cases  registers  d0  and  d1 hold one
  73.     number, registers d2 and d3  hold  the second number (where applicable)
  74.     and register d4 holds the  function  number (0-28). The values returned
  75.     are always held in registers d0 and d1, no other registers are changed.
  76.     Note that the original STOS routines  pass  the numbers to the routines
  77.     in registers d1/d2 (or d3/d4)  but  return  the results in registers d0
  78.     and d1  which  makes  it  very  messy  to  program.  The  start  of the
  79.     'float_point' routines swaps  the  registers  around  so  that they are
  80.     always in d0/d1 or d2/d3.
  81.  
  82.     The standard  IEEE  format  for  the  double  precision  floating point
  83.     numbers is as follows: registers d0.l and d1.l together form a complete
  84.     64 bit floating point number (registers  d2  and d3 are formed the same
  85.     way). Register d0.l holds  the  bottom  half  (bits 0-31) and registers
  86.     d1.l holds the top half (bits 32-63). Bits 0-51 form the mantissa part,
  87.     bits 52-62 form the exponent part and  bit 63 holds the sign. The exact
  88.     format of the numbers is not really important for the programmer (and I
  89.     don't know what it is anyway) since  there are routines to convert from
  90.     ASCII or integer  formats  available.  Just  remember  when moving data
  91.     about that the top and bottom halves  of  the numbers are copied to the
  92.     correct registers as longwords.
  93.  
  94.     A typical program  to  multiply  two  floating  point  numbers in ASCII
  95.     format and display the results in ASCII format might look like this :-
  96.  
  97.     main initialisation
  98.                 .
  99.                 bsr     init_float              initialise fp code
  100.                 .
  101.     first convert ASCII numbers to fp format (if not already done)
  102.                 .
  103.                 lea     first_no,a0             convert 1st No to fp
  104.                 move    #11,d4                  ASCII to fp function
  105.                 bsr     float_point             d0/d1=fp No
  106.                 move.l  d0,d2                   and save in d2/d3
  107.                 move.l  d1,d3
  108.  
  109.                 lea     second_no,a0            convert 2nd No to fp
  110.                 bsr     float_point             d4=11 still, d0/d1=fp No
  111.                 .
  112.     now multiply fp numbers together, result in d0/d1
  113.                 .
  114.                 move    #2,d4                   multiply function
  115.                 bsr     float_point             result in d0/d1
  116.                 .
  117.     now convert fp numbers back to ASCII for display
  118.                 .
  119.                 lea     fp_buffer,a0            convert fp to ASCII
  120.                 move    #'3',d2                 3 digits after decimal pt
  121.                 move    #12,d4                  fp to ASCII function
  122.                 bsr     float_point             result in fp_buffer
  123.                 .
  124.     now display ASCII numbers, if required
  125.                 .
  126.                 move.l  a0,-(sp)                display results with
  127.                 move    #9,-(sp)                c_conws BIOS call at
  128.                 trap    #1                      current cursor posn
  129.                 addq    #6,sp
  130.                 .
  131.                 .
  132.     first_no    dc.b    '123.456',0             1st No=123.456
  133.     second_no   dc.b    '987.654',0             2nd No=987.654
  134.                 .
  135.     fp_buffer   ds.b    50                      output buffer
  136.                 .
  137.  
  138.     The format for each function  with  the  input and output parameters is
  139.     shown below :-
  140.  
  141.     1   Add two floating point numbers.
  142.         ENTRY d0.l and d1.l hold first fp number
  143.               d2.l and d3.l hold second fp number
  144.               d4=0
  145.         EXIT  d0.l and d1.l hold result of d0/d1 plus d2/d3
  146.  
  147.     2   Subtract one floating point number from another.
  148.         ENTRY d0.l and d1.l hold first fp number
  149.               d2.l and d3.l hold second fp number
  150.               d4=1
  151.         EXIT  d0.l and d1.l hold result of d0/d1 minus d2/d3
  152.  
  153.     3   Multiply two floating point numbers together.
  154.         ENTRY d0.l and d1.l hold first fp number
  155.               d2.l and d3.l hold second fp number
  156.               d4=2
  157.         EXIT  d0.l and d1.l hold result of d0/d1 times d2/d3
  158.  
  159.     4   Divide one floating point number into another.
  160.         ENTRY d0.l and d1.l hold first fp number
  161.               d2.l and d3.l hold second fp number
  162.               d4=3
  163.         EXIT  d0.l and d1.l hold result of d0/d1 divided by d2/d3
  164.  
  165.     5   Return the sine of a floating point number.
  166.         ENTRY d0.l and d1.l hold floating point number
  167.               d4=4
  168.         EXIT  d0.l and d1.l hold sine value
  169.  
  170.     6   Return the cosine of a floating point number.
  171.         ENTRY d0.l and d1.l hold floating point number
  172.               d4=5
  173.         EXIT  d0.l and d1.l hold cosine value
  174.  
  175.     7   Return the tangent of a floating point number.
  176.         ENTRY d0.l and d1.l hold floating point number
  177.               d4=6
  178.         EXIT  d0.l and d1.l hold tangent value
  179.  
  180.     8   Returns the exponential of a floating point number.
  181.         ENTRY d0.l and d1.l hold floating point number
  182.               d4=7
  183.         EXIT  d0.l and d1.l hold exponential value
  184.  
  185.     9   Returns the naperien log of a floating point number.
  186.         ENTRY d0.l and d1.l hold floating point number
  187.               d4=8
  188.         EXIT  d0.l and d1.l hold naperien log value
  189.  
  190.     10  Returns the base10 log of a floating point number.
  191.         ENTRY d0.l and d1.l hold floating point number
  192.               d4=9
  193.         EXIT  d0.l and d1.l hold base10 log value
  194.  
  195.     11  Returns the square root of a floating point number.
  196.         ENTRY d0.l and d1.l hold floating point number
  197.               d4=10
  198.         EXIT  d0.l and d1.l hold square root value
  199.  
  200.     12  Converts an ASCII string into a floating point number.
  201.         ENTRY a0=start address of buffer which holds value in ASCII
  202.               d4=11
  203.         EXIT  d0.l and d1.l hold floating point number
  204.  
  205.     13  Converts a floating point number into an ASCII string.
  206.         ENTRY d0.l and d1.l hold floating point number
  207.               d2 holds number of digits required after decimal point
  208.                  as an ASCII character
  209.               d4=12
  210.               a0=start address of buffer (ensure buffer is big enough)
  211.         EXIT  d0=number of characters (excluding the NUL chr) in string
  212.               a0=start address of output buffer
  213.  
  214.     14  Converts a floating point number into an integer.
  215.         ENTRY d0.l and d1.l hold floating point number
  216.               d4=13
  217.         EXIT  d0.l holds integer value
  218.  
  219.     15  Converts an integer value into a floating point number.
  220.         ENTRY d0.l holds integer number
  221.               d4=14
  222.         EXIT  d0.l and d1.l hold floating point value
  223.  
  224.     16  Tests if two floating point numbers are equal.
  225.         ENTRY d0.l and d1.l hold first floating point number
  226.               d2.l and d3.l hold second floating point number
  227.               d4=15
  228.         EXIT  d0=1 if numbers are equal or 0 if not
  229.  
  230.     17  Tests if two floating point numbers are not equal.
  231.         ENTRY d0.l and d1.l hold first floating point number
  232.               d2.l and d3.l hold second floating point number
  233.               d4=16
  234.         EXIT  d0=1 if numbers are not equal or 0 if they are
  235.  
  236.     18  Tests if a floating point number is greater than another one.
  237.         ENTRY d0.l and d1.l hold first floating point number
  238.               d2.l and d3.l hold second floating point number
  239.               d4=17
  240.         EXIT  d0=1 if 1st number is greater than 2nd number or 0 if not
  241.  
  242.     19  Tests if a fp number is equal to or greater than another one.
  243.         ENTRY d0.l and d1.l hold first floating point number
  244.               d2.l and d3.l hold second floating point number
  245.               d4=18
  246.         EXIT  d0=1 if 1st number is equal to or greater than 2nd number or
  247.                    0 if not
  248.  
  249.     20  Tests if a floating point number is less than another one.
  250.         ENTRY d0.l and d1.l hold first floating point number
  251.               d2.l and d3.l hold second floating point number
  252.               d4=19
  253.         EXIT  d0=1 if 1st number is less than 2nd number or 0 if not
  254.  
  255.     21  Tests if a fp number is less than or equal to another one.
  256.         ENTRY d0.l and d1.l hold first floating point number
  257.               d2.l and d3.l hold second floating point number
  258.               d4=20
  259.         EXIT  d0=1 if 1st number is less than or equal to 2nd number  or
  260.                    0 if not
  261.  
  262.     22  Returns the arc sin of a floating point number.
  263.         ENTRY d0.l and d1.l hold floating point number
  264.               d4=21
  265.         EXIT  d0.l and d1.l hold arc sin value
  266.  
  267.     23  Returns the arc cos of a floating point number.
  268.         ENTRY d0.l and d1.l hold floating point number
  269.               d4=22
  270.         EXIT  d0.l and d1.l hold arc cos value
  271.  
  272.     24  Returns the arc tan of a floating point number.
  273.         ENTRY d0.l and d1.l hold floating point number
  274.               d4=23
  275.         EXIT  d0.l and d1.l hold arc tan value
  276.  
  277.     25  Returns the hyperbolic sin of a floating point number.
  278.         ENTRY d0.l and d1.l hold floating point number
  279.               d4=24
  280.         EXIT  d0.l and d1.l hold hyperbolic sin value
  281.  
  282.     26  Returns the hyperbolic cos of a floating point number.
  283.         ENTRY d0.l and d1.l hold floating point number
  284.               d4=25
  285.         EXIT  d0.l and d1.l hold hyperbolic cos value
  286.  
  287.     27  Returns the hyperbolic tan of a floating point number.
  288.         ENTRY d0.l and d1.l hold floating point number
  289.               d4=26
  290.         EXIT  d0.l and d1.l hold hyperbolic tan value
  291.  
  292.     28  Returns the integer part of a floating point number.
  293.         ENTRY d0.l and d1.l hold floating point number
  294.               d4=27
  295.         EXIT  d0.l and d1.l hold integer part value
  296.  
  297.     29  Returns the value of a number raised to the power of another one.
  298.         ENTRY d0.l and d1.l hold first floating point number
  299.               d2.l and d3.l hold second floating point number
  300.               d4=28
  301.         EXIT  d0.l and d1.l hold value of 1st number raised to the power of
  302.               the 2nd number
  303.  
  304.  
  305.     See also FP_MACRO.DOC file  for  macro  definitions. Programmers should
  306.     note that although it would be  OK  to  use the FLOAT.BIN file in their
  307.     own programs it could  be  a  breach  of  copyright  to  use  it in any
  308.     published programs. ICTARI accepts  no  responsibility  for programs or
  309.     programmers who may be  in  breach  of  copyright  in  respect of these
  310.     routines.
  311.