5.1.3 Interrupt service routines

When the processor jumps to execute code to respond to an interrupt, it actually makes a call. In other words, the processor first saves the address of the next instruction onto the stack, then it jumps to the code to respond to an interrupt.

This is necessary because after the processor responds to an interrupt, it needs to know how to resume execution of whatever it was doing when it got interrupted.

Right before the processor saves the address of the instruction to resume to, it also disables interrupt. This is done automatically. This practice is common to most processors and MCUs because it is tricky to handle another interrupt when a processor is in the process of responding to the first one.

An ISR is typically short and does not take much time to complete. At the completion of an ISR, a special return instruction is used. This instruction returns to the saved address on the stack. This allows the processor resume execution of code that was interrupted. However, this special instruction also reenables interrupt after the address to resume to is retrieved.

This way, even if there are multiple devices request interrupts, we only need enough space to save one single instruction address.

Copyright © 2006-02-15 by Tak Auyeung