interrupts Flashcards
what is an interrupt
An interrupt is a signal to the processor that requires immediate attention
what is polling
- a way to signal the CPU
- the cpu checks with each device whether it needs attention
- this is inefficient, if a device did not need attention, there was no point checking it.
when are interrupts serviced
after code is executed/before another instruction is fetched
problems with the interrrupt service routine and how its fixed
- Interrupt occurs, forcing the CPU to stop executing the current program.
- The Program Counter (PC) holds the address of the next instruction in the original program.
- If the interrupt causes the CPU to jump to the ISR without saving the PC:
- The CPU loses track of where to return after the ISR.
- This disrupts the original program’s flow, causing errors or crashes.
how to fix the interrupt service routine problem using a stack
Solution Using a Stack:
Interrupt occurs:
Before the ISR is executed, the CPU pushes (saves) the current PC (and other important registers) onto the stack.
ISR execution:
The CPU changes the PC to point to the ISR’s starting address.
The ISR is executed to handle the interrupt.
After ISR completes:
The CPU pops (restores) the PC and other saved data from the stack.
Resume normal execution:
The original PC value is restored, allowing the CPU to continue the interrupted program at the correct point.
The program resumes seamlessly as if no interrupt occurred.
types of interrupts/ when do they happen
- hardware
- software
- if an illegal instruction is encountered
- arithmetic overflow
- if buffers nearly empty
Why must the CPU save the volatile environment when an interrupt occurs?
- To preserve the current state of the program, so it can resume from where it left off after handling the interrupt.
What is included in the volatile environment?
The program counter (PC), registers, and status flags.
What would happen if the CPU didn’t save the volatile environment before servicing an interrupt?
- The CPU would lose track of where it was in the program, leading to errors or data corruption.
What is a maskable interrupt?
An interrupt that can be disabled or delayed by the CPU.
What is a non-maskable interrupt (NMI)?
A high-priority interrupt that cannot be disabled and must be handled immediately.
Give an example of a hardware interrupt.
Give an example of a hardware interrupt.
How do software interrupts differ from hardware interrupts?
- Software interrupts are triggered by programs (e.g., errors or system calls), while hardware interrupts come from external devices.
How does the CPU decide which ISR to run?
The CPU uses an interrupt vector table, which maps each interrupt to its corresponding ISR.
How does the CPU know where to return after handling an interrupt?
- The CPU saves the program counter (PC) and other important states before executing the ISR, then restores them afterward.