home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast2.iso / asmutil / bluebook.zip / FLOATPT.DOC < prev    next >
Text File  |  1986-05-14  |  19KB  |  434 lines

  1. FLOATPT.DOC -- Floating Point Conversion Procedures
  2. ===================================================
  3.  
  4.   From `BLUEBOOK of ASSEMBLY ROUTINES for the IBM PC & XT'
  5.         by Christopher L. Morgan
  6.         Copyright (C) 1984 by The Waite Group, Inc.
  7.  
  8.   Purpose: These procedures perform input, conversion, and output on 
  9.     floating point numbers.
  10.  
  11.    Contents:
  12.    ---------
  13.    BIN802DEC    --  Convert from 80-bit binary to decimal digits
  14.    DECDOUBLE    --  Double a temporary decimal floating point number
  15.    DECHALF    --  Halve a temporary decimal floating point number
  16.    DECNORM    --  Normalize temporary decimal floating point
  17.    DFP2SFP    --  Convert from double to single precision floating point
  18.    FIX        --  Convert from floating point to 16-bit integer
  19.    FLOAT    --  Convert from 16-bit integer to floating point
  20.    FPIN        --  Convert from external to internal floating point
  21.    FPINDIGIT    --  Convert from decimal digit to temporary floating point
  22.    FPOUT    --  Convert from internal to external floating point
  23.    FPTDIV    --  Divide temporary floating point by 10
  24.    FPTMUL    --  Multiply temporary floating point by 10
  25.    FPTNORM    --  Normalize temporary floating point
  26.    SFP2DFP    --  Convert from single to double precision floating point
  27.    SFP2TFP    --  Convert from single precision to temporary floating point
  28.    SGNDEC16IN    --  Convert from ASCII signed decimal to binary
  29.    TDECSHOW    --  Display floating point
  30.    TFP2SFP    --  Convert from temporary floating point to single precision
  31. _____________________________________________________________________________
  32.  
  33.   Overview
  34.  
  35. __________________________ FLOATING POINT ROUTINES __________________________
  36. -----------------------------------------------------------------------------
  37. Conversion from 80-bit binary to decimal digits
  38. BIN802DEC
  39.  
  40.   Function: This routine converts an 80-bit binary integer to a decimal string.
  41.  
  42.   Input: Upon entry, SI points to an 80-bit binary integer to be used as input
  43.     and DI points to a 25-digit decimal string to be used as output.
  44.  
  45.   Output: Upon exit, a 25-digit decimal string is where DI pointed upon entry.
  46.     DI still points there upon exit.
  47.  
  48.   Registers used: AX, BX, CX, DX, and SI are modified; DI points to output.
  49.  
  50.   Segments referenced: The data segment contains storage for the 80-bit binary
  51.     number (10 bytes) and the 25-digit decimal number (25 bytes).
  52.  
  53.   Note: This is a near procedure needed by FPOUT.
  54. -----------------------------------------------------------------------------
  55. Double a temporary decimal floating point number
  56. DECDOUBLE
  57.  
  58.   Function: This routine multiplies a temporary decimal floating point
  59.     number by two.
  60.  
  61.   Input: Upon entry, DS:DI points to a temporary decimal floating point number.
  62.  
  63.   Output: Upon exit, the number has been doubled.
  64.  
  65.   Registers used: AX,CX, & DX are modified.
  66.  
  67.   Segments referenced: The data segment contains storage for the temporary
  68.     decimal floating point number.    
  69.  
  70.   Note: This is a near procedure needed by FPOUT.
  71.  
  72. -----------------------------------------------------------------------------
  73. Half a temporary decimal floating point number
  74. DECHALF
  75.  
  76.   Function: This routine divides a temporary decimal floating number by two.
  77.  
  78.   Input: Upon entry, DI points to a temporary decimal floating point number.
  79.  
  80.   Output: Upon exit, the number has been divided by two. The result is not
  81.     normalized.
  82.  
  83.   Registers used: AX, CX, and DI are modified.
  84.  
  85.   Segments referenced: The data segment contains a temporary decimal floating
  86.     point number.
  87.  
  88.   Note: This is a near procedure needed by FPOUT.
  89. -----------------------------------------------------------------------------
  90. Normalize a temporary decimal floating point number
  91. DECNORM
  92.  
  93.   Function: This routine normalizes a temporary decimal floating number.
  94.  
  95.   Input: Upon entry, DI points to a temporary decimal floating point number.
  96.  
  97.   Output: Upon exit, the number is normalized.
  98.  
  99.   Registers used: AX, CX, and DI are modified.
  100.  
  101.   Segments referenced: The data segment contains a temporary decimal floating
  102.     point number.
  103.  
  104.   Note: Equates are used to shorten address fields. This is a near procedure
  105.      needed by FPOUT.
  106. -----------------------------------------------------------------------------
  107. Convert from double to single precision floating point
  108. DFP2SFP
  109.  
  110.   Function: This routine converts an internal double precision binary floating
  111.     point number to an internal single precision floating point number.
  112.  
  113.   Input: Upon entry, a double precision binary floating point number is in
  114.     DFPBUFF. The double precision floating point number has a 40-bit binary
  115.     mantissa, a sign bit, and an 8-bit exponent biased by 128.    
  116.  
  117.   Output: Upon exit, a single precision binary floating point number is in
  118.     SFPBUFF. The single precision floating point number has a 24-bit binary
  119.     mantissa, a sign bit, and an 8-bit exponent biased by 128.
  120.  
  121.   Registers used: Unmodified; AX is saved and restored.
  122.  
  123.   Segments referenced: The data segment contains storage for the variables,
  124.     SFPBUFF and DFPBUFF.
  125.  
  126.   Note: Equates are used to shorten address fields.
  127.  
  128. -----------------------------------------------------------------------------
  129. Convert from floating point to 16-bit integer
  130. FIX
  131.  
  132.   Function: This routine converts from internal single precision binary
  133.     floating point to internal 16-bit signed two's complement integer.
  134.  
  135.   Input: Upon entry, a single precision binary floating point is in SFPBUFF.
  136.     The single precision floating point number has a 24-bit binary mantissa, 
  137.     a sign bit, and an 8-bit exponent biased by 128.
  138.  
  139.   Output: Upon exit, a 16-bit signed two's complement binary number is in DX.
  140.  
  141.   Registers used: DX is used for output; CX,and AX are saved and then restored.
  142.  
  143.   Segments referenced: The data segment contains storage for SFPBUFF.
  144.  
  145.   Note: Equates are used to shorten address fields.
  146. -----------------------------------------------------------------------------
  147. Convert from 16-bit integer to floating point
  148. FLOAT
  149.  
  150.   Function: This routine converts an unsigned 16-bit binary number to a
  151.     single precision binary floating point number.
  152.  
  153.   Input: Upon entry, DX contains an unsigned 16-bit binary number.
  154.  
  155.   Output: Upon exit, SFPBUFF contains a single precision floating point
  156.     number. The single precision floating point number has a 24-bit binary
  157.     mantissa, a sign bit, and an 8-bit exponent biased by 128.
  158.  
  159.   Registers used: Unmodified; DX is used for input; DX, CX, & AX are saved
  160.     and then restored.
  161.  
  162.   Segments referenced: The data segment contains storage for the variable, 
  163.     SFPBUFF and the message, INTERNAL.
  164.  
  165.   Routines called: STDMSG_OUT,HEX16OUT,STD_SPACE (all for debugging).
  166.  
  167.   Note: Equates are used to shorten address fields.
  168. -----------------------------------------------------------------------------
  169. Convert from external to internal floating point
  170. FPIN
  171.  
  172.   Function: This routine accepts an ASCII decimal floating point number from
  173.     a standard input device and converts it to internal binary floating point.
  174.  
  175.   Input: The characters of the floating point number are received in ASCII
  176.     through a call to a standard input routine. The decimal floating point
  177.     number has an optional sign, followed by decimal digits of the mantissa
  178.     with one embedded decimal point. Following the mantissa is an optional
  179.     exponent starting with the letter, 'E', then an optional sign, then a
  180.     decimal number. It is possible to get erroneous results if the number is
  181.     too large or small to be stored as a single precision binary floating 
  182.     point number.
  183.  
  184.   Output: Upon exit a single precision binary floating point number is in
  185.     SFPBUFF. The single precision floating point number has a 24-bit binary
  186.     mantissa, a sign bit, and an 8-bit exponent biased by 128.
  187.  
  188.   Registers used: Unmodified; DI, SI, DX, CX, & AX are saved and restored.
  189.  
  190.   Segments referenced: The data segment contains the variables, FPTEMP1,
  191.     FPTEMP2, and SFPBUFF.
  192.  
  193.   Routines called: STD_IN, FPINDIGIT, FPMUL, FPTDIV, and FPTNORM.
  194.  
  195.   Note: Equates are used to shorten address fields
  196. -----------------------------------------------------------------------------
  197. Convert an input single decimal digit to temporary floating point
  198. FPINDIGIT
  199.  
  200.   Function: A single decimal digit is placed in temporary binary floating
  201.     point format.
  202.  
  203.   Input: Upon entry, AL contains the value of the digit.
  204.  
  205.   Output: Upon entry and exit, the address of the temporary binary floating
  206.     point result is in DI.
  207.  
  208.   Registers used: AS, CX, and DI are modified.
  209.  
  210.   Segments referenced: Upon entry, the data segment contains storage for the
  211.     temporary binary floating point number.
  212.  
  213.   Note: This is a near procedure needed by FPIN.
  214. -----------------------------------------------------------------------------
  215. Convert from internal to external floating point
  216. FPOUT
  217.  
  218.   Function: This routine displays a single precision floating point number
  219.     on a standard output device as a decimal floating point number.
  220.  
  221.   Input: Upon entry, a single precision binary floating point number is in
  222.     SFPBUFF. The single precision floating point number has a 24-bit binary
  223.     mantissa, a sign bit, and an 8-bit exponent biased by 128.
  224.  
  225.   Output: The individual characters of a decimal floating number are sent out
  226.     through the standard output device. The decimal floating point number has
  227.     a sign character (blank or minus), followed by decimal digits of the
  228.     mantissa with one embedded decimal point to the right of the first
  229.     significant digit. Following the mantissa is an exponent that starts with
  230.     the letter, 'E', then a sign, then a decimal number.
  231.  
  232.   Registers used: AX,CX,BX,DX,SI,& DI are modified.
  233.  
  234.   Segments referenced: The data segment contains storage for the variables,
  235.     DECBUFF, DECSIGN, DECEXP, FPTEMP1, and SFPBUFF.
  236.  
  237.   Routines called: STDOUT, SFP2TFP, DECHALF, DECDOUBLE, DECNORM, & TDECSHOW.
  238.  
  239.   Note: Equates are used to shorten address fields.
  240. -----------------------------------------------------------------------------
  241. Divide temporary floating point by 10
  242. FPTDIV
  243.  
  244.   Function: This routine divides a temp binary floating point number by 10.
  245.  
  246.   Input: Upon entry, DS:DI points to a temporary binary floating point number.
  247.  
  248.   Output: Upon exit, DS:DI points to a temporary binary floating point number.
  249.  
  250.   Registers used: AX, CX, DX, and DI are modified. DI points to input & output.
  251.  
  252.   Segments referenced: The data segment contains a temporary binary floating
  253.     point number.
  254.  
  255.   Note: Equates are used to shorten address fields. This routine is needed
  256.     by FPIN.
  257. -----------------------------------------------------------------------------
  258. Multiply temporary floating point by 10
  259. FPTMUL
  260.  
  261.   Function: This routine multiplies a temporary binary floating point number
  262.      by 10. The result is not normalized.
  263.  
  264.   Input: Upon entry, DS:DI points to a temporary binary floating point number.
  265.  
  266.   Output: Upon exit, DS:DI points to a temporary binary floating point number.
  267.     This number is not normalized.
  268.  
  269.   Registers used: AX, CX, DX, and DI are modified. DI points to input & output.
  270.  
  271.   Segments referenced: The data segment contains a temporary binary floating
  272.     point number.
  273.  
  274.   Note: This near routine is needed by FPIN.
  275. -----------------------------------------------------------------------------
  276. Normalize temporary floating point
  277. FPTNORM
  278.  
  279.   Function: This routine normalizes temporary binary floating point numbers
  280.     that have too large a mantissa.
  281.  
  282.   Input: Upon entry, DS:DI points to a temporary binary floating point number
  283.     whose mantissa is too large.
  284.  
  285.   Output: Upon exit, DS:DI points to a normalized temporary binary floating
  286.     point number.
  287.  
  288.   Registers used: Unmodified; DI must point to the number.
  289.  
  290.   Segments referenced: The data segment must contain the temporary floating
  291.     number.
  292.  
  293.   Note: Equates are used to shorten address fields. This is a near procedure
  294.     needed by FPIN.
  295. -----------------------------------------------------------------------------
  296. Convert from single to double precision floating point
  297. SFP2DFP
  298.  
  299.   Function: This routine converts an internal single precision binary floating
  300.     point number into an internal double precision floating point number.
  301.  
  302.   Input: Upon entry, a single precision floating point number is stored in
  303.     SFPBUFF. The single precision floating point number has a 24-bit binary
  304.     mantissa, a sign bit, and an 8-bit exponent biased by 128.    
  305.  
  306.   Output: Upon exit, a double precision floating point number is stored in
  307.     DFPBUFF. The double precision floating point number has a 40-bit binary
  308.     mantissa, a sign bit, and an 8-bit exponent biased by 128.
  309.  
  310.   Registers used: Unmodified; AX is saved and restored.
  311.  
  312.   Segments referenced: The data segment contains storage for the variables,
  313.      SFPBUFF and DFPBUFF.
  314.  
  315.   Note: Equates are used to shorten address fields.
  316. -----------------------------------------------------------------------------
  317. Convert from single precision to temporary floating point
  318. SFP2TFP
  319.  
  320.   Function: This routine converts a single precision binary floating point
  321.     number into a temporary binary floating point number.
  322.  
  323.   Input: Upon entry, a single precision floating point number is stored in
  324.     SFPBUFF. The single precision floating point number has a 24-bit binary
  325.     mantissa, a sign bit, and an 8-bit exponent biased by 128.    
  326.  
  327.   Output: Upon exit, a temporary binary floating point number is stored in
  328.     FPTEMP1. The temporary binary floating point number has a 72-bit binary
  329.     mantissa with 8 bits to the left of these for internal use, a sign byte,
  330.     and a 16-bit two's complement binary exponent.
  331.  
  332.   Registers used: AX is modified.
  333.  
  334.   Segments referenced: The data segment contains the variables, SFPBUFF and
  335.     FPTEMP1.
  336.  
  337.   Note: Equates are used to shorten address fields. This is a near procedure
  338.     needed by FPOUT.
  339. -----------------------------------------------------------------------------
  340. Convert from ASCII signed decimal to binary
  341. SGNDEC16IN
  342.  
  343.   Function: This routine accepts a signed decimal number from the standard
  344.     input device and converts it to internal signed two's complement
  345.     16-bit binary form.
  346.  
  347.   Input: Individual digits of the signed decimal number are received in
  348.     ASCII through a call to a standard input routine. The sign (+ or -) is
  349.     optional and the valid digits are 0 through 9. An ASCII code other than
  350.     that for the sign and the valid digits will terminate the routine.    
  351.  
  352.   Output: A signed two's complement 16-bit binary number is returned in DX.
  353.  
  354.   Registers used: AX & CX are modified; DX contains the output.
  355.  
  356.   Routines called: STD_IN
  357. -----------------------------------------------------------------------------
  358. Display floating point 
  359. TDECSHOW
  360.  
  361.   Function: This routine displays a floating point number on the standard
  362.     output device.
  363.  
  364.   Input: Upon input, a number is stored in temporary decimal floating point
  365.     form. The temporary format has a string of 25 decimal digits, a sign byte,
  366.     and a base ten exponent that is stored in two's complement 16-bit binary
  367.     format.        
  368.  
  369.   Output: The individual characters of a floating point number are sent out
  370.     the standard output device. The form of the output is: a sign character
  371.     that is blank or minus, followed by decimal digits of the mantissa with
  372.     one embedded decimal point to the right of the first significant digit.
  373.     Following the mantissa is an exponent which starts with the letter E, 
  374.     then a sign, then a decimal number. 
  375.  
  376.   Registers used: AL, CX, DX, & SI are modified.
  377.  
  378.   Segments referenced: The data segment contains the variables, DECBUFF (25
  379.     bytes), DECSIGN (1 byte), and DECEXP (2 bytes).
  380.  
  381.   Routines called: STD_OUT
  382.  
  383.   Note: This is a near procedure needed by FPOUT.
  384.  
  385. -----------------------------------------------------------------------------
  386. Convert from temporary floating point to single precision
  387. TFP2SFP
  388.  
  389.   Function: This routine converts from temporary binary floating point to
  390.     single precision floating point.
  391.  
  392.   Input: Upon entry, a number is stored in temporary binary floating point
  393.     form in FPTEMP1. The temporary binary floating point number has a 72-bit
  394.     binary mantissa with 8 bits to the left of these for internal use, a
  395.     sign byte, and a 16-bit two's complement binary exponent.
  396.  
  397.                       Temporary binary floating point
  398.             _________________________________________________________________
  399.            /    /    /    /    /    /    /    /    /    /    /    /    /    /
  400.   Bytes   /  0 /  1 /  2 /  3 /  4 /  5 /  6 /  7 /  8 /  9 / 10 / 11 / 12 /
  401.          /____/____/____/____/____/____/____/____/____/____/____/____/____/
  402.         |                                                 |    |         |
  403.          \__________________ Mantissa ___________________/  /   \Exponent/
  404.                                                       Sign /    (2's comp)
  405.  
  406.                    Single precision binary floating point
  407.              ________________________
  408.             /     /     /     /     /
  409.            /  0  /  1  /  2  /  3  / 
  410.           /_____/_____/_____/_____/                                                             
  411.           |               ||     |
  412.            \_  Mantissa _// \   /
  413.                     Sign /   \ /
  414.                               \ Exponent biased by 128 
  415.  
  416.   Output: Upon exit, a single precision floating point number is stored in 
  417.     SFPBUFF. The single precision floating point number has a 24-bit binary
  418.     mantissa, a sign bit, and an 8-bit exponent biased by 128.
  419.  
  420.   Registers used: AX and DX are modified.
  421.  
  422.   Segments referenced: Upon entry, the data segment contains the messages:
  423.     INTERNAL, UNDERFLOW, & OVERFLOW, and storage for the temporary binary
  424.     floating point number, FPTEMP1, and the single precision floating point
  425.     number, SFPBUFF.
  426.  
  427.   Routines called: STD_SPACE, EMSG_OUT, & HEX16OUT
  428.  
  429.   Note: Equates are used to shorten fields.  This is a near procedure needed
  430.     by FPIN.
  431. -----------------------------------------------------------------------------
  432. ______________________________________________________________________________
  433. >>>>> Physical EOF FLOATPT.DOC <<<<<
  434.