6
  mov eax, 0x01
  mov ecx, 0x02
  div ecx                 ; Divide AX/CX, saves remainder in DX
  cmp dx, 0
  je OddNumber
  int 80h

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 says "Program received signal SIGFPE, Arithmetic exception." by the way.

David Gomes
  • 5,644
  • 16
  • 60
  • 103
  • to check for zero [use `test` instead of `cmp`](https://stackoverflow.com/a/33724806/995714) – phuclv Sep 10 '18 at 15:04

2 Answers2

13
  1. You need to zero edx before calling div ecx. When using a 32-bit divisor (e.g, ecx), div divides the 64-bit value in edx:eax by its argument, so if there's junk in edx, it's being treated as part of the dividend.

  2. After the div, you probably want to compare edx, not just dx.

1

Your answer seems to be covered in this floating point exception may mean division by 0 post. Can you have a look at what is in edx before the div?

Keldon Alleyne
  • 2,103
  • 16
  • 23