home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c082_144 / 1.ddi / MATHSRC.ZIP / FTOL.ASM < prev    next >
Encoding:
Assembly Source File  |  1992-06-10  |  1.7 KB  |  72 lines

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