Interrupts Flashcards
What is an interrupt?
a way to pause execution of a program to run a predefined routine
once the interrupt has been handled the CPU returns to executing the original program
can be used by hardware or software
e.g keyboard and mouse inputs and software crashes
Interrupt register
when an interrupt is thrown the interrupt register is updated
value held within the register is a memory address which holds the program that handles the specific interrupt
add extra step to FDE cycle where the interrupt register is checked
if there is an interrupt we store the current state of the CPU and execute the interrupt
Where are interrupts handled in the FDE cycle?
between execute and fetch
The stack
behaves like a stack of plates
new items are placed at the top of the pile, push
items are taken from the top of the pile, pop
first item in the stack is the last one out (first in last out)
are used all over the place
Storing the CPU state
as dealing with an interrupt the state of all the registers in the CPU before the interrupt are stored in a stack
once finished executing the interrupt we rewrite the registers with the data in the stack
then continue as normal
copy contents of the interrupt register into the PC
follow stages of FDE cycle until the interrupt program is finished
when the interrupt program is finished the CPU state at the top of the stack is resumed
Interrupting the interrupt
while executing the first interrupt another interrupt occurs
still suspend the current program and store the CPU state in the stack
when interrupt B finishes we resume the interrupt A then returns to the original program
Why we have interrupts
often need a computer system to do something right this instant and can’t wait for the scheduler
e.g emergency stop on industrial equipment
or a program has crashed and we need to halt execution
e.g you didn’t add an exit condition in pygame game
are also used when hardware connected to the computer is changed
e.g. when a USB drive is disconnected
needed to halt execution of programs that are now