home *** CD-ROM | disk | FTP | other *** search
-
- *********************** FLOATING-POINT DATA *******************************
-
- ASM32 floating-point data subroutines (C) Copyright 1993 Douglas Herr
- all rights reserved
-
- ASM32 recognizes two floating point formats: IEEE-standard single-
- precision, and IEEE-standard double-precision. Single-precision
- floating point numbers are 4 bytes long, and are referred to as float4
- or simply f4, while double-precision floating point numbers are 8 bytes
- long, which I describe as float8 or f8.
-
-
- ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
-
- CMPF4: compare two float4 values
- Source: cmpf4.asm
-
- CMPF8: compare two float8 values
- Source: cmpf8.asm
-
- 80x87 NOT required
-
- Call with: ESI pointing to value 0
- EDI pointing to value 1
- Returns: if ZF = 1, values are equal
- if SF = 1, value 1 is larger
- Uses: zero flag (ZF), sign flag (SF)
- Example:
-
- extrn cmpf4:near
-
-
- include dataseg.inc
-
- v0 dd 12.345
- v1 dd 17.04
-
- @curseg ends
-
- include codeseg.inc
-
- .
- .
- .
- lea esi,v0 ; point ESI to number 0
- lea edi,v1 ; point EDI to number 1
- call cmpf4 ; compare
- js number1 ; v1 is larger if SF = 1
- je equal ; numbers identical if ZF = 1
- ; otherwise v0 is larger
-
-
- ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
-
- F4TOI2: copies the integer portion of a float4 number to AX
- Source: f4toi2.asm
-
- 80x87 not required
-
- Note: only the integer portion of the number is converted; decimals
- are truncated
- Call with: ESI pointing to a float4 number
- Returns: if CF = 0, AX = integer number
- if CF = 1, float4 number is too large (if positive)
- or is too small (if negtive)
- Uses: AX, CF; all other flags and registers are saved
- Example:
-
-
- extrn f4toi2:near
-
- include dataseg.inc
-
- float4 dd 1234.567
-
- @curseg ends
-
- include codeseg.inc
-
- .
- .
- .
- lea esi,float4
- call f4toi2
- jc oops ; gotta fix something if error
-
-
-
- ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
-
- F4TOI4: copies the long integer portion of a float4 number to EAX
- Source: f4toi4.asm
-
- 80x87 not required
-
- Note: only the integer portion of the number is converted; decimals
- are truncated
- Call with: ESI pointing to a float4 number
- Returns: if CF = 0, EAX = long integer number
- if CF = 1, float4 number is too large (if positive)
- or is too small (if negtive)
- Uses: EAX, CF; all other flags and registers are saved
- Example:
-
- extrn f4toi4:near
-
- include dataseg.inc
-
- float4 dd 1234.567
-
- @curseg ends
-
- include codeseg.inc
- .
- .
- .
- lea esi,float4
- call f4toi4
- jc oops ; gotta fix something if error
-
-
-
-
- ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
-
- MAXF4, MAXF4b: find maximum value in single-precision real-number array
- Source: maxf4.asm
-
- MINF4, MINF4b: find minimum value in single-precision real-number array
- Source: minf4.asm
-
- 80x87 not required
-
- Call with: EDI pointing to array element at start of search
- ECX = number of array elements to search
- For maxf4b or minf4b, call with EBX = byte increment between
- array elements. Maxf4 and minf4 assume byte increment = 4.
- Returns: EAX = array element number with maximum or minimum value
- note that the offset of that value is EDI + (EAX shl 2).
- With maxf4b and minf4b, the offset of the value is
- EDI + (EAX * EBX). CF = 1 if called with ECX = 0.
- Uses: EAX, CF
- Example:
-
- extrn maxf4:near
-
- include dataseg.inc
-
- floatdata dd 1500 dup(0)
-
- @curseg ends
-
- include codeseg.inc
-
- ; program provides values for the array
- .
- .
- .
- lea edi,floatdata ; EDI points to the data array
- mov ecx,1500 ; search entire array
- call maxf4 ; returns with EAX = array element
-
-
-
- ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
-
- MAXF8, MAXF8b: find maximum value in double-precision real-number array
- Source: maxf8.asm
-
- MINF8, MINF8b: find minimum value in double-precision real-number array
- Source: minf8.asm
-
- 80x87 not required
-
- Call with: EDI pointing to array element at start of search
- ECX = number of array elements to search
- For maxf8b or minf8b, call with EBX = byte increment between
- array elements. Maxf8 and minf8 assume byte increment = 8.
- Returns: EAX = array element number with maximum or minimum value
- note that the offset of that value is EDI + (EAX shl 3)
- With maxf8b and minf8b, the offset of the value is
- EDI + (EAX * EBX). CF = 1 if called with ECX = 0.
- Uses: EAX, CF
- Example:
-
- extrn maxf8:near
-
- include dataseg.inc
-
- floatdata dq 1500 dup(0)
-
- @curseg ends
-
- include codeseg.inc
-
- ; program provides values for the array
- .
- .
- .
- lea edi,floatdata ; EDI points to the data array
- mov ecx,1500 ; search entire array
- call maxf8 ; returns with EAX = array element
- shl eax,3
- add edi,eax ; EDI points to maximum value
-
-
-
- ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
-
- SORTF4HI: sort an array of single-precision real numbers, highest first
- Source: sortf4hi.asm
-
- SORTF4LO: sort an array of single-precision real numbers, lowest first
- Source: sortf4lo.asm
-
- 80x87 not required
-
- Call with: EDI pointing to the first of the array elements to be
- sorted, ECX = number of array elements
- Returns: nothing
- Uses: nothing; all registers and flags are saved
- Example:
-
- extrn sortf4hi:near
-
- include dataseg.inc
-
- floatdata dd 1500 dup(0)
-
- @curseg ends
-
- include codeseg.inc
-
- ; program provides values for the array
- .
- .
- lea edi,floatdata
- mov ecx,1500 ; sort entire array
- call sortf4hi ; highest value first
-
-
-