Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | Download | RSS feed

  1. ;*****************************************************************************
  2. ;*
  3. ;*                            Open Watcom Project
  4. ;*
  5. ;*    Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
  6. ;*
  7. ;*  ========================================================================
  8. ;*
  9. ;*    This file contains Original Code and/or Modifications of Original
  10. ;*    Code as defined in and that are subject to the Sybase Open Watcom
  11. ;*    Public License version 1.0 (the 'License'). You may not use this file
  12. ;*    except in compliance with the License. BY USING THIS FILE YOU AGREE TO
  13. ;*    ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
  14. ;*    provided with the Original Code and Modifications, and is also
  15. ;*    available at www.sybase.com/developer/opensource.
  16. ;*
  17. ;*    The Original Code and all software distributed under the License are
  18. ;*    distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
  19. ;*    EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
  20. ;*    ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
  21. ;*    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
  22. ;*    NON-INFRINGEMENT. Please see the License for the specific language
  23. ;*    governing rights and limitations under the License.
  24. ;*
  25. ;*  ========================================================================
  26. ;*
  27. ;* Description:  WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
  28. ;*               DESCRIBE IT HERE!
  29. ;*
  30. ;*****************************************************************************
  31.  
  32.  
  33. include mdef.inc
  34. include struct.inc
  35.  
  36. .8087
  37.         modstart        _7fu8386
  38.  
  39.         xdefp   __FSU87
  40.         xdefp   __FDU87
  41.  
  42. defpe __FSU87
  43.         sub     esp,12
  44.         mov     [esp],eax
  45.         fld     dword ptr [esp]
  46.         jmp     short convert
  47.  
  48. defpe __FDU87
  49.         sub     esp,12
  50.         mov     [esp],eax
  51.         mov     4[esp],edx
  52.         fld     qword ptr [esp]
  53.  
  54.         ; fall through
  55.  
  56. convert:
  57.         push    ecx
  58.         fstp    tbyte ptr 4[esp]        ; get number out in memory
  59.         mov     ax,12[esp]              ; pick up sign/exponent
  60.         and     ax,7fffh                ; isolate exponent
  61.         sub     ax,16383                ; remove bias
  62.         jl      ret_zero                ; if less than .5, return zero
  63.         cmp     ax,64                   ; are we too big?
  64.         jae     ret_inf                 ; if so, return infinity
  65.         mov     cl,63                   ; calculate shift count
  66.         sub     cl,al                   ; ...
  67.         mov     eax,4[esp]              ; pick up mantissa
  68.         mov     edx,8[esp]              ; ...
  69.         je      negate                  ; skip out if no shifting
  70. L2:
  71.         shr     edx,1                   ; shift down one bit
  72.         rcr     eax,1                   ; ...
  73.         dec     cl                      ; are we done?
  74.         jne     L2                      ; do it again if not
  75. negate:
  76.         test    byte ptr 13[esp],80h    ; is number negative?
  77.         jns     done                    ; if not, we're done
  78.         neg     edx                     ; negate number
  79.         neg     eax                     ; ...
  80.         sbb     edx,0                   ; ...
  81. done:
  82.         pop     ecx                     ; ...
  83.         add     esp,12                  ; outta here
  84.         ret                             ; ...
  85.  
  86. ret_zero:
  87.         xor     edx,edx
  88.         xor     eax,eax
  89.         jmp     done
  90.  
  91. ret_inf:
  92.         mov     edx,0ffffffffh
  93.         mov     eax,edx
  94.         jmp     done
  95. endproc __FDU87
  96. endproc __FSU87
  97.  
  98.         endmod
  99.         end
  100.