Vol. 1 7-21
PROGRAMMING WITH GENERAL-PURPOSE INSTRUCTIONS
7.3.12
Enter and Leave Instructions
The ENTER and LEAVE instructions provide machine-language support for procedure calls in block-structured
languages, such as C and Pascal. These instructions and the call and return mechanism that they support are
described in detail in Section 6.5, “Procedure Calls for Block-Structured Languages”.
7.3.13
Flag Control (EFLAG) Instructions
The Flag Control (EFLAG) instructions allow the state of selected flags in the EFLAGS register to be read or modi-
fied. For the purpose of this discussion, these instructions are further divided into subordinate subgroups of
instructions that manipulate:
•
Carry and direction flags
•
The EFLAGS register
•
Interrupt flags
7.3.13.1 Carry and Direction Flag Instructions
The STC (set carry flag), CLC (clear carry flag), and CMC (complement carry flag) instructions allow the CF flag in
the EFLAGS register to be modified directly. They are typically used to initialize the CF flag to a known state before
an instruction that 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 direction 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 iter-
ation of a string instruction; if the DF flag is set, the registers are decremented.
7.3.13.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 unaffected, 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
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 5 4 3 2 1 0
0
C
F
A
F
P
F 1
D
F
I
F
T
F
S
F
Z
F
N
T
0
0
0 0 0 0 0 0 0 0 0
V
I
P
V
I
F
O
F
I
O
P
L