Assembly: Flags

Posted March 3, 2006 by William_Wilson in Computer programming

The following tech recipe explains EFlags register, including what they are, what they do, and when they are set.


The flags are located in a single 32-bit register (EFlags), each a single bit and thus holding a value of 1 true or 0 false.

I will list the flags by name, location in the register, and use.
*Location will be a bit from zero to 31.
00: CF Carry Flag – becomes one if an addition, multiplication, AND, OR, etc results in a value larger than the register meant for the result
02: PF Parity Flag – becomes 1 if the lower 8-bits of an operation contains an even number of 1 bits
04: AF Auxiliary Flag – set on a carry or borrow to the value of the lower order 4 bits
06: ZF Zero Flag – becomes 1 if an operation results in a 0 writeback or 0 register
07: SF Sign Flag – is 1 if the value saved is negative, 0 for positive
08: TF Trap Flag – allows for the stopping of code within a segment (allows for single stepping/debugging in programming)
09: IF Interrupt Flag – When this flag is set, the processor begins “listening” for external interrupts.
10: DF Direction Flag – determines the direction to move through the code (specific to repeat instructions)
11: OF Overflow Flag – becomes 1 if the operation is larger than available space to write (e.g., addition which results in a number >32-bits)
12-13: IOPL I/O Privilege Level – Read, Write, or a combination of the 2 (2-bit register)
14: NT Nested Task – becomes 1 when calls within a program are made
16: RF Resume Flag – stays 1 upon a break and stays that way until a given ‘release’ or resume operation/command occurs
17: VM Virtual Machine 8086 – becomes a 1 if the processor is to simulate the 8086 processor (16-bit)
18: AC Alignment Check – checks that a file or command is not breaking its privilege level
19: VIF Virtual Interupt Flag – almost always set in protected mode, listening for internal and assembling interrupts
20: VIP Virtual Interrupt Pending – 1 if a virtual interrupt has yet to occur
21: ID ID Flag – is set if a CPU identification check is pending (used in some cases to ensure valid hardware)

*Missing bits are not mistakes. Some flags temporarily use 2+ bits and use neighbors to hold temporary values. Also, there are 17 necessary flags, so 32-bits is the smallest register to hold them. (2^5)

NOTE: A single operation may change or set multiple flags. Even those which seem independent may be nullified by specific operations.

The flags are used in many operations to save clock cycles and determine results without actually having to do read operations.
examples: jmp command (can be modified to a conditional jump, based on a flags value)

Questions/Comments: [email protected]
-William. ยง (marvin_gohan)

The Conversation

Follow the reactions below and share your own thoughts.