1

How exactly does the processor handle this division by zero condition?

A divide by zero condition occurs when in a divide operation the divisor turns out to be a zero as there is no binary representation for infinity. The ALU cannot handle it.

Does different processor have different way of handling it? I am a new at this topic and all the articles on the Internet contradict other.

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847

1 Answers1

1

It depends on the ISA. For example, x86 raises a #DE exception (same as divide overflow when the quotient doesn't fit in one register). ARM doesn't fault, you just get 0 in the destination. Division by zero not causing runtime exception on Nvidia Jetson.

(ARM division instructions only have a dividend 1 register wide, unlike x86 where the dividend is twice as wide as the divisor or quotient. ARM division can thus only overflow on INT_MIN/-1, other than divide-by-zero.)

In terms of an ALU, you have to build one that checks for that and handles it as a special case. What the rest of the CPU's internal logic does

(I'm assuming you mean integer division; FP usually runs with exceptions masked...)


What the OS does with a division exception depends on the OS. But if it's Unix-like, it has to deliver SIGFPE (arithmetic exception) to the offending process. Of course at that point it's no longer CPU-architecture, but software.

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847