FLAGS register

FLAGS register

From Wikipedia, the free encyclopedia

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.

Contents

Flags

Intel x86 FLAGS register[1]
Bit #AbbreviationDescriptionCategory
FLAGS
0CFCarry flagStatus
1 Reserved 
2PFParity flagStatus
3 Reserved 
4AFAdjust flagStatus
5 Reserved 
6ZFZero flagStatus
7SFSign flagStatus
8TFTrap flag (single step)Control
9IFInterrupt enable flagControl
10DFDirection flagControl
11OFOverflow flagStatus
12-13IOPLI/O privilege level (286+ only), always 1 on 8086 and 186System
14NTNested task flag (286+ only), always 1 on 8086 and 186System
15 Reserved, always 1 on 8086 and 186, always 0 on later models 
EFLAGS
16RFResume flag (386+ only)System
17VMVirtual 8086 mode flag (386+ only)System
18ACAlignment check (486SX+ only)System
19VIFVirtual interrupt flag (Pentium+)System
20VIPVirtual interrupt pending (Pentium+)System
21IDAble to use CPUID instruction (Pentium+)System
22 Reserved 
23 Reserved 
24 Reserved 
25 Reserved 
26 Reserved 
27 Reserved 
28 Reserved 
29 Reserved 
30 Reserved 
31 Reserved 
RFLAGS
32-63 Reserved 

Use

The POPF, POPFD, and POPFQ instructions read from the stack the first 16, 32, and 64 bits of the flags register, respectively. POPFD was introduced with the i386 architecture and POPFQ with the x64 architecture. In 64-bit mode, PUSHF/POPF and PUSHFQ/POPFQ are available but not PUSHFD/POPFD.[2]

The following assembly code changes the direction flag (DF):

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, 400h ; toggle 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 instructions are used to clear and set the direction flag, respectively. Some instructions in assembly language use the FLAGS register. The conditional jump instructions use certain flags to compute. For example, jz uses the zero flag, jc uses the carry flag and jo uses the overflow flag. Other conditional instructions look at combinations of several flags.

Determination of processor type

Testing if certain bits in the FLAGS register are changeable allows determining what kind of processor is installed. For example, the alignment flag can only be changed on the 486 and above, so if it can be changed then the CPU is a 486 or higher. These methods of processor detection were made obsolete by the CPUID instruction, which was first included in the Intel Pentium.

See also

References



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值