ReC98/libs/BorlandC/math/ftol.asm

68 lines
1.8 KiB
NASM

; *Not* the original file, but an edit to turn it into an includable slice.
; Changes include:
; * removal of RULES.ASI to eliminate redundancy
; * removal of the segment declarations (for obvious reasons)
; * the Fcall and Ncall labels being replaced with LPROG
;[]------------------------------------------------------------[]
;| FTOL.ASM -- Float to Long conversion |
;[]------------------------------------------------------------[]
;
; C/C++ Run Time Library - Version 5.0
;
; Copyright (c) 1987, 1992 by Borland International
; All Rights Reserved.
;
NAME Ftol
option emulator ; generate emulated '87 code
; FTOL@
; Calls to FTOL@ are generated by the compiler for code
; that needs to convert a floating point type to an integral type.
; Input: floating point number on the top of the '87.
; Output: a (signed or unsigned) long in AX, DX.
; All other registers preserved.
; Proc is far, independent of memory model.
; Caution: Overflows are ignored.
temp1 equ [bp-2]
temp2 equ [bp-10]
ifdef LPROG
PubSym@ FTOL@, <PROC FAR>, __PASCAL__
PubSym@ F_FTOL@, <LABEL FAR>, __PASCAL__
else
PubSym@ N_FTOL@, <PROC NEAR>, __PASCAL__
endif
push bp
mov bp, sp
sub sp, 10
fstcw temp1 ; save the control word
fwait
mov al, byte ptr temp1 + 1
or byte ptr temp1 + 1, 0Ch
fldcw temp1
fistp qword ptr temp2 ; convert to 64-bit integer
mov byte ptr temp1 + 1, al
fldcw temp1 ; restore the control word
mov ax, word ptr temp2 ; return LS 32 bits
mov dx, word ptr temp2 + 2
mov sp, bp
pop bp
ret
ifdef LPROG
EndProc@ FTOL@, __PASCAL__
else
EndProc@ N_FTOL@, __PASCAL__
endif