We've already looked into some aspects of interrupts, especially the
low-level aspects (for example, why an interrupt happens, what sequence
of events occurs during the generation and acknowledgment of an interrupt,
etc). This chapter takes a good look at the software that responds to an
interrupt by calling the appropriate routine.
Before we begin, we need to remember the following:
When an interrupt occurs, the hardware saves the current PC and PS
on the stack, and then pops the PC and PS stored in the interrupt dispatch
table entry identified by the interrupt vector.
The interrupt routine needs to call a special return instruction (not
the usual one that returns from a subroutine) to return from interrupt
processing. This instruction restores the pushed PC and PS in a single
step.
Some assembly is required because the ISR (interrupt service routine)
may need to manipulate registers, and because the special RTI (return from
interrupt) instruction is not generally callable from a high-level language.