FLAGS register (computing)

From Wikipedia, the free encyclopedia
Jump to: navigation, search
This article discusses the flag register specific to the x86 architecture. For a general discussion about flag registers, see status register (condition code register).

The FLAGS register is the status register in Intel x86 microprocessors that contains the current state of the processor. This register is 16 bits wide. Its successors, the EFLAGS and RFLAGS registers, are 32 bits and 64 bits wide, respectively. The wider registers retain compatibility with their smaller predecessors.

Intel x86 FLAGS register
Bit # Abbreviation Description Category[1]
FLAGS
0 CF Carry flag S
1 1 Reserved  
2 PF Parity flag S
3 0 Reserved  
4 AF Adjust flag S
5 0 Reserved  
6 ZF Zero flag S
7 SF Sign flag S
8 TF Trap flag (single step) X
9 IF Interrupt enable flag C
10 DF Direction flag C
11 OF Overflow flag S
12, 13 1,1 / IOPL I/O privilege level (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 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  
  1. ^ S: Status flag
    C: Control flag
    X: System flag

[edit] Determination of the Processor-Type through flags

Testing if bits in the Flags-register exist, which only exist on certain processors is a method for determining what Processor 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 standard one for distinguishing the processors from 186 to 586. The 8086 and the 186 can be distinguished by a CL-bitshift of 32 (which has no effect 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 return values.

[edit] Examples

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

mov bx, 400h ; Set the DF fl
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.

[edit] See also


Personal tools
Namespaces
Variants
Actions
Navigation
Interaction
Toolbox
Print/export
Languages