Clear Interrupt Enable Flag

Encoding

EncodingOperand
zoNone

Description

The CLI instruction clears EFLAGS.IF (the interrupt enable flag). Doing so will cause the processor to ignore maskable (external) interrupts.

Operation depends on the operating mode and the current privilege level of the executing code. In addition, two seprate conditions regarding virtual interrupts are used:

VME Mode (Virtual-8086 Mode Extensions)
If in Virtual-8086 Mode and CR4.VME is 1.
PVI Mode (Protected Mode Virtual Interrupts)
If in Protected Mode, CPL is 3, and CR4.PVI is 1.

With those two definitions, operation follows this truth table:

ModeIOPLCLI Operation
Real Moden/aIF ← 0
Virtual-8086 Mode, not VME0-2#GP fault
3IF ← 0
Virtual-8086 Mode, VME0-2VIF ← 0
3IF ← 0
Protected Mode, not PVI<CPL#GP fault
≥CPLIF ← 0
Protected Mode, PVI0-2VIF ← 0
3IF ← 0

Operation

public void CLI()
{
    if (!CR0.PE)
    {
        // real mode
        EFLAGS.IF = 0;
        return;
    }

    if (IOPL > CPL)
    {
        // NOTE: CPL is 3 in virtual-8086 mode
        EFLAGS.IF = 0;
        return;
    }

    bool vme = EFLAGS.VM && CR4.VME;
    bool pvi = !EFLAGS.VM && CPL > 3 && CR4.PVI;
    if (vme || pvi)
        EFLAGS.VIF = 0;
    #GP(0);
}

Flags Affected

CF (carry flag)
Unmodified.
PF (parity flag)
Unmodified.
AF (auxiliary flag)
Unmodified.
ZF (zero flag)
Unmodified.
SF (sign flag)
Unmodified.
IF (interrupt enable flag)
Cleared if in Real Mode or if IOPL is greater than or equal to CPL.
OF (overflow flag)
Unmodified.
VIF (virtual interrupt flag)
Cleared if in VME or PVI submodes and EFLAGS.IF is unmodified.

Exceptions

Real-Address Mode

#UD
  • If the
  • LOCK
  • prefix is used.

Virtual-8086 Mode

#UD
  • If the
  • LOCK
  • prefix is used.
#GP(0)
  • If
  • IOPL
  • is less than
  • 3
  • and the
  • VME
  • submode is not active.

Protected Mode

#UD
  • If the
  • LOCK
  • prefix is used.
#GP(0)
  • If CPL is greater than IOPL but also less than 3.
  • If CPL is greater than IOPL and the PVI submode is not active.

Compatibility Mode

#UD
  • If the
  • LOCK
  • prefix is used.
#GP(0)
  • If CPL is greater than IOPL but also less than 3.
  • If CPL is greater than IOPL and the PVI submode is not active.

Long Mode

#UD
  • If the
  • LOCK
  • prefix is used.
#GP(0)
  • If CPL is greater than IOPL but also less than 3.
  • If CPL is greater than IOPL and the PVI submode is not active.