What is an interrupt?
This is a controlled violation of the sequential execution of a program. Interrupts allows one to change program execution order based on events external to the program itself.
After a signal (external or internal) is caught, a program’s execution is suspended, some registers are saved, and the CPU starts executing a special routine to handle the situation. Following are exemplary situations when an interrupt occurs (and an appropriate piece of code is executed to handle it):
- A signal from an external device (external interrupt).
- Zero division (internal interrupt).
- Invalid instruction (when CPU failed to recognize an instruction by its binary representation -- internal interrupt).
- An attempt to execute a privileged instruction in a non-privileged mode (internal interrupt).