装配体和浮点数 [英] Assembly divisions and floating points
问题描述
mov eax, 0x01
mov ecx, 0x02
div ecx ; Divide AX/CX, saves remainder in DX
cmp dx, 0
je OddNumber
int 80h
当我尝试除以1/2而不是将其标记为OddNumber时,它将返回浮点异常".我知道1/2是浮点数,但是我该如何处理呢?谢谢.
When I try to divide 1/2, instead of going to label OddNumber, it returns "Floating point exception". I know 1/2 is a float, but how can I handle it? Thanks.
GDB说:程序收到信号SIGFPE,算术异常."顺便说一句.
GDB says "Program received signal SIGFPE, Arithmetic exception." by the way.
推荐答案
-
在调用
div ecx
之前,您需要将edx
设置为零.当使用32位除数(例如ecx
)时,div
将edx:eax
中的64位值除以其参数,因此,如果edx
中存在垃圾,它将被视为股息的一部分.
You need to zero
edx
before callingdiv ecx
. When using a 32-bit divisor (e.g,ecx
),div
divides the 64-bit value inedx:eax
by its argument, so if there's junk inedx
, it's being treated as part of the dividend.
在div
之后,您可能想比较edx
,而不仅仅是dx
.
After the div
, you probably want to compare edx
, not just dx
.
这篇关于装配体和浮点数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!