为什么IDIV为-1会导致浮点异常? [英] Why IDIV with -1 causes floating point exception?

查看:111
本文介绍了为什么IDIV为-1会导致浮点异常?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

据我了解,idiv %ebxedx:eax(按该顺序连接为64位值)除以32位ebx.

As far as I understood, idiv %ebx will divide edx:eax (concatenated into 64-bit value, in that order) with 32-bit ebx.

但是,当我尝试将0x00000000:0xfffffffb(0和-5)与0xffffffff(-1)相除时,会出现浮点异常.

However, when I try to divide 0x00000000:0xfffffffb (0 and -5) with 0xffffffff (-1), I get a floating-point exception.

有人可以解释为什么吗?我很困惑为什么会这样,因为我毕竟没有被0除.

Can someone explain why? I'm quite puzzled why this is happening because I'm not dividing by 0 after all.

注意,我知道我需要对扩展名edx:eax进行签名才能实现我想要的目标,即计算-5/-1.但是,即使没有符号扩展名,以下内容也应 不会导致FPE.

Note that I know I need to sign extend edx:eax to achieve what I want, which is to calculate -5/-1. However, even without sign extension the below should not cause an FPE.

推荐答案

请注意,我知道我需要签署扩展名edx:eax ...

如果不对eax进行符号扩展,则将edx:eax解释为64位带符号数字:

If you don't sign-extend eax, edx:eax is interpreted as 64-bit signed number:

在您的情况下,该值为0x00000000fffffffb,即4294967291(而不是-5).

In your case, this would be 0x00000000fffffffb which is 4294967291 (and not -5).

dividiv在两种情况下会导致异常:

div and idiv will cause an exception in two cases:

  • 你被零除
  • 除法结果不在eax寄存器可以表示的范围内
  • You divide by zero
  • The division result is not in the range that can be represented by the eax register

eax可以保存从-2147483648到+2147483647范围内的带符号数字,但是-4294967291不在该范围内.您会得到一个例外.

eax can hold signed numbers in the range from -2147483648 to +2147483647, but -4294967291 lies outside that range. You'll get an exception.

不应导致FPE.

should not cause an FPE.

实际上,dividiv将导致整数除法异常",而不是浮点异常".

Indeed, div and idiv will cause an "integer division exception", not "a floating-point exception".

但是,许多操作系统将显示浮点异常"消息; POSIX将SIGFPE定义为涵盖任何算术异常.

However, many OSs will show the message "floating point exception"; POSIX defines SIGFPE as covering any arithmetic exception.

这篇关于为什么IDIV为-1会导致浮点异常?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