Note: The mask column in the table is the AND bitmask (as hexadecimal value) to query the flag(s) within FLAGS register value.
All FLAGS registers contain the condition codes, flag bits that let the results of one machine-language instruction affect another instruction. Arithmetic and logical instructions set some or all of the flags, and conditional jump instructions take variable action based on the value of certain flags. For example, jz (Jump if Zero), jc (Jump if Carry), and jo (Jump if Overflow) depend on specific flags. Other conditional jumps test combinations of several flags.
FLAGS registers can be moved from or to the stack. This is part of the job of saving and restoring CPU context, against a routine such as an interrupt service routine whose changes to registers should not be seen by the calling code. Here are the relevant instructions:
In 64-bit mode, PUSHF/POPF and PUSHFQ/POPFQ are available but PUSHFD/POPFD are not.10: 4–349, 4–432
The lower 8 bits of the FLAGS register is also open to direct load/store manipulation by SAHF and LAHF (load/store AH into flags).
The ability to push and pop FLAGS registers lets a program manipulate information in the FLAGS in ways for which machine-language instructions do not exist. For example, the cld and std instructions clear and set the direction flag (DF), respectively; but there is no instruction to complement DF. This can be achieved with the following assembly code:
By manipulating the FLAGS register, a program can determine the model of the installed processor. For example, the alignment flag can only be changed on the 486 and above. If the program tries to modify this flag and senses that the modification did not persist, the processor is earlier than the 486.
Starting with the Intel Pentium, the CPUID instruction reports the processor model. However, the above method remains useful to distinguish between earlier models.
Intel 64 and IA-32 Architectures Software Developer's Manual (PDF). Vol. 1. May 2012. pp. 3–21. https://download.intel.com/products/processor/manual/253665.pdf#page=93 ↩
Intel 64 and IA-32 Architectures Software Developer's Manual (PDF). Vol. 1. Dec 2016. p. 78. https://software.intel.com/sites/default/files/managed/39/c5/325462-sdm-vol-1-2abcd-3abcd.pdf#page=78 ↩
"Silicon reverse engineering: The 8085's undocumented flags". www.righto.com. Retrieved 2018-10-21. https://www.righto.com/2013/02/looking-at-silicon-to-understanding.html ↩
Intel 64 and IA-32 Architectures Software Developer's Manual, Vol. 1. Dec 2022. pp. 3–16. https://www.intel.com/content/www/us/en/developer/articles/technical/intel-sdm.html ↩
NEC, 16-bit V-Series User's Manual, document no. U11301E, sep 2000, p. 186 https://www.ardent-tool.com/CPU/docs/NEC/V20-V30/v_series.pdf ↩
VIA, PadLock Programming Guide, v1.66, Aug 4, 2005, pp. 7-8. Archived from the original on May 26, 2010. https://web.archive.org/web/20100526054140/http://linux.via.com.tw/support/beginDownload.action?eleid=181&fid=261 ↩
VIA, VIA C3 Processor Alternate Instruction Set Application Note, version 0.24, 2002 - see figure 2 on page 12 and chapter 4 on page 21 for details on the EFLAGS.AI flag. https://www.bitsavers.org/components/viaTechnologies/C3-ais-appnote.pdf ↩
Intel 64 and IA-32 Architectures Software Developer's Manual (PDF). Vol. 2B. May 2012. https://download.intel.com/products/processor/manual/253667.pdf#page=351 ↩