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.                 modstart        mdfd386
  37.  
  38.                 xdefp   "C",_dmsbintoieee
  39.                 defpe   _dmsbintoieee
  40.  
  41. ifdef __STACK__
  42.                 mov     eax,dword ptr +4H[esp]
  43.                 mov     edx,dword ptr +8H[esp]
  44. else
  45.                 push    ecx
  46. endif
  47.  
  48. ; At this point:
  49. ; eax     - ptr to MBF source double
  50. ; edx     - ptr to IEEE dest double
  51. ; ecx     - spare register
  52.  
  53. ; Check for and process MBF 0.0 first
  54.                 mov     ecx,+4h[eax]    ; load MBF double (hi)
  55.                 test    ecx,0ff000000h  ; MBF exponent = 0 ?
  56.                 jne     MBFNonZero      ; no, jump
  57.  
  58. ; MBF 0.0, store IEEE 0.0
  59.                 xor     eax,eax         ; make 0
  60.                 mov     [edx],eax       ; store IEEE 0.0 (lo)
  61.                 mov     +4h[edx],eax    ; store IEEE 0.0 (hi)
  62. ifndef __STACK__
  63.                 pop     ecx             ; clean up
  64. endif
  65.                 ret                     ; return 0 (no overflow)
  66.  
  67. MBFNonZero:     mov     eax,[eax]       ; load MBF double (lo)
  68.  
  69. ; At this point:
  70. ; ecx:eax - MBF source double
  71. ; edx     - ptr to IEEE dest double
  72.  
  73.                 rol     ecx,9           ; rotate exponent & sign bit low
  74.                 shr     ecx,1           ; move sign bit before exponent
  75.                 rcr     cl,1            ; :
  76.                 adc     ecx,ecx         ; :
  77.                 ror     ecx,9           ; rotate exponent & sign bit back
  78.  
  79. ; shift mantissa into place
  80.                 shrd    eax,ecx,2       ; shift mantissa
  81.                 sar     ecx,3           ; shift exponent & mantissa, save sign bit
  82.                 rcr     eax,1           ; shift mantissa
  83.                 jc      MBFRound        ; jump if rounding up
  84.                 and     ecx,8FFFFFFFh   ; mask out surplus sign bits
  85.                 add     ecx,37e00000h   ; convert MBF to IEEE exponent
  86.  
  87. IEEEStore:
  88.                 mov     [edx],eax       ; store IEEE double (lo)
  89.                 mov     +4h[edx],ecx    ; store IEEE double (hi)
  90.                 xor     eax,eax         ; 0
  91. ifndef __STACK__
  92.                 pop     ecx             ; clean up
  93. endif
  94.                 ret                     ; return 0 (no overflow)
  95.  
  96. ; add rounding bit
  97. MBFRound:       and     ecx,8FFFFFFFh   ; mask out surplus sign bits
  98.                 add     eax,1           ; add round bit
  99.                 adc     ecx,37e00000h   ; convert MBF to IEEE exponent
  100.                 jmp     IEEEStore       ; store result
  101.  
  102.                 endproc _dmsbintoieee
  103.  
  104.                 endmod
  105.                 end
  106.