home *** CD-ROM | disk | FTP | other *** search
/ Chip 1997 April / Chip_1997-04_cd.bin / prezent / cb / data.z / EXT2REAL.ASM < prev    next >
Assembly Source File  |  1997-01-16  |  1KB  |  78 lines

  1.  
  2. ; *******************************************************
  3. ; *                            *
  4. ; *     Delphi Runtime Library                          *
  5. ; *                            *
  6. ; *    Copyright (c) 1996 Borland International    *
  7. ; *                            *
  8. ; *******************************************************
  9.  
  10.     INCLUDE    SE.ASM
  11.  
  12.     .386
  13.     .MODEL    FLAT
  14.  
  15.     EXTRN    Error:NEAR
  16.  
  17.     PUBLIC    _Ext2Real
  18.  
  19.     .CODE
  20.  
  21. RealBias EQU    129
  22. ExtBias  EQU    3FFFH
  23.  
  24. ;    FUNCTION _Ext2Real( val : Extended ) : Real;
  25.  
  26. _Ext2Real PROC
  27.  
  28. ; ->    FST(0)    Value
  29. ;    EAX    Pointer to result
  30.  
  31.     PUSH    EBX
  32.  
  33.     SUB    ESP,12
  34.     FSTP    tbyte ptr [ESP]
  35.  
  36.     POP    EBX            ; EBX is low half of fraction
  37.     POP    EDX            ; EDX is high half of fraction
  38.     POP    ECX            ; CX is exponent and sign
  39.  
  40.     SHR    EBX,24            ; set carry to last bit shifted out
  41.     ADC    BL,0            ; if bit was 1, round up
  42.     ADC    EDX,0
  43.     ADC    CX,0
  44.     JO    @@overflow
  45.  
  46.     ADD    EDX,EDX            ; shift fraction 1 bit left
  47.     ADD    CX,CX            ; shift sign bit into carry
  48.     RCR    EDX,1            ; attach sign bit to fraction
  49.     SHR    CX,1            ; restore exponent, deleting sign
  50.  
  51.     SUB    CX,ExtBias-RealBias    ; adjust exponent
  52.     JLE    @@underflow
  53.     TEST    CH,CH            ; CX must be in 1..255
  54.     JG    @@overflow
  55.  
  56.     MOV    [EAX],CL
  57.     MOV    [EAX+1],BL
  58.     MOV    [EAX+2],EDX
  59.  
  60.     POP    EBX
  61.     RET
  62.  
  63. @@underflow:
  64.     XOR    ECX,ECX
  65.     MOV    [EAX],ECX
  66.     MOV    [EAX+4],CX
  67.     POP    EBX
  68.     RET
  69.  
  70. @@overflow:
  71.     POP    EBX
  72.     MOV    AL,8
  73.     JMP    Error
  74.  
  75. _Ext2Real ENDP
  76.  
  77.     END
  78.