Transcript for:
Understanding Interrupts and ISRs

in this video we're going to discuss the role of interrupts and the interrupt service routine within the process of the fetch decode and execute cycle so as we know a computer system executes programs and it does this by the processor fetching decoding and executing instructions over and over again now while this is occurring other devices and applications may require the processor's attention they need a way to signal to the processor that they require attention and this is what we call an interrupt you can think about an interrupt with a simple analogy when a student wants to ask a question ideally they would raise their hand signaling to the teacher that they need attention in other words they're generating an interrupt so we can evolve our understanding a little now of the fetch decode execute cycle to include an additional step fetch decode execute and then check if there are any new interrupts to be handled now interrupts present us with a bit of a problem the processor will need to stop executing its current program to run the code for the interrupt known as an interrupt service routine but remember the cpu contains registers that hold data currently being handled including the program counter the memory location of the next instruction the current instruction register the actual instruction that's currently being carried out and various other registers like the mar and mdr the interrupt service routine is simply a program with its own set of instructions that need to be fetched decoded and executed to carry out the operations of the interrupt that means the contents of the program counter need to be changed to point to the address for the first instruction of the interrupt well that's fine but when the interrupts complete how will the processor know to continue the previous executing program it had to suspend well when an interrupt is received the current values held in the registers are copied into a data structure in memory known as the stack these values are pushed onto the stack in a stack frame effectively saving them for later retrieval the interrupt can now be executed and once the interrupt is complete we pop the frame off the top of the stack by using this stack it allows us to retrieve the previous values for the original program load them back into the process of registers and carry on executing where we left off now we could also have an interrupt which has been interrupted now in this situation an interrupt come along to the previous program has been suspended and the data for it has been stored in a stack frame the interrupt is now executing so let's call this interrupt service routine a while the processor executes interrupt service routine a another higher priority interrupt comes along the beauty of the stack data structure is it handles this perfectly fine we simply suspend interrupt service routine a and push the register's contents onto the top of the stack now start executing interrupt service routine b once interrupt service routine b has completed executing we pop the frame that's on the top of the stack and in doing so we retrieve the values for interrupt service routine a load them back into the registers and carry on executing it once interrupt service routine a has completed executing we pop the frame that's on the top of the stack and in doing so we retrieve the previous values for the original program load them back into registers and carry on exactly where we left off now as i've kind of indicated here interrupt service routines have a priority and these priorities are important interrupts always have a higher priority than normal standard programs for example say your computer starts responding and you want to open the task manager or shut your pc down the processor in this situation is caught in a problem which it cannot resolve on its own without being to interrupt the cycle by pressing ctrl or delete or the power button the only way to recover from this situation would be to pull the plug now in reality the number of different interrupts that different pc architectures understand is wide and varied and quite complex but what we've summarized here are some of the typical interrupts that you might like to remember for the exam and also the sort of categories they fall into so having watched this video you should be able to answer the following key question what causes an interrupt to the cpu and how is it handled [Music] you