Interrupts and resets are among the most useful mechanisms that a computer system provides. In this section, we begin with a general discussion of interrupts and the motivation for using one.
An interrupt is an event that requests the CPU to suspend the program execution briefly and run a subroutine, called an interrupt service routine (ISR).
Figure 6.1 An interrupt in the program.
<aside>
<img src="/icons/map-pin_gray.svg" alt="/icons/map-pin_gray.svg" width="40px" /> The difference between an interrupt and a subroutine call (in figure 4.7 for reference), is that we are not explicitly calling it through instructions, such as BSR <opr>
or JSR <opr>
. Instead, it is initiated by an event.
</aside>
In particular, an interrupt can be internal or external.
After executing the ISR, the CPU resumes the program execution from the point it left the program. The textbook explains this through an analogy. Refer to the example below if you’re interested.
This can be achieved easily because the address of the instruction to be resumed was saved in memory (the stack). Most microprocessors do this by executing a return from-interrupt instruction.
Figure 6.2 Stack order on entry to interrupts.
As explained above, when the HCS12 processes an interrupt, it goes through the following steps: