📖 Explanation
When an interrupt is issued, the processor follows a specific sequence to handle it and then resume the original task. Let's break down the process:
-
(Q) The processor finishes the execution of the current instruction. The CPU checks for interrupts only after completing the current instruction. It cannot suspend an instruction midway.
-
(P) The processor pushes the process status of L onto the control stack. Before servicing the interrupt, the processor must save the current state of process L (including the Program Counter and other registers) so that it can be resumed later without losing its context. This state is saved on the stack.
-
(T) The processor loads the new PC value based on the interrupt. The processor determines the type of interrupt and uses the interrupt vector table to find the starting address of the corresponding Interrupt Service Routine (ISR). This address is loaded into the Program Counter (PC).
-
(R) The processor executes the interrupt service routine. With the PC now pointing to the ISR, the processor begins executing the ISR's code to handle the specific event that caused the interrupt.
-
(S) The processor pops the process status of L from the control stack. After the ISR completes its task, the saved state of process L is restored by popping it from the stack back into the processor's registers. The PC is restored to the address of the next instruction in process L.
This sequence ensures that the interrupt is handled correctly and the interrupted process can resume exactly where it left off. The correct order is Q, P, T, R, S.