Flags Register

The flags register (RFLAGS) is a 64 bit bitfield register, of which the first 21 are defined. It contains a few bits of information that are accessible to any running program, but not all of them are writeable.

This register is accessible through three overlapping "registers": FLAGS for the lowest 16 bits, EFLAGS for the lower 32, and RFLAGS for the whole register. Despite the fact that only bits 0 through 21 are defined, RFLAGS exists for consistency with the rest of the x86-64 general purpose register set.

List of Fields

In ascending order (least significant bit to most significant), RFLAGS contains the following bits of information:

CF - Carry Flag (bit 0)
Indicates if an arithmetic operation generated a carry out of (or borrowed into) the most significant bit of the result. It signals an overflow or underflow for unsigned arithmetic.
Some other (non-arithmetic) instructions overload this bit for various results.
VF - "V" Flag (bit 1)
Reserved. Always set.
Historically, this undocumented flag signaled an overflow or underflow for 8 bit signed arithmetic.[vkFlags]
PF - Parity Flag (bit 2)
Indicates if the least significant byte of a result contains an even number of set ("1") bits (indicating even parity), and cleared otherwise. Due to the result only being based on the least significant byte, it is considered obsolete and does not have much usage today. However, in situations where it is used, there exists two "jump" instructions: JP/JPE - Jump If Parity (Even) and JNP/JPO - Jump If No Parity (Odd).
Some other (non-arithmetic) instructions overload this bit for various results.
(bit 3)
Reserved. Always cleared.
AF - Auxiliary Carry Flag (bit 4)
Sometimes referred to as the "Half Carry Flag", it is similar to the carry flag (bit 0), but always operating on overflow or underflow with bit 3 of the result. This obsolete flag is used for the obsolete BCD instructions such as AAA (ASCII Adjust AL After Addition).
Some other (non-arithmetic) instructions overload this bit for various results.
KF - "K" Flag (bit 5)
Reserved. Always cleared.
Historically, this undocumented flag would signal that the first value of a signed comparison is smaller than the second.[vkFlags]
ZF - Zero Flag (bit 6)
As the name imples, this flag is set if the result of an arithmetic operation is zero, and cleared otherwise.
Some other (non-arithmetic) instructions overload this bit for various results.
SF - Sign Flag (bit 7)
As the name imples, this flag is set if the most significant bit of an arithmetic operation is set, and cleared otherwise.
Some other (non-arithmetic) instructions overload this bit for various results.
TF - Trap Flag (bit 8)
When set, single-step debugging of the executing thread is enabled.
IF - Interrupt Enable Flag (bit 9)
When set, the processor will ignore maskable interrupts. Non-maskable interrupts are uninhibited by this flag, and will execute regardless.
DF - Direction Flag (bit 10)
Controls the direction of string instructions. When set, the instructions will operate by decrementing the address each iteration (for processing from high to low address). When cleared, they will operate by incrementing it (from low to high address).
OF - Overflow Flag (bit 11)
Similar to the carry flag (bit 0), except that this flag indicates an overflow out of (or borrow into) the second most significant bit of the result. It signals an overflow or underflow for signed arithmetic.
Some other (non-arithmetic) instructions overload this bit for various results.
IOPL - I/O Privilege Level (bits 12 and 13)
Indicates the processor ring of a thread. A zero indicates the most privilege, while a three indicates the least.
On the 8086 and 80186, bit 12 is always set, and bit 13 is always cleared.
NT - Nested Task (bit 14)
Indicates if the current thread is linked to a previously executed thread.
On the 8086 and 80186, this is always set.
(bit 15)
Reserved. Always cleared.
On the 8086 and 80186, this is, instead, always set.
RF - Resume Flag (bit 16)
Controls if the processor will respond to debug exceptions.
VM - Virtual-8086 Mode (bit 17)
Controls if the processor is in Virtual-8086 mode (inside of Protected Mode).
AC - Alignment Check / Access Control Flag (bit 18)
A user-controllable flag that can mask the AM bit in the CR0 register. If both of these flags are set, alignment checking is enforced on all memory accesses.
VIF - Virtual Interrupt Flag (bit 19)
TODO
VIP - Virtual Interrupt Pending (bit 20)
TODO
ID - "ID" Flag (bit 21)
Provides a method of checking for support of the CPUID (CPU Identification) instruction. On the 80486 and older processors, attempts to set this bit will be unsuccessful as the processor will clear it upon load into the register. However, Pentium (and newer) processors (which support CPUID) will allow setting and clearing this bit.
(bits 22 and up)
Reserved. Always cleared.

References