home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c065 / 2.ddi / MATH.ZIP / FTOL.ASM < prev    next >
Encoding:
Assembly Source File  |  1990-06-07  |  1.9 KB  |  71 lines

  1.  
  2.         NAME    Ftol
  3.         PAGE    60,132
  4. ;[]------------------------------------------------------------[]
  5. ;|      FTOL.ASM -- Float to Long conversion                    |
  6. ;|                                                              |
  7. ;|      Turbo-C Run Time Library        version 3.0             |
  8. ;|                                                              |
  9. ;|      Copyright (c) 1987, 1990 by Borland International Inc.  |
  10. ;|      All Rights Reserved.                                    |
  11. ;[]------------------------------------------------------------[]
  12.  
  13. include RULES.ASI
  14.  
  15. emul            ; generate emulated '87 code
  16.  
  17. CSeg@
  18.  
  19. ; FTOL@
  20. ; Calls to FTOL@ are generated by the compiler for code
  21. ; that needs to convert a floating point type to an integral type.
  22. ; Input: floating point number on the top of the '87.
  23. ; Output: a (signed or unsigned) long in AX, DX.
  24. ; All other registers preserved.
  25. ; Proc is far, independent of memory model.
  26.  
  27. ; Caution: Overflows are ignored.
  28.  
  29. temp1   equ     [bp-2]
  30. temp2   equ     [bp-10]
  31.  
  32. ifdef   FCall
  33.  
  34. PubSym@ FTOL@, <PROC FAR>, __PASCAL__
  35. PubSym@ F_FTOL@, <LABEL FAR>, __PASCAL__
  36.  
  37. endif
  38.  
  39. ifdef   NCall
  40.  
  41. PubSym@ N_FTOL@, <PROC NEAR>, __PASCAL__
  42.  
  43. endif
  44.  
  45.         push    bp
  46.         mov     bp, sp
  47.         sub     sp, 10
  48.         fstcw   temp1                   ; save the control word
  49.         fwait
  50.         mov     al, temp1.BY1
  51.         or      temp1.BY1, 0Ch
  52.         fldcw   temp1
  53.         fistp   qword ptr temp2         ; convert to 64-bit integer
  54.         mov     temp1.BY1, al
  55.         fldcw   temp1                   ; restore the control word
  56.         mov     ax, temp2.W0            ; return LS 32 bits
  57.         mov     dx, temp2.W1
  58.         mov     sp, bp
  59.         pop     bp
  60.         ret
  61.  
  62. ifdef   FCall
  63. EndProc@ FTOL@, __PASCAL__
  64. else
  65. EndProc@ N_FTOL@, __PASCAL__
  66. endif
  67.  
  68. CSegEnd@
  69.  
  70. end
  71.