8

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:

   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. I then move 0x2 into ECX and divide, this unfortunately gives me a floating point exception, I' m not sure what I did wrong.

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.

Stephen Canon
  • 103,815
  • 19
  • 183
  • 269
Lucas Kauffman
  • 6,789
  • 15
  • 60
  • 86

1 Answers1

7

The quotient (0x80000000) doesn't fit into a 32-bit signed integer (max value: 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.

Stephen Canon
  • 103,815
  • 19
  • 183
  • 269