home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power-Programmierung
/
CD1.mdf
/
xbase
/
library
/
clipper
/
rettig
/
source
/
_tr_frex.asm
< prev
next >
Wrap
Assembly Source File
|
1990-10-21
|
3KB
|
110 lines
; _TR_FREX.ASM
;
; by Ralph Davis, Leonard Zerman
; modified by Rick Spence
;
; Placed in the public domain by Tom Rettig Associates, 10/22/1990.
;
;
PUBLIC __TR_FREXP
DGROUP GROUP _DATA
;***************************************************
_DATA SEGMENT WORD PUBLIC 'DATA'
;
RETNUM DQ 0
RETNUM2 DQ 0
;
_DATA ENDS
;***************************************************
;**************************************
_TR_FREX_TEXT SEGMENT BYTE PUBLIC 'CODE'
ASSUME CS:_TR_FREX_TEXT,DS:_DATA
;--------------------------------------
;
; Replaces Lattice library routine frexp();
;
; C SYNTAX: _tr_frexp(n, ip);
;
; double _tr_frexp();
; double n;
; int *ip;
;
; RETURNS: Mantissa in pointer to double in DX:AX, Exponent in *ip
;
; NOTE: This routine behaves somewhat differently from the
; Lattice routine.
;
; Lattice normalizes the mantissa to be between 0 and 1,
; and increases the exponent accordingly.
;
; This routine returns the mantissa the way it is actually
; stored, i.e., as a number between 1 and 2. The
; exponent is returned exactly as represented.
;
; ALSO NOTE that zero, which is stored as 8 bytes of
; zeroes, is returned as a mantissa of 0.000 and an
; exponent of 0, as it is by the Lattice library routine.
;
;--------------------
__TR_FREXP PROC FAR
PUSH BP
MOV BP,SP
PUSH SI
PUSH DI
PUSH DS
PUSH ES
PUSH CX
PUSH BX
MOV AX,WORD PTR [bp+12]
MOV WORD PTR _DATA:RETNUM2+6,AX
MOV AX,WORD PTR [bp+10]
MOV WORD PTR _DATA:RETNUM2+4,AX
MOV AX,WORD PTR [bp+8]
MOV WORD PTR _DATA:RETNUM2+2,AX
MOV AX,WORD PTR [bp+6]
MOV WORD PTR _DATA:RETNUM2,AX
MOV DX,[BP+6] ; Load number (double precision)
MOV CX,[BP+8] ; into AX:BX:CX:DX
MOV BX,[BP+10]
MOV AX,[BP+12]
OR AX,AX ; Is the number zero?
JZ FR_RET0
MOV SI,AX ; Isolate exponent
AND SI,7FFFH ; Turn off sign bit
XOR AH,AH ; Clear AH
OR AX,3FF0H ; Mantissa has 0 exponent (1.xxx * 2^0)
REPT 4
SHR SI,1
ENDM
MOV WORD PTR _DATA:RETNUM2+6,AX
MOV AX,OFFSET _DATA:RETNUM2
MOV DX,DS ;SEG _DATA:RETNUM2
JMP SHORT FR_1
FR_RET0:
MOV AX,OFFSET _DATA:RETNUM+6 ;Return zero mantissa and exponent
MOV DX,DS ;SEG _DATA:RETNUM
MOV SI,03FFH
FR_1:
SUB SI,03FFH ; SI now holds exponent
LES DI,[BP+14] ; Pick up address for return of exponent
MOV ES:[DI],SI ; Store it
POP BX
POP CX
POP ES
POP DS
POP DI
POP SI
POP BP
RET
__TR_FREXP ENDP
;--------------------------------------
_TR_FREX_TEXT ENDS
;**************************************
END