質問

Now I'm not asking about the mathematical answer of dividing by zero, I want to what my computer does when it tries to divide by zero?

I can see different answers depending on what level we look at? Looking at a high-level I expect the language specification may just say "hey you can't do that throw an error"

Looking at an assembly level, will the CPU try to call the divide instruction when we try to divide by 0?

If it does that'll take us to the machine code level. What happens now?

Now if that doesn't happen and we force it to happen, what would the result be?

役に立ちましたか?

解決 2

Looking at an assembly level, will the CPU try to call the divide instruction when we try to divide by 0?

Yep instruction gets fetched and decoded. What happens then? The divisor is found to be zero and the process stops doing what it's doing. It throws some kind of an exception, pipeline (if there is one) is flushed and most likely control jumps to some predefined error handling code - often the OS controls a machine level jump table called an interrupt vector (or this could be a separate to the interrupt vector table).

There are many architectures however, and things like error handling vary. Intel x86 follows above procedure at least.

If it does that'll take us to the machine code level. What happens now?

I have no idea what that means. From the CPU's perspective, it is all machine code level.

他のヒント

I think what you're asking is what's going to happen if we perform binary division algorithm with 0 in the denominator.

The algorithm will go into an infinite loop, and the quotient will grow larger and larger until it exhausts all available memory.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top