📄 exmathop.asm
字号:
page 49,132
TITLE exMathOp - I2 Math Operators
;***
;exmathop.asm - executors for math operators and functions
;
; Copyright <C> 1986, Microsoft Corporation
;
;Purpose:
;
; This module includes:
; - the I2 calculator functions.
; - interface to the mathpack for all mathpack resident functions.
;
;
;****************************************************************************
.8087
.xlist
include version.inc
EXMATHOP_ASM = ON
IncludeOnce architec
IncludeOnce executor
IncludeOnce exint
IncludeOnce opcontrl
IncludeOnce opintrsc
IncludeOnce opaftqb4
IncludeOnce rtinterp
IncludeOnce context
IncludeOnce qbimsgs
IncludeOnce extort
IncludeOnce ssint
.list
assumes cs, CODE
assumes es, NOTHING
assumes ss, DATA
PREC53 MACRO ;NOOP if NOT FV_PREC53
ENDM
PREC64 MACRO ;NOOP if NOT FV_PREC53
ENDM
extrn B$CMI4:far
extrn __aFlmul:far
sBegin CODE
;===============================================================================
subttl I2 Math Support
page
MakeExe exAddI2,opAdd
pop ax
mov bx,sp
add DGROUP:[bx],ax
jo MulI2OVF
DispMac
MakeExe exSubI2,opSub
pop ax ;Right hand arg
mov bx,sp
sub DGROUP:[bx],ax
jo MulI2OVF
DispMac
MakeExe exMulI2,opMul
pop cx
pop ax
imul cx
jo MulI2OVF
push ax
DispMac
MulI2OVF:
FnAbsI2OVF:
UMiI2OVF:
jmp exMathErrOVF
MakeExe exIdvI2,opIdv
pop cx ;Right hand arg
pop ax ;Left hand arg
cwd
jcxz IdvI2DV0
idiv cx
push ax
DispMac
exMod0:
IdvI2DV0:
jmp exMathErrDV0
MakeExe exUMiI2,opUMi
mov bx,sp
neg word ptr DGROUP:[bx]
jo UMiI2OVF
DispMac
MakeExe exModI2,opMod
pop cx
pop ax
cwd
jcxz exMod0
idiv cx
push dx
exModDisp:
DispMac
MakeExe exModI4,opMod
pop ax
pop bx
pop cx
pop dx
push bx
push ax
push dx
push cx ;MS Math(?)
CALLRT B$RMI4,DispMovDxAx ;MOD function
MakeExe exIDvI4,opIDv
pop ax
pop bx
pop cx
pop dx
push bx
push ax
push dx
push cx ;MS Math(?)
CALLRT B$DVI4,DispMovDxAx
MakeExe exFnAbsI2,opFnAbs
pop ax
cwd
xor ax,dx
sub ax,dx
jo FnAbsI2OVF
push ax
DispMac
MakeExe exStCaseEQI2,opStCaseEQ
SkipExHeader
MakeExe exStCaseI2,opStCase
SkipExHeader
MakeExe exEQI2,opEQ
pop ax
pop cx
xor bx,bx
cmp ax,cx
jnz @F
dec bx
@@:
push bx
DispMac
MakeExe exStCaseNEI2,opStCaseNE
SkipExHeader
MakeExe exNEI2,opNE
pop ax
pop cx
xor bx,bx
cmp ax,cx
jz @F
dec bx
@@:
push bx
DispMac
MakeExe exStCaseLEI2,opStCaseLE
SkipExHeader
MakeExe exLEI2,opLE
pop cx ;Right arg
pop ax ;Left arg
xor bx,bx
cmp ax,cx
jg @F
dec bx
@@:
push bx
DispMac
MakeExe exStCaseGEI2,opStCaseGE
SkipExHeader
MakeExe exGEI2,opGE
pop cx ;Right arg
pop ax ;Left arg
xor bx,bx
cmp ax,cx
jl @F
dec bx
@@:
push bx
DispMac
MakeExe exStCaseGTI2,opStCaseGT
SkipExHeader
MakeExe exGTI2,opGT
pop cx ;Right arg
pop ax ;Left arg
xor bx,bx
cmp ax,cx
jle @F
dec bx
@@:
push bx
DispMac
MakeExe exStCaseLTI2,opStCaseLT
SkipExHeader
MakeExe exLTI2,opLT
pop cx ;Right arg
pop ax ;Left arg
xor bx,bx
cmp ax,cx
jge @F
dec bx
@@:
push bx
DispMac
MakeExe exNotI2,opNot
mov bx,sp
not word ptr DGROUP:[bx]
DispMac
MakeExe exAndI2,opAnd
pop ax
pop cx
and ax,cx
push ax
DispMac
MakeExe exOrI2,opOr
pop ax
mov bx,sp
or DGROUP:[bx],ax
DispMac
MakeExe exXorI2,opXor
pop ax
mov bx,sp
xor DGROUP:[bx],ax
DispMac
MakeExe exEqvI2,opEqv
pop ax ;Right operand
pop cx ;Left operand
xor ax,cx
not ax
push ax
DispMac
MakeExe exImpI2,opImp
pop ax ;Right hand arg
pop cx ;Left hand arg
not cx
or ax,cx
push ax
DispMac
MakeExe exFnIntInt,opFnInt
SkipExHeader
MakeExe exFnFixInt,opFnFix
DispMac
MakeExe exFnSgnI2,opFnSgn
xor ax,ax ;Assume 0
pop bx
or bx,bx
jz PushAxDisp
js SgnSgn
inc ax
jmp short PushAxDisp
SgnSgn:
dec ax
jmp short PushAxDisp
;===============================================================================
subttl I4 Math Support
page
MakeExe exAddI4,opAdd
pop ax
pop dx
mov bx,sp
add DGROUP:[bx],ax
adc DGROUP:[bx+2],dx
jo SubI4OVF
DispMac
MakeExe exSubI4,opSub
pop ax
pop dx
mov bx,sp
sub DGROUP:[bx],ax
sbb DGROUP:[bx+2],dx
jo SubI4OVF
DispMac
SubI4OVF:
FnAbsI4OVF:
UMiI4OVF:
jmp exMathErrOVF
MakeExe exMulI4,opMul
call __aFlmul ;Perform the multiply
jb SubI4OVF ;Declare overflows
push dx
push ax
DispMac
MakeExe exFnSgnI4,opFnSgn
pop ax
pop dx
or ax,dx ;Test for zero
jz PushAxDisp ;Result = 0
shl dx,1 ;PSW.C
sbb ax,ax ;PSW.NZ indicates input was neg
jnz PushAxDisp ; so return -1
inc ax ;Must have been positive
jmp short PushAxDisp
MakeExe exFnAbsI4,opFnAbs
pop ax
pop dx
or dx,dx
jns PushDxAxDisp
not ax
not dx
add ax,1
adc dx,0
jo FnAbsI4OVF
PushDxAxDisp:
push dx
PushAxDisp:
push ax
DispMac
MakeExe exNotI4,opNot
mov bx,sp
not word ptr DGROUP:[bx]
not word ptr DGROUP:[bx+2]
DispMac
MakeExe exUMiI4,opUMi
pop ax
pop dx
not ax
not dx
add ax,1
adc dx,0
jo UMiI4OVF
jmp short PushDxAxDisp
MakeExe exAndI4,opAnd
pop ax
pop dx
mov bx,sp
and DGROUP:[bx],ax
and DGROUP:[bx+2],dx
DispMac
MakeExe exOrI4,opOr
pop ax
pop dx
mov bx,sp
or DGROUP:[bx],ax
or DGROUP:[bx+2],dx
DispMac
MakeExe exXorI4,opXor
pop ax
pop dx
mov bx,sp
xor DGROUP:[bx],ax
xor DGROUP:[bx+2],dx
DispMac
MakeExe exEqvI4,opEqv
pop ax
pop dx
pop cx
pop bx
xor ax,cx
not ax
xor dx,bx
not dx
jmp short PushDxAxDisp
MakeExe exImpI4,opImp
pop ax
pop dx ;Right hand arg
pop cx
pop bx ;Left hand arg
not cx
not bx
or ax,cx
or dx,bx
jmp short PushDxAxDisp
;***
;CompareI4 - I4 signed comparison routine
;Purpose:
; Signed compare of two I4 numbers.
;
;Inputs:
; ParmD Left left hand argument
; ParmD Right right hand argument
;
;Function:
; Set Carry and Zero flags based on input arguments.
; Left > Right Zero clear and carry clear
; Left < Right Zero clear and carry set
; Left = Right Zero set
;
; Note: These are the flag conventions used by
; unsigned jumps, NOT signed jumps.
;
;Outputs:
; Zero and carry flags have result (set up for signed jmp)
;***************************************************************************
Public CompareI4
CompareI4:
pop ax ;Near
push cs ; to far
push ax ; return address
jmp B$CMI4 ;Perform and return to caller
MakeExe exStCaseLTI4,opStCaseLT
SkipExHeader
MakeExe exLTI4,opLT
call CompareI4
jb I4TrueDisp
jmp short I4FalseDisp
MakeExe exStCaseLEI4,opStCaseLE
SkipExHeader
MakeExe exLEI4,opLE
call CompareI4
ja I4FalseDisp
jmp short I4TrueDisp
MakeExe exStCaseGEI4,opStCaseGE
SkipExHeader
MakeExe exGEI4,opGE
call CompareI4
jae I4TrueDisp
jmp short I4FalseDisp
MakeExe exStCaseGTI4,opStCaseGT
SkipExHeader
MakeExe exGTI4,opGT
call CompareI4
ja I4TrueDisp
jmp short I4FalseDisp
MakeExe exStCaseEQI4,opStCaseEQ
SkipExHeader
MakeExe exStCaseI4,opStCase
SkipExHeader
MakeExe exEQI4,opEQ
call CompareI4
jz I4TrueDisp
I4FalseDisp:
PUSHI AX,FALSE
DispMac
MakeExe exStCaseNEI4,opStCaseNE
SkipExHeader
MakeExe exNEI4,opNE
call CompareI4
jz I4FalseDisp
I4TrueDisp:
PUSHI AX,<NOT FALSE>
DispMac
;===============================================================================
subttl R8 math Support
page
MovAxDisp MACRO RtEnt
if LOW (P&RtEnt+1)
mov ax,P&RtEnt+1
else
mov ax,(HIGH P&RtEnt)+100h
endif
ENDM
;Rewritten with [21]
MakeExe exAddR8,opAdd
PREC53
fadd
PREC64
DispMac
MakeExe exSubR8,opSub
PREC53
fsub
PREC64
DispMac
MakeExe exMulR8,opMul
PREC53
fmul
PREC64
DispMac
MakeExe exDivR8,opDiv
PREC53
fdiv
PREC64
DispMac
MakeExe exPwrR8,opPwr
call CheckCONST ;Declare error if in CONST
fxch ;Reverse order for runtime
MovAxDisp B$POW8 ;Runtime entrypoint
jmp short DispR8 ;Go do rt call, and exit
subttl R8 Math Support - Single argument executors
page
MakeExe exFnSin,opFnSin
MovAxDisp B$SIN8
DispR8:
call ExToRtCall ;Perform the function in ax
DispMac
;End of [21]
MakeExe exFnCos,opFnCos
MovAxDisp B$COS8
jmp DispR8
MakeExe exFnTan,opFnTan
MovAxDisp B$TAN8
jmp DispR8
MakeExe exFnAtn,opFnAtn
MovAxDisp B$ATN8
jmp DispR8
MakeExe exFnExp,opFnExp
MovAxDisp B$EXP8
jmp DispR8
MakeExe exFnSqr,opFnSqr
PREC53
fsqrt ;Do the root
PREC64
DispMac
MakeExe exFnLog,opFnLog
MovAxDisp B$LOG8
jmp DispR8
MakeExe exFnIntR8,opFnInt
MovAxDisp B$INT8
jmp DispR8
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -