cli

Clear Interrupt Flag

CLI

Disables maskable hardware interrupts.

Details

Clears the Interrupt Flag (IF) to 0, disabling maskable hardware interrupts (IRQ0–IRQ15) but not non-maskable interrupts (NMI) or exceptions. This instruction is privileged and requires CPL=0; execution in user mode raises a #GP exception. Available in protected and 64-bit modes.

Pseudocode Operation

IF ← 0  // Requires CPL = 0 (kernel mode)

Example

CLI

Encoding

Binary Layout
FA
+0
 
Format Legacy
Opcode FA
Extension Base

Operands

Reference (Intel® SDM)

Instruction Forms

Opcode Instruction Op/En 64/32-bit Mode CPUID Description
FA CLI ZO Valid Valid Clear interrupt flag; interrupts disabled when interrupt flag cleared.

Description

In most cases, CLI clears the IF flag in the EFLAGS register and no other flags are affected. Clearing the IF flag causes the processor to ignore maskable external interrupts. The IF flag and the CLI and STI instruction have no effect on the generation of exceptions and NMI interrupts. Operation is different in two modes defined as follows: • PVI mode (protected-mode virtual interrupts): CR0.PE = 1, EFLAGS.VM = 0, CPL = 3, and CR4.PVI = 1; • VME mode (virtual-8086 mode extensions): CR0.PE = 1, EFLAGS.VM = 1, and CR4.VME = 1. If IOPL < 3 and either VME mode or PVI mode is active, CLI clears the VIF flag in the EFLAGS register, leaving IF unaffected. Table 3-7 indicates the action of the CLI instruction depending on the processor operating mode, IOPL, and CPL. Table 3-7. Decision Table for CLI Results Mode IOPL CLI Result Real-address X1 IF = 0 ≥ CPL IF = 0 Protected, not PVI2 < CPL #GP fault 3 IF = 0 Protected, PVI3 0–2 VIF = 0 3 IF = 0 Virtual-8086, not VME3 0–2 #GP fault 3 IF = 0 Virtual-8086, VME3 0–2 VIF = 0

Operation

IF CR0.PE = 0
THEN IF := 0; (* Reset Interrupt Flag *)
ELSE
IF IOPL ≥ CPL (* CPL = 3 if EFLAGS.VM = 1 *)
THEN IF := 0; (* Reset Interrupt Flag *)
ELSE
IF VME mode OR PVI mode
THEN VIF := 0; (* Reset Virtual Interrupt Flag *)
ELSE #GP(0);
FI;
FI;
FI;

Flags Affected

Either the IF flag or the VIF flag is cleared to 0. Other flags are unaffected.

Exceptions

Protected Mode Exceptions

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

Real-Address Mode Exceptions

#UD If the LOCK prefix is used.

Virtual-8086 Mode Exceptions

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

Compatibility Mode Exceptions

Same exceptions as in protected mode.

64-Bit Mode Exceptions

Same exceptions as in protected mode. CLI—Clear Interrupt Flag Vol. 2A 3-149