Explain the sequence of steps that occurs during interrupt processing
Answers
Answered by
7
The challenge with an interrupt, unlike a subroutine, is that some other code that is not part of the current program may be called and change the state of the CPU (registers). Think about writing code in assembly. Many of the registers were general purpose and as a programmer you mapped them into uses that made sense to your program. For instance, suppose you had a counter that determined program state and every aspect of the program used it constantly. You may choose to store this in a register and never use that register for any other purpose. In that case you wouldn't need to save it on the stack during a subroutine. But, if an interrupt request occurred that code may overwrite that register so to return the CPU to the same state, the registers are pushed on the stack with PC+1, the PC is loaded with the address of the interrupt code, and the registers are restored from the stack with the PC being the last one, returning the execution point to the next instruction in the original program.
An can interrupt occur at any time. The only way to maintain the CPU state the program is expecting is to have the hardware save the registers. For this reason it is built into the architecture in the CPU. When the CPU detects the interrupt it must save the registers in order to return the CPU to the same state as it was before the interrupt occurred.
As Alec Cawley said, it depends on the architecture. In simple systems the CPU, as part of its logic, pushes all the registers on the stack including the PC+1, and then "jumps to interrupt" the interrupt routine normally using a vector table. After the interrupt routine runs the "return from interrupt" pulls the registers in reverse order so they are restored. Back when a CPU had only had 3-4 registers this was pretty much how they all worked. But this took time and made interrupts slow even on those older chips because even though they had fewer registers they also ran much slower. The Motorola 6800 did this, for instance, pushing the PC, index register, registers A and B, and bits form the status register allowing the interrupt routine to use all registers.
Soon CPUs had more registers and pushing them all became too slow. Look at the number of registers on a modern x86_64 CPU
An can interrupt occur at any time. The only way to maintain the CPU state the program is expecting is to have the hardware save the registers. For this reason it is built into the architecture in the CPU. When the CPU detects the interrupt it must save the registers in order to return the CPU to the same state as it was before the interrupt occurred.
As Alec Cawley said, it depends on the architecture. In simple systems the CPU, as part of its logic, pushes all the registers on the stack including the PC+1, and then "jumps to interrupt" the interrupt routine normally using a vector table. After the interrupt routine runs the "return from interrupt" pulls the registers in reverse order so they are restored. Back when a CPU had only had 3-4 registers this was pretty much how they all worked. But this took time and made interrupts slow even on those older chips because even though they had fewer registers they also ran much slower. The Motorola 6800 did this, for instance, pushing the PC, index register, registers A and B, and bits form the status register allowing the interrupt routine to use all registers.
Soon CPUs had more registers and pushing them all became too slow. Look at the number of registers on a modern x86_64 CPU
Answered by
13
The sequence of steps that occurs during interrupt processing are:
- The contents of flag register the CS and IP are pushed on to the stack.
- To disable single steps and INTR interupts the TF and IF are cleared.
- The program then jumps to the beginning or starting adsress of ISS.
- When the IRET executes last line that are also ISS last line the CS and IP flag contents are popped from stack and placed in appropriate registers.
- Once the flags are restored then Tf and IF values are also restored to their previos values.
- Then it continues the process which was doing before interrupt.
Similar questions