x86 exceptions and flags

3

please, I know that when you for example divide by zero, the aproptiate flag is set in CPU flag register. But today I read that there are special interrupt vectors (I think the first 16 in IVT) that are used for such conditions like dividing by zero. So, what I want to ask is, does any situation that couses change som flag also triggers apropriate interrupt? Becouse in school, we used conditional jumps that checks wheather carry flag has been set or not, and I don´t remember there was some interrupt triggerd by that. So I am pretty confused now.

user32569

Posted 2010-05-03T15:31:32.930

Reputation: 739

Minimal 16-bit real mode division by zero interrupt example: https://github.com/cirosantilli/x86-bare-metal-examples/blob/9e58c1dc656dab54aa69daa38f84eb8c0aa6151e/interrupt_zero_divide.S 32-bit version: https://github.com/cirosantilli/x86-bare-metal-examples/blob/9e58c1dc656dab54aa69daa38f84eb8c0aa6151e/idt.S

– Ciro Santilli 新疆改造中心法轮功六四事件 – 2015-10-21T19:44:51.320

Answers

3

There are two types of interrupts.

The first type are interrupts for signalling hardware events, like that the hardware timer has elapsed or that the hard drive controller has finished transferring data to memory.

The second type are interrupts for signalling some unexpected condition. Some examples are: access to invalid memory, division by zero (actually it's "divide overflow" that occurs not only when you divide by zero, but even when you divide a very large value by a very small value), breakpoint instruction, hardware breakpoint etc. This type of exceptions are raised by CPU when it cannot complete the current instruction and usually result in terminating the current process or breaking into debugger. They are actually unrelated to CPU flags, which hold the results of the latest instruction.

qbeuek

Posted 2010-05-03T15:31:32.930

Reputation: 226