home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power Programming
/
powerprogramming1994.iso
/
progtool
/
asmutl
/
bluebook.arc
/
FLOATPT.DOC
< prev
next >
Wrap
Text File
|
1986-05-14
|
19KB
|
434 lines
FLOATPT.DOC -- Floating Point Conversion Procedures
===================================================
From `BLUEBOOK of ASSEMBLY ROUTINES for the IBM PC & XT'
by Christopher L. Morgan
Copyright (C) 1984 by The Waite Group, Inc.
Purpose: These procedures perform input, conversion, and output on
floating point numbers.
Contents:
---------
BIN802DEC -- Convert from 80-bit binary to decimal digits
DECDOUBLE -- Double a temporary decimal floating point number
DECHALF -- Halve a temporary decimal floating point number
DECNORM -- Normalize temporary decimal floating point
DFP2SFP -- Convert from double to single precision floating point
FIX -- Convert from floating point to 16-bit integer
FLOAT -- Convert from 16-bit integer to floating point
FPIN -- Convert from external to internal floating point
FPINDIGIT -- Convert from decimal digit to temporary floating point
FPOUT -- Convert from internal to external floating point
FPTDIV -- Divide temporary floating point by 10
FPTMUL -- Multiply temporary floating point by 10
FPTNORM -- Normalize temporary floating point
SFP2DFP -- Convert from single to double precision floating point
SFP2TFP -- Convert from single precision to temporary floating point
SGNDEC16IN -- Convert from ASCII signed decimal to binary
TDECSHOW -- Display floating point
TFP2SFP -- Convert from temporary floating point to single precision
_____________________________________________________________________________
Overview
__________________________ FLOATING POINT ROUTINES __________________________
-----------------------------------------------------------------------------
Conversion from 80-bit binary to decimal digits
BIN802DEC
Function: This routine converts an 80-bit binary integer to a decimal string.
Input: Upon entry, SI points to an 80-bit binary integer to be used as input
and DI points to a 25-digit decimal string to be used as output.
Output: Upon exit, a 25-digit decimal string is where DI pointed upon entry.
DI still points there upon exit.
Registers used: AX, BX, CX, DX, and SI are modified; DI points to output.
Segments referenced: The data segment contains storage for the 80-bit binary
number (10 bytes) and the 25-digit decimal number (25 bytes).
Note: This is a near procedure needed by FPOUT.
-----------------------------------------------------------------------------
Double a temporary decimal floating point number
DECDOUBLE
Function: This routine multiplies a temporary decimal floating point
number by two.
Input: Upon entry, DS:DI points to a temporary decimal floating point number.
Output: Upon exit, the number has been doubled.
Registers used: AX,CX, & DX are modified.
Segments referenced: The data segment contains storage for the temporary
decimal floating point number.
Note: This is a near procedure needed by FPOUT.
-----------------------------------------------------------------------------
Half a temporary decimal floating point number
DECHALF
Function: This routine divides a temporary decimal floating number by two.
Input: Upon entry, DI points to a temporary decimal floating point number.
Output: Upon exit, the number has been divided by two. The result is not
normalized.
Registers used: AX, CX, and DI are modified.
Segments referenced: The data segment contains a temporary decimal floating
point number.
Note: This is a near procedure needed by FPOUT.
-----------------------------------------------------------------------------
Normalize a temporary decimal floating point number
DECNORM
Function: This routine normalizes a temporary decimal floating number.
Input: Upon entry, DI points to a temporary decimal floating point number.
Output: Upon exit, the number is normalized.
Registers used: AX, CX, and DI are modified.
Segments referenced: The data segment contains a temporary decimal floating
point number.
Note: Equates are used to shorten address fields. This is a near procedure
needed by FPOUT.
-----------------------------------------------------------------------------
Convert from double to single precision floating point
DFP2SFP
Function: This routine converts an internal double precision binary floating
point number to an internal single precision floating point number.
Input: Upon entry, a double precision binary floating point number is in
DFPBUFF. The double precision floating point number has a 40-bit binary
mantissa, a sign bit, and an 8-bit exponent biased by 128.
Output: Upon exit, a single precision binary floating point number is in
SFPBUFF. The single precision floating point number has a 24-bit binary
mantissa, a sign bit, and an 8-bit exponent biased by 128.
Registers used: Unmodified; AX is saved and restored.
Segments referenced: The data segment contains storage for the variables,
SFPBUFF and DFPBUFF.
Note: Equates are used to shorten address fields.
-----------------------------------------------------------------------------
Convert from floating point to 16-bit integer
FIX
Function: This routine converts from internal single precision binary
floating point to internal 16-bit signed two's complement integer.
Input: Upon entry, a single precision binary floating point is in SFPBUFF.
The single precision floating point number has a 24-bit binary mantissa,
a sign bit, and an 8-bit exponent biased by 128.
Output: Upon exit, a 16-bit signed two's complement binary number is in DX.
Registers used: DX is used for output; CX,and AX are saved and then restored.
Segments referenced: The data segment contains storage for SFPBUFF.
Note: Equates are used to shorten address fields.
-----------------------------------------------------------------------------
Convert from 16-bit integer to floating point
FLOAT
Function: This routine converts an unsigned 16-bit binary number to a
single precision binary floating point number.
Input: Upon entry, DX contains an unsigned 16-bit binary number.
Output: Upon exit, SFPBUFF contains a single precision floating point
number. The single precision floating point number has a 24-bit binary
mantissa, a sign bit, and an 8-bit exponent biased by 128.
Registers used: Unmodified; DX is used for input; DX, CX, & AX are saved
and then restored.
Segments referenced: The data segment contains storage for the variable,
SFPBUFF and the message, INTERNAL.
Routines called: STDMSG_OUT,HEX16OUT,STD_SPACE (all for debugging).
Note: Equates are used to shorten address fields.
-----------------------------------------------------------------------------
Convert from external to internal floating point
FPIN
Function: This routine accepts an ASCII decimal floating point number from
a standard input device and converts it to internal binary floating point.
Input: The characters of the floating point number are received in ASCII
through a call to a standard input routine. The decimal floating point
number has an optional sign, followed by decimal digits of the mantissa
with one embedded decimal point. Following the mantissa is an optional
exponent starting with the letter, 'E', then an optional sign, then a
decimal number. It is possible to get erroneous results if the number is
too large or small to be stored as a single precision binary floating
point number.
Output: Upon exit a single precision binary floating point number is in
SFPBUFF. The single precision floating point number has a 24-bit binary
mantissa, a sign bit, and an 8-bit exponent biased by 128.
Registers used: Unmodified; DI, SI, DX, CX, & AX are saved and restored.
Segments referenced: The data segment contains the variables, FPTEMP1,
FPTEMP2, and SFPBUFF.
Routines called: STD_IN, FPINDIGIT, FPMUL, FPTDIV, and FPTNORM.
Note: Equates are used to shorten address fields
-----------------------------------------------------------------------------
Convert an input single decimal digit to temporary floating point
FPINDIGIT
Function: A single decimal digit is placed in temporary binary floating
point format.
Input: Upon entry, AL contains the value of the digit.
Output: Upon entry and exit, the address of the temporary binary floating
point result is in DI.
Registers used: AS, CX, and DI are modified.
Segments referenced: Upon entry, the data segment contains storage for the
temporary binary floating point number.
Note: This is a near procedure needed by FPIN.
-----------------------------------------------------------------------------
Convert from internal to external floating point
FPOUT
Function: This routine displays a single precision floating point number
on a standard output device as a decimal floating point number.
Input: Upon entry, a single precision binary floating point number is in
SFPBUFF. The single precision floating point number has a 24-bit binary
mantissa, a sign bit, and an 8-bit exponent biased by 128.
Output: The individual characters of a decimal floating number are sent out
through the standard output device. The decimal floating point number has
a sign character (blank or minus), followed by decimal digits of the
mantissa with one embedded decimal point to the right of the first
significant digit. Following the mantissa is an exponent that starts with
the letter, 'E', then a sign, then a decimal number.
Registers used: AX,CX,BX,DX,SI,& DI are modified.
Segments referenced: The data segment contains storage for the variables,
DECBUFF, DECSIGN, DECEXP, FPTEMP1, and SFPBUFF.
Routines called: STDOUT, SFP2TFP, DECHALF, DECDOUBLE, DECNORM, & TDECSHOW.
Note: Equates are used to shorten address fields.
-----------------------------------------------------------------------------
Divide temporary floating point by 10
FPTDIV
Function: This routine divides a temp binary floating point number by 10.
Input: Upon entry, DS:DI points to a temporary binary floating point number.
Output: Upon exit, DS:DI points to a temporary binary floating point number.
Registers used: AX, CX, DX, and DI are modified. DI points to input & output.
Segments referenced: The data segment contains a temporary binary floating
point number.
Note: Equates are used to shorten address fields. This routine is needed
by FPIN.
-----------------------------------------------------------------------------
Multiply temporary floating point by 10
FPTMUL
Function: This routine multiplies a temporary binary floating point number
by 10. The result is not normalized.
Input: Upon entry, DS:DI points to a temporary binary floating point number.
Output: Upon exit, DS:DI points to a temporary binary floating point number.
This number is not normalized.
Registers used: AX, CX, DX, and DI are modified. DI points to input & output.
Segments referenced: The data segment contains a temporary binary floating
point number.
Note: This near routine is needed by FPIN.
-----------------------------------------------------------------------------
Normalize temporary floating point
FPTNORM
Function: This routine normalizes temporary binary floating point numbers
that have too large a mantissa.
Input: Upon entry, DS:DI points to a temporary binary floating point number
whose mantissa is too large.
Output: Upon exit, DS:DI points to a normalized temporary binary floating
point number.
Registers used: Unmodified; DI must point to the number.
Segments referenced: The data segment must contain the temporary floating
number.
Note: Equates are used to shorten address fields. This is a near procedure
needed by FPIN.
-----------------------------------------------------------------------------
Convert from single to double precision floating point
SFP2DFP
Function: This routine converts an internal single precision binary floating
point number into an internal double precision floating point number.
Input: Upon entry, a single precision floating point number is stored in
SFPBUFF. The single precision floating point number has a 24-bit binary
mantissa, a sign bit, and an 8-bit exponent biased by 128.
Output: Upon exit, a double precision floating point number is stored in
DFPBUFF. The double precision floating point number has a 40-bit binary
mantissa, a sign bit, and an 8-bit exponent biased by 128.
Registers used: Unmodified; AX is saved and restored.
Segments referenced: The data segment contains storage for the variables,
SFPBUFF and DFPBUFF.
Note: Equates are used to shorten address fields.
-----------------------------------------------------------------------------
Convert from single precision to temporary floating point
SFP2TFP
Function: This routine converts a single precision binary floating point
number into a temporary binary floating point number.
Input: Upon entry, a single precision floating point number is stored in
SFPBUFF. The single precision floating point number has a 24-bit binary
mantissa, a sign bit, and an 8-bit exponent biased by 128.
Output: Upon exit, a temporary binary floating point number is stored in
FPTEMP1. The temporary binary floating point number has a 72-bit binary
mantissa with 8 bits to the left of these for internal use, a sign byte,
and a 16-bit two's complement binary exponent.
Registers used: AX is modified.
Segments referenced: The data segment contains the variables, SFPBUFF and
FPTEMP1.
Note: Equates are used to shorten address fields. This is a near procedure
needed by FPOUT.
-----------------------------------------------------------------------------
Convert from ASCII signed decimal to binary
SGNDEC16IN
Function: This routine accepts a signed decimal number from the standard
input device and converts it to internal signed two's complement
16-bit binary form.
Input: Individual digits of the signed decimal number are received in
ASCII through a call to a standard input routine. The sign (+ or -) is
optional and the valid digits are 0 through 9. An ASCII code other than
that for the sign and the valid digits will terminate the routine.
Output: A signed two's complement 16-bit binary number is returned in DX.
Registers used: AX & CX are modified; DX contains the output.
Routines called: STD_IN
-----------------------------------------------------------------------------
Display floating point
TDECSHOW
Function: This routine displays a floating point number on the standard
output device.
Input: Upon input, a number is stored in temporary decimal floating point
form. The temporary format has a string of 25 decimal digits, a sign byte,
and a base ten exponent that is stored in two's complement 16-bit binary
format.
Output: The individual characters of a floating point number are sent out
the standard output device. The form of the output is: a sign character
that is blank or minus, followed by decimal digits of the mantissa with
one embedded decimal point to the right of the first significant digit.
Following the mantissa is an exponent which starts with the letter E,
then a sign, then a decimal number.
Registers used: AL, CX, DX, & SI are modified.
Segments referenced: The data segment contains the variables, DECBUFF (25
bytes), DECSIGN (1 byte), and DECEXP (2 bytes).
Routines called: STD_OUT
Note: This is a near procedure needed by FPOUT.
-----------------------------------------------------------------------------
Convert from temporary floating point to single precision
TFP2SFP
Function: This routine converts from temporary binary floating point to
single precision floating point.
Input: Upon entry, a number is stored in temporary binary floating point
form in FPTEMP1. The temporary binary floating point number has a 72-bit
binary mantissa with 8 bits to the left of these for internal use, a
sign byte, and a 16-bit two's complement binary exponent.
Temporary binary floating point
_________________________________________________________________
/ / / / / / / / / / / / / /
Bytes / 0 / 1 / 2 / 3 / 4 / 5 / 6 / 7 / 8 / 9 / 10 / 11 / 12 /
/____/____/____/____/____/____/____/____/____/____/____/____/____/
| | | |
\__________________ Mantissa ___________________/ / \Exponent/
Sign / (2's comp)
Single precision binary floating point
________________________
/ / / / /
/ 0 / 1 / 2 / 3 /
/_____/_____/_____/_____/
| || |
\_ Mantissa _// \ /
Sign / \ /
\ Exponent biased by 128
Output: Upon exit, a single precision floating point number is stored in
SFPBUFF. The single precision floating point number has a 24-bit binary
mantissa, a sign bit, and an 8-bit exponent biased by 128.
Registers used: AX and DX are modified.
Segments referenced: Upon entry, the data segment contains the messages:
INTERNAL, UNDERFLOW, & OVERFLOW, and storage for the temporary binary
floating point number, FPTEMP1, and the single precision floating point
number, SFPBUFF.
Routines called: STD_SPACE, EMSG_OUT, & HEX16OUT
Note: Equates are used to shorten fields. This is a near procedure needed
by FPIN.
-----------------------------------------------------------------------------
______________________________________________________________________________
>>>>> Physical EOF FLOATPT.DOC <<<<<