What Happens When IRET Instruction Executes (x86)
The IRET (Interrupt Return) instruction in x86 architecture performs a far return from an interrupt handler or privileged procedure. Actions:
- Pops IP (Instruction Pointer) from stack → resumes execution at return address.
- Pops CS (Code Segment) from stack → restores code segment.
- Pops Flags Register (EFLAGS/RFLAGS) → restores interrupt enable, status flags.
- If privilege level changes: pops SP (Stack Pointer) and SS (Stack Segment) → restores caller's stack.
- Restores CPL (Current Privilege Level) from CS's RPL.
Used at end of ISRs (Interrupt Service Routines) and task gates. Differs from RET by restoring flags and optionally stack pointer for privilege transitions.