Intel 64 and IA-32 Architectures Software Developers Manual Volume 1, Basic Architecture
Vol. 1 7-29
PROGRAMMING WITH GENERAL-PURPOSE INSTRUCTIONS
uses the flag in an operation is executed. They are also used in conjunction with the
rotate-with-carry instructions (RCL and RCR).
The STD (set direction flag) and CLD (clear direction flag) instructions allow the DF
flag in the EFLAGS register to be modified directly. The DF flag determines the direc-
tion in which index registers ESI and EDI are stepped when executing string
processing instructions. If the DF flag is clear, the index registers are incremented
after each iteration of a string instruction; if the DF flag is set, the registers are
decremented.
7.3.14.2 EFLAGS Transfer Instructions
The EFLAGS transfer instructions allow groups of flags in the EFLAGS register to be
copied to a register or memory or be loaded from a register or memory.
The LAHF (load AH from flags) and SAHF (store AH into flags) instructions operate on
five of the EFLAGS status flags (SF, ZF, AF, PF, and CF). The LAHF instruction copies
the status flags to bits 7, 6, 4, 2, and 0 of the AH register, respectively. The contents
of the remaining bits in the register (bits 5, 3, and 1) are undefined, and the contents
of the EFLAGS register remain unchanged. The SAHF instruction copies bits 7, 6, 4,
2, and 0 from the AH register into the SF, ZF, AF, PF, and CF flags, respectively in the
EFLAGS register.
The PUSHF (push flags), PUSHFD (push flags double), POPF (pop flags), and POPFD
(pop flags double) instructions copy the flags in the EFLAGS register to and from the
stack. The PUSHF instruction pushes the lower word of the EFLAGS register onto the
stack (see Figure 7-11). The PUSHFD instruction pushes the entire EFLAGS register
onto the stack (with the RF and VM flags read as clear).
The POPF instruction pops a word from the stack into the EFLAGS register. Only bits
11, 10, 8, 7, 6, 4, 2, and 0 of the EFLAGS register are affected with all uses of this
instruction. If the current privilege level (CPL) of the current code segment is 0 (most
privileged), the IOPL bits (bits 13 and 12) also are affected. If the I/O privilege level
(IOPL) is greater than or equal to the CPL, numerically, the IF flag (bit 9) also is
affected.
Figure 7-11. Flags Affected by the PUSHF, POPF, PUSHFD, and POPFD Instructions
PUSHFD/POPFD
PUSHF/POPF
31
29
30 28 27
26 25
24
23
22
21 20 19
18
17
16
0
R
F
I
D
A
C
V
M
15
13
14 12 11
10 9
8
7
6
543
2
10
0
C
F
A
F
P
F
1
D
F
I
F
T
F
S
F
Z
F
N
T
00
00
0000000
V
I
P
V
I
F
O
F
I
O
P
L