FLAGS register (computing)
Encyclopedia
The FLAGS register
Processor register
In computer architecture, a processor register is a small amount of storage available as part of a CPU or other digital processor. Such registers are addressed by mechanisms other than main memory and can be accessed more quickly...

 is the status register
Status register
A status register or flag register is a collection of flag bits for a processor. An example is the FLAGS register of the x86 architecture....

 in Intel x86 microprocessor
Microprocessor
A microprocessor incorporates the functions of a computer's central processing unit on a single integrated circuit, or at most a few integrated circuits. It is a multipurpose, programmable device that accepts digital data as input, processes it according to instructions stored in its memory, and...

s that contains the current state of the processor. This register is 16 bits
16-bit
-16-bit architecture:The HP BPC, introduced in 1975, was the world's first 16-bit microprocessor. Prominent 16-bit processors include the PDP-11, Intel 8086, Intel 80286 and the WDC 65C816. The Intel 8088 was program-compatible with the Intel 8086, and was 16-bit in that its registers were 16...

 wide. Its successors, the EFLAGS and RFLAGS registers, are 32 bits
32-bit
The range of integer values that can be stored in 32 bits is 0 through 4,294,967,295. Hence, a processor with 32-bit memory addresses can directly access 4 GB of byte-addressable memory....

 and 64 bits
64-bit
64-bit is a word size that defines certain classes of computer architecture, buses, memory and CPUs, and by extension the software that runs on them. 64-bit CPUs have existed in supercomputers since the 1970s and in RISC-based workstations and servers since the early 1990s...

 wide, respectively. The wider registers retain compatibility with their smaller predecessors.
Intel x86 FLAGS register
Bit # Abbreviation Description Category
FLAGS
0 CF Carry flag
Carry flag
In computer processors the carry flag is a single bit in a system status register used to indicate when an arithmetic carry or borrow has been generated out of the most significant ALU bit position...

 
S
1 1 Reserved  
2 PF Parity flag
Parity flag
In computer processors the parity flag indicates if the number of set bits is odd or even in the binary representation of the result of the last operation. It is normally a single bit in a processor status register....

 
S
3 0 Reserved  
4 AF Adjust flag
Adjust flag
The Adjust flag is a flag stored in the FLAGS register on all x86 compatible CPUs. It is bit 4. It is used to indicate when an arithmetic carry or borrow has been generated out of the 4 least significant bits. It is primarily used in BCD arithmetics....

 
S
5 0 Reserved  
6 ZF Zero flag
Zero flag
The Zero Flag is a single bit flag that is a central feature on most conventional CPU architectures . It is often stored in a dedicated register, typically called status register or flag register, along with other flags...

 
S
7 SF Sign flag  S
8 TF Trap flag
Trap flag
A trap flag permits operation of a processor in single-step mode. If such a flag is available, debuggers can use it to step through the execution of a computer program.-Single-step interrupt:...

 (single step)
X
9 IF Interrupt enable flag
IF (x86 flag)
IF is a system flag bit in the x86 architecture's FLAGS register, which determines whether or not the CPU will handle maskable hardware interrupts....

 
C
10 DF Direction flag
Direction flag
The Direction Flag is a flag that controls the left-to-right or right-to-left direction of string processing stored in the FLAGS register on all x86 compatible CPUs. It is bit 10....

 
C
11 OF Overflow flag
Overflow flag
In computer processors, the overflow flag is usually a single bit in a system status register used to indicate when an arithmetic overflow has occurred in an operation, indicating that the signed two's-complement result would not fit in the number of bits used for the operation...

 
S
12, 13 1,1 / IOPL I/O privilege level
IOPL
The IOPL flag is a flag found on all IA-32 compatible x86 CPUs. It occupies bits 12 and 13 in the FLAGS register. In protected mode and long mode, it shows the I/O privilege level of the current program or task...

 (286+ only) always 1 on 8086 and 186
