TITLE Unmasking an Exception (Exceptions.asm)
; This program shows how to mask (set) and unmask (clear) the divide by zero
; exception flag.
INCLUDE Irvine32.inc
.data
ctrlWord WORD ?
val1 DWORD 1
val2 REAL8 0.0
.code
main PROC
finit ; initialize FPU (divide by zero is masked)
; By unmasking, we enable the divide by zero exception.
fstcw ctrlWord ; get the control word
and ctrlWord,1111111111111011b ; unmask Divide by 0
fldcw ctrlWord ; load it back into FPU
fild val1
fdiv val2 ; divide by zero
fst val2
exit
main ENDP
END main
大家好,我对masm很新,我正在通过一些我可以找到的在线项目并且遇到这个问题,因为你可以看到它取消了0除外的分界但我怎么能编辑这个来掩盖同样的例外?如果你能解释并尽可能详细,那将会有所帮助!
答案 0 :(得分:3)
fstcw ctrlWord ; get the control word and ctrlWord,1111111111111011b ; unmask Divide by 0 fldcw ctrlWord ; load it back into FPU
零除法异常的屏蔽位(ZM)是FPU控制字的第2位。如果你没有写出像“1111111111111011b”这样的长掩蔽值,它会提高可读性 由于第2位由值4表示,因此清除该位的更可读方式是:
and ctrlWord, not(4)
有些人甚至更愿意写and ctrlWord, not(1<<2)
,因为这个仍然保留对位数的引用(在这种情况下为2)。
现在采用这种改进时,屏蔽零除法异常变成了将and
更改为or
并删除而不是运算符的问题。
and ctrlWord, not(4) ----> or ctrlWord, 4
作为替代方案,您还可以使用btr
和bts
说明清除或设置位:
and ctrlWord, not(4) ----> btr ctrlWord, 2 ;Clears bit 2
or ctrlWord, 4 ----> bts ctrlWord, 2 ;Sets bit 2