home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / opendc12.zip / od124os2.exe / od12osr1.exe / src / IODMathA.asm < prev    next >
Assembly Source File  |  1997-03-21  |  6KB  |  221 lines

  1. ; @(#) 1.10 os2/src/utils/IODMathA.asm, odutils, od96os2, odos29712d 10/31/96 10:18:00 [3/21/97 17:37:43]
  2. ;====START_GENERATED_PROLOG======================================
  3. ;
  4. ;
  5. ;   COMPONENT_NAME: odutils
  6. ;
  7. ;   CLASSES: none
  8. ;
  9. ;   ORIGINS: 82,27
  10. ;
  11. ;
  12. ;   (C) COPYRIGHT International Business Machines Corp. 1995,1996
  13. ;   All Rights Reserved
  14. ;   Licensed Materials - Property of IBM
  15. ;   US Government Users Restricted Rights - Use, duplication or
  16. ;   disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  17. ;       
  18. ;   IBM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  19. ;   ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  20. ;   PURPOSE. IN NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  21. ;   CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
  22. ;   USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
  23. ;   OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE
  24. ;   OR PERFORMANCE OF THIS SOFTWARE.
  25. ;
  26. ;====END_GENERATED_PROLOG========================================
  27. ;
  28.  
  29. ;*******************************************************************
  30. ;*
  31. ;* Copyright (C) Apple Computer, Inc., 1994
  32. ;*
  33. ;*******************************************************************
  34.         TITLE   ODMATHA.ASM
  35.         .486
  36.         .model FLAT
  37.  
  38.         .code
  39.  
  40. ODWide STRUC
  41. highdd DD      ?   ; high double word
  42. lowdd  DD      ?   ; low  double word
  43. ODWide ENDS
  44.  
  45. ;******** From ODMath.h *************
  46. kODFixedInfinity       equ 07FFFFFFFh     ; ced [117913]
  47. kODFixedMinusInfinity  equ 080000000h     ; ced [117913]
  48. kODIgnoreRemainder     equ 0FFFFFFFFh     ; ced [117913]
  49.  
  50.  
  51. USE_SYSTEM_CALLING_CONVENTION equ 0
  52.  
  53. IF USE_SYSTEM_CALLING_CONVENTION
  54. arg1  EQU  <[ESP+4]>
  55. arg2  EQU  <[ESP+8]>
  56. arg3  EQU  <[ESP+12]>
  57. ENDIF
  58.  
  59. ;*********************************************************************
  60. ;
  61. ;  ODWideMultiply -
  62. ;
  63. ;  C language prototype
  64. ;     ODWide*  ODWideMultiply( ODSLong a, ODSLong b, ODWide *result )
  65. ;
  66. ;  Multiplies a and b and places product in result.
  67. ;  Returns result ponter
  68. ;
  69. ;  Input parameters using C/Set++ Optlink calling convention:
  70. ;     EAX = a
  71. ;     EDX = b
  72. ;     ECX = result pointer
  73. ;
  74. ;  On return:
  75. ;     EAX = result pointer
  76. ;
  77. ;*********************************************************************
  78.         ALIGN 04H
  79. IFDEF _PLATFORM_WIN32_
  80.         PUBLIC ?ODWideMultiply
  81. ?ODWideMultiply  PROC
  82. ELSE
  83.         PUBLIC ODWideMultiply
  84. ODWideMultiply  PROC
  85. ENDIF
  86.  
  87. IF USE_SYSTEM_CALLING_CONVENTION
  88.    MOV   EAX,arg1
  89.    MOV   EDX,arg2
  90.    MOV   ECX,arg3
  91. ENDIF
  92.    IMUL  EDX
  93.    MOV   (ODWide PTR [ECX]).lowdd,EAX
  94.    MOV   (ODWide PTR [ECX]).highdd,EDX
  95.    MOV   EAX,ECX
  96.    RET
  97. IFDEF _PLATFORM_WIN32_
  98. ?ODWideMultiply  ENDP
  99. ELSE
  100. ODWideMultiply  ENDP
  101. ENDIF
  102.  
  103. ;*********************************************************************
  104. ;
  105. ;  ODWideDivide -
  106. ;
  107. ;  C language prototype
  108. ;     ODSLong  ODWideDivide( const ODWide *dividend,
  109. ;                               ODSLong divisor, ODSLong *remainder)
  110. ;
  111. ;  Divides dividend by divisor and returns quotient and places
  112. ;  remainder in 'remainder'.
  113. ;
  114. ;  Returns quotient
  115. ;
  116. ;  Input parameters using C/Set++ Optlink calling convention:
  117. ;     EAX = dividend pointer
  118. ;     EDX = divisor
  119. ;     ECX = remainder pointer
  120. ;
  121. ;  On return:
  122. ;     EAX = quotient
  123. ;
  124. ;*********************************************************************
  125.         ALIGN 04H
  126. IFDEF _PLATFORM_WIN32_
  127.         PUBLIC ?ODWideDivide
  128. ?ODWideDivide    PROC
  129. ELSE
  130.         PUBLIC ODWideDivide
  131. ODWideDivide    PROC
  132. ENDIF
  133.  
  134. IF USE_SYSTEM_CALLING_CONVENTION
  135.    MOV   EAX,arg1
  136.    MOV   EDX,arg2
  137.    MOV   ECX,arg3
  138. ENDIF
  139.    ; If performing the signed division would result in a divide by
  140.    ; zero exception, we want to detect that and return
  141.    ; kODMinusInfinity instead.  A divide by zero exception for
  142.    ; signed division will result if the absolute value of the dividend
  143.    ; divided by 2*31 is greater than the absolute value of the divisor.
  144.  
  145. ;  [120333] start  - ced
  146.    PUSH  EAX                 ; save gp registers
  147.    PUSH  EBX
  148.    PUSH  EDX
  149.  
  150.    MOV   EBX,(ODWide PTR [EAX]).lowdd     ;Get abs value of dividend in EAX:EBX
  151.    MOV   EAX,(ODWide PTR [EAX]).highdd
  152. ;  .if   <EAX lt 0>
  153.    TEST  EAX,EAX
  154.     JGE   label1
  155.       CLC
  156.       NOT   EBX
  157.       NOT   EAX
  158.       ADD   EBX,1
  159.       ADC   EAX,0
  160. ;  .endif
  161. label1:
  162. ;  .if   <EDX lt 0>          ;Get abs value of divisor in EDX
  163.     CMP   EDX,0
  164.     JGE   label2
  165.       NEG  EDX
  166. ;  .endif
  167. label2:
  168.    ; Test EAX msb.  If set then dividend was largest neg number in which
  169.    ; case an exception would result no matter what value the divisor is.
  170.    SAL   EAX,1
  171. ;  .if   <nc>                ;greatest neg number is special case
  172.     JC    label3
  173.       SHR   EAX,1            ;Restore EAX
  174.       SHRD  EBX,EAX,31       ;Divide dividend by 2**31
  175.       CMP   EDX,EBX          ;Divisor must be gt dividend / (2**31)
  176. ;  .endif
  177. label3:
  178.    POP   EDX
  179.    POP   EBX
  180.    POP   EAX
  181.  
  182.    ; Check result of comparison.  Remember, we're using unsigned numbers
  183.    ; so the carry flag is used to indicate that the source operand is
  184.    ; greater than the destination operand rather than the sign flag.
  185.  
  186. ;  .if   <c> or
  187. ;  .if   <eq>
  188.    JA    label4
  189.       MOV  EAX,kODFixedMinusInfinity
  190.       RET
  191. ;  .endif
  192. label4:
  193. ;  [120333] end  - ced
  194.  
  195.    ; Looks like we're OK.  Go ahead and do the division now.
  196.  
  197.    PUSH  ECX
  198.    MOV   ECX,EDX
  199.    MOV   EDX,(ODWide PTR [EAX]).highdd
  200.    MOV   EAX,(ODWide PTR [EAX]).lowdd
  201.    IDIV  ECX
  202.    POP   ECX
  203. ;  .if   <ecx ne kODIgnoreRemainder> and   ; ced [117913]
  204.    CMP   ECX,kODIgnoreRemainder
  205.     JE    return
  206. ;  .if   <ecx ne 0>                        ; ced [117913]
  207.    TEST  ECX,ECX
  208.     JZ    return
  209.       MOV   [ECX],EDX                      ; ced [117913]
  210. ;  .endif
  211. return:
  212.    RET
  213. IFDEF _PLATFORM_WIN32_
  214. ?ODWideDivide   ENDP
  215. ELSE
  216. ODWideDivide   ENDP
  217. ENDIF
  218.  
  219. END
  220.  
  221.