简体   繁体   English

在x86 nasm中划分时的浮点异常

[英]Floating Point Exception when dividing in x86 nasm

I'm busy with learning Assembly and was looking at dividing, however I ran into a pickle with the following statement: 我正忙着学习装配,正在考虑分裂,但是我遇到了以下声明:

mov edx,0x00000001
mov eax,0x00000000
mov ecx,0x00000002
idiv ecx

GDB: GDB:

   0x08048071 <+17>:    mov    edx,0x1
   0x08048076 <+22>:    mov    eax,0x0
   0x0804807b <+27>:    mov    ecx,0x2
=> 0x08048080 <+32>:    idiv   ecx

I wanted to divide 0x100000000 by 0x00000002, so since the span for division is EDX:EAX I moved 0x1 into EDX and 0x0 into EAX. 我想将0x100000000除以0x00000002,因为除法的范围是EDX:EAX我将0x1移动到EDX,将0x0移动到EAX。 I then move 0x2 into ECX and divide, this unfortunately gives me a floating point exception, I' m not sure what I did wrong. 然后我将0x2移动到ECX并进行除法,这不幸地给了我一个浮点异常,我不确定我做错了什么。

When using div (unsigned) it works normal, so I wonder what the difference is in interpretation between div and idiv for this particular statement which causes the exception. 当使用div(无符号)时它工作正常,所以我想知道这个导致异常的特定语句在div和idiv之间的解释有什么不同。

The quotient ( 0x80000000 ) doesn't fit into a 32-bit signed integer (max value: 0x7fffffff ). 商( 0x80000000 )不适合32位有符号整数(最大值: 0x7fffffff )。 Hence you get an exception. 因此你得到一个例外。 It does fit into a 32-bit unsigned integer (max value 0xffffffff ), so no exception is triggered by an unsigned divide. 确实适合32位无符号整数(最大值0xffffffff ),因此无符号除法不会触发异常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM