Interrupts are messages sent to the processor to obtain processing time. Each interrupt has a priority, There are different types of interrupt:
I/O interrupt - Generated by an input/output device to signal that a job (process) is complete or an error has occurred, for example: the printer is out of paper.
Timer Interrupt - Generated by an internal clock indicating that the processor must attend to time critical activities.
Hardware Error - For example: power failure. This type of interrupt has high priority.
Program interrupt - Generated due to an error in a program for example: attempting to divide by zero.
Interrupts are held in queues. After each CPU cycle, the queue is checked for an interrupt with a higher priority than the current job. If an interrupt with a higher priority is found, the contents of the registers are put on a stack. This allows the job to resume once the interrupt has been processed.
Once all higher priority interrupts have been processed, the contents of registers are pulled from the stack and the original job is resumed.
By replacing the contents of the registers on a stack, the problem caused by an interrupts occuring during the processing of another interrupt is solved. Remember, a stack is a 'last in first out (LIFO)' data structure.