X
14 1 / NT Nested task flag (286+ only) always 1 on 8086 and 186 X
15 1 on 8086 and 186, should be 0 above Reserved  
EFLAGS
16 RF Resume flag (386+ only) X
17 VM Virtual 8086 mode
Virtual 8086 mode
In the 80386 microprocessor and later, virtual 8086 mode allows the execution of real mode applications that are incapable of running directly in protected mode while the processor is running a protected mode operating system.VM86 mode uses a segmentation scheme identical to that of real mode In...

 flag (386+ only)
X
18 AC Alignment check (486SX+ only) X
19 VIF Virtual interrupt flag (Pentium+) X
20 VIP Virtual interrupt pending (Pentium+) X
21 ID Able to use CPUID instruction (Pentium+) X
22 0 Reserved  
23 0 Reserved  
24 0 Reserved  
25 0 Reserved  
26 0 Reserved  
27 0 Reserved  
28 0 Reserved  
29 0 Reserved  
30 0 Reserved  
31 0 Reserved  
RFLAGS
32-63 0 Reserved  


Determination of the Processor-Type through flags

Testing if bits in the Flags-register exist, which only exist on certain processors is a methode for determining what Prozessor is installed (For example the Alignment-Flag is present on 486 and above, so if it could be toggled the CPU is a 486 or higher else 386). This Method is the standart one for destinguishing the processors from 186 to 586. The 8086 and the 186 can be distinguished by a CL-bitshift
SHL
SHL may refer to:*The x86 command for shift left*Schmidt hammer lassen, architecture firm*Shillong Airport, IATA code SHL*SHL Group Ltd, a recruitment firm*Southern Hockey League*Shillong Airport*SHL - Polish motorcycle brand between 1930s-1970...

 of 32 (which has no effekt on 186 and above cause only the lower 5 bits are significant). The 586 and the Processors above can be distinguished by an entry in the CPUID
CPUID
The CPUID opcode is a processor supplementary instruction for the x86 architecture. It was introduced by Intel in 1993 when it introduced the Pentium and SL-Enhanced 486 processors....

 returnvalues.

Examples

Below is an example for changing the flag in DF (direction flag)


mov bx, 400h ; Set the DF flag
pushf ; Pushes the current flags onto the stack
pop ax ; Pop the flags from the stack into ax register
push ax ; Push them back onto the stack for storage
xor ax, bx ; XOR dest, src | Used for toggling the DF flag only, keep the rest of the flags
push ax ; Push again to add the new value to the stack
popf ; Pop the newly pushed into the FLAGS register
... Code here ...
popf ; Pop the old FLAGS back into place

In practical software, the cld and std mnemonics are used to clear and set the direction flag, respectively.

See also

  • Status register
    Status register
    A status register or flag register is a collection of flag bits for a processor. An example is the FLAGS register of the x86 architecture....

  • Flag byte
    Flag byte
    A flag word is a generic term for a word used to indicate conditions within a binary computer. In particular, the byte can be used to show up to 8 discrete conditions...

  • Flag (computing)
    Flag (computing)
    In computer programming, flag can refer to one or more bits that are used to store a binary value or code that has an assigned meaning, but can refer to uses of other data types...

  • Program status word
    Program status word
    The Program status word is an IBM System/360 architecture and successors control register which performs the function of a Status register in other architectures, and more....

  • Control register
    Control register
    A control register is a processor register which changes or controls the general behavior of a CPU or other digital device. Common tasks performed by control registers include interrupt control, switching the addressing mode, paging control, and coprocessor control.-CR0:The CR0 register is 32 bits...

  • x86
  • x86 assembly language
    X86 assembly language
    x86 assembly language is a family of backward-compatible assembly languages, which provide some level of compatibility all the way back to the Intel 8008. x86 assembly languages are used to produce object code for the x86 class of processors, which includes Intel's Core series and AMD's Phenom and...

  • x86 instruction listings
    X86 instruction listings
    The x86 instruction set has been extended several times, introducing wider registers and datatypes and/or new functionality.-x86 integer instructions:...

The source of this article is wikipedia, the free encyclopedia.  The text of this article is licensed under the GFDL.
 
x
OK