Suppose a program is running on a non-pipelined single processor computer system. The computer is connected to an external device that can interrupt the processor asynchronously. The processor needs to execute the interrupt service routine (ISR) to serve the interrupt. The following steps (not necessarily in order) are taken by the processor when the interrupt arrives: The processor saves the content of the program counter. The program counter is loaded with the start address of the ISR. The processor finishes the present instruction. Which ONE of the following is the CORRECT sequence of steps?
Suppose a program is running on a non-pipelined single processor computer system. The computer is connected to an external device that can interrupt the processor asynchronously. The processor needs to execute the interrupt service routine (ISR) to serve the interrupt. The following steps (not necessarily in order) are taken by the processor when the interrupt arrives:
- The processor saves the content of the program counter.
- The program counter is loaded with the start address of the ISR.
- The processor finishes the present instruction.
Choose an Option
Answer
3 --> 1-->2
Theory
ISR: Interrupt Service Routine
An interrupt service routine is a special function that the CPU execute automatically when an interrupt occurs.Why it is needed?
- To execute higher priority events like:
- A keyboard key being pressed
- Any hardware error
- A timer expiring
Steps for handling an interrupt
- Interrupt occurs --> Device signals CPU.
- CPU finishes the current instruction execution.
- CPU saves context --> content of PC, flags, register, etc... [ push to stack ]
- CPU jumps to ISR address --> New PC value loads based on interrupt.
- Execute the ISR to handle the event.
- Restores the saved state [ pop the PC value ].
- Resume the main program from where it is left off.
Solution
For a non-pipelined processor, when an interrupt arrives:
1. Finish the current instruction that being executed. 3️⃣
2. Push PC value onto the stack. 1️⃣
3. New PC value loads based on interrupt. 2️⃣
4. Control transfer to ISR.
5. Serviced the interrupt.
6. Pop the PC value.
7. Resume the main program
So the correct sequence is: 3 --> 1 --> 2
Option © is the correct Answer
1. Finish the current instruction that being executed. 3️⃣
2. Push PC value onto the stack. 1️⃣
3. New PC value loads based on interrupt. 2️⃣
4. Control transfer to ISR.
5. Serviced the interrupt.
6. Pop the PC value.
7. Resume the main program
So the correct sequence is: 3 --> 1 --> 2
Option © is the correct Answer