home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / assemblr / library / asm32 / float.doc < prev    next >
Text File  |  1993-12-07  |  7KB  |  243 lines

  1.  
  2. ***********************  FLOATING-POINT DATA  *******************************
  3.  
  4. ASM32 floating-point data subroutines (C) Copyright 1993 Douglas Herr
  5. all rights reserved
  6.  
  7. ASM32 recognizes two floating point formats: IEEE-standard single-
  8. precision, and IEEE-standard double-precision.  Single-precision
  9. floating point numbers are 4 bytes long, and are referred to as float4
  10. or simply f4, while double-precision floating point numbers are 8 bytes
  11. long, which I describe as float8 or f8.
  12.  
  13.  
  14. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  15.  
  16. CMPF4:      compare two float4 values
  17. Source:     cmpf4.asm
  18.  
  19. CMPF8:      compare two float8 values
  20. Source:     cmpf8.asm
  21.  
  22. 80x87 NOT required
  23.  
  24. Call with:  ESI pointing to value 0
  25.             EDI pointing to value 1
  26. Returns:    if ZF = 1, values are equal
  27.             if SF = 1, value 1 is larger
  28. Uses:       zero flag (ZF), sign flag (SF)
  29. Example:
  30.  
  31. extrn   cmpf4:near
  32.  
  33.  
  34. include dataseg.inc
  35.  
  36. v0      dd 12.345
  37. v1      dd 17.04
  38.  
  39. @curseg ends
  40.  
  41. include codeseg.inc
  42.  
  43.          .
  44.          .
  45.          .
  46.         lea    esi,v0            ; point ESI to number 0
  47.         lea    edi,v1            ; point EDI to number 1
  48.         call   cmpf4             ; compare
  49.         js     number1           ; v1 is larger if SF = 1
  50.         je     equal             ; numbers identical if ZF = 1
  51.                                   ; otherwise v0 is larger
  52.  
  53.  
  54. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  55.  
  56. F4TOI2:     copies the integer portion of a float4 number to AX
  57. Source:     f4toi2.asm
  58.  
  59. 80x87 not required
  60.  
  61. Note:       only the integer portion of the number is converted; decimals
  62.             are truncated
  63. Call with:  ESI pointing to a float4 number
  64. Returns:    if CF = 0, AX = integer number
  65.             if CF = 1, float4 number is too large (if positive)
  66.                        or is too small (if negtive)
  67. Uses:       AX, CF; all other flags and registers are saved
  68. Example:
  69.  
  70.  
  71. extrn   f4toi2:near
  72.  
  73. include dataseg.inc
  74.  
  75. float4  dd  1234.567
  76.  
  77. @curseg ends
  78.  
  79. include codeseg.inc
  80.  
  81.         .
  82.         .
  83.         .
  84.         lea  esi,float4
  85.         call f4toi2
  86.         jc   oops                     ; gotta fix something if error
  87.  
  88.  
  89.  
  90. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  91.  
  92. F4TOI4:     copies the long integer portion of a float4 number to EAX
  93. Source:     f4toi4.asm
  94.  
  95. 80x87 not required
  96.  
  97. Note:       only the integer portion of the number is converted; decimals
  98.             are truncated
  99. Call with:  ESI pointing to a float4 number
  100. Returns:    if CF = 0, EAX = long integer number
  101.             if CF = 1, float4 number is too large (if positive)
  102.                        or is too small (if negtive)
  103. Uses:       EAX, CF; all other flags and registers are saved
  104. Example:
  105.  
  106. extrn   f4toi4:near
  107.  
  108. include dataseg.inc
  109.  
  110. float4  dd  1234.567
  111.  
  112. @curseg ends
  113.  
  114. include codeseg.inc
  115.         .
  116.         .
  117.         .
  118.         lea    esi,float4
  119.         call   f4toi4
  120.         jc     oops                   ; gotta fix something if error
  121.  
  122.  
  123.  
  124.  
  125. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  126.  
  127. MAXF4, MAXF4b: find maximum value in single-precision real-number array
  128. Source:        maxf4.asm
  129.  
  130. MINF4, MINF4b: find minimum value in single-precision real-number array
  131. Source:        minf4.asm
  132.  
  133. 80x87 not required
  134.  
  135. Call with:  EDI pointing to array element at start of search
  136.             ECX = number of array elements to search
  137.             For maxf4b or minf4b, call with EBX = byte increment between
  138.             array elements.  Maxf4 and minf4 assume byte increment = 4.
  139. Returns:    EAX = array element number with maximum or minimum value
  140.             note that the offset of that value is EDI + (EAX shl 2).
  141.             With maxf4b and minf4b, the offset of the value is
  142.             EDI + (EAX * EBX).  CF = 1 if called with ECX = 0.
  143. Uses:       EAX, CF
  144. Example:
  145.  
  146. extrn  maxf4:near
  147.  
  148. include dataseg.inc
  149.  
  150. floatdata   dd 1500 dup(0)
  151.  
  152. @curseg ends
  153.  
  154. include codeseg.inc
  155.  
  156. ; program provides values for the array
  157.        .
  158.        .
  159.        .
  160.        lea    edi,floatdata      ; EDI points to the data array
  161.        mov    ecx,1500           ; search entire array
  162.        call   maxf4              ; returns with EAX = array element
  163.  
  164.  
  165.  
  166. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  167.  
  168. MAXF8, MAXF8b: find maximum value in double-precision real-number array
  169. Source:        maxf8.asm
  170.  
  171. MINF8, MINF8b: find minimum value in double-precision real-number array
  172. Source:        minf8.asm
  173.  
  174. 80x87 not required
  175.  
  176. Call with:  EDI pointing to array element at start of search
  177.             ECX = number of array elements to search
  178.             For maxf8b or minf8b, call with EBX = byte increment between
  179.             array elements.  Maxf8 and minf8 assume byte increment = 8.
  180. Returns:    EAX = array element number with maximum or minimum value
  181.             note that the offset of that value is EDI + (EAX shl 3)
  182.             With maxf8b and minf8b, the offset of the value is
  183.             EDI + (EAX * EBX).  CF = 1 if called with ECX = 0.
  184. Uses:       EAX, CF
  185. Example:
  186.  
  187. extrn  maxf8:near
  188.  
  189. include dataseg.inc
  190.  
  191. floatdata   dq 1500 dup(0)
  192.  
  193. @curseg ends
  194.  
  195. include codeseg.inc
  196.  
  197. ; program provides values for the array
  198.        .
  199.        .
  200.        .
  201.        lea    edi,floatdata      ; EDI points to the data array
  202.        mov    ecx,1500           ; search entire array
  203.        call   maxf8              ; returns with EAX = array element
  204.        shl    eax,3
  205.        add    edi,eax            ; EDI points to maximum value
  206.  
  207.  
  208.  
  209. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  210.  
  211. SORTF4HI:    sort an array of single-precision real numbers, highest first
  212. Source:      sortf4hi.asm
  213.  
  214. SORTF4LO:    sort an array of single-precision real numbers, lowest first
  215. Source:      sortf4lo.asm
  216.  
  217. 80x87 not required
  218.  
  219. Call with:  EDI pointing to the first of the array elements to be
  220.             sorted, ECX = number of array elements
  221. Returns:    nothing
  222. Uses:       nothing; all registers and flags are saved
  223. Example:
  224.  
  225. extrn   sortf4hi:near
  226.  
  227. include dataseg.inc
  228.  
  229. floatdata   dd 1500 dup(0)
  230.  
  231. @curseg    ends
  232.  
  233. include codeseg.inc
  234.  
  235. ; program provides values for the array
  236.         .
  237.         .
  238.         lea     edi,floatdata
  239.         mov     ecx,1500           ; sort entire array
  240.         call    sortf4hi           ; highest value first
  241.  
  242.  
  243.