User's Manual

BASIC INSTRUCTION SET
3.9.3
Flag
Transfer
Instructions
Though specific instructions exist to alter CF and DF, there
is
no
direct method of altering the other
flags. The flag transfer instructions allow a program
to
alter the other flag bits with the bit manipula-
tion instructions after transferring these flags to the stack or the AH register.
The
PUSHF and POPF instructions are also useful
for
preserving the state of the flag register before
executing a procedure.
LAHF
(Load
AH
from
Flags) copies SF, ZF, AF, PF, and CF to AH bits
7,
6,
4,
2,
and
0,
respectively
(see figure 3-13). The contents of the remaining bits (5,
3,
and
1)
are undefined. The flags remain
unaffected. This instruction can assist in converting
8080/8085 assembly language programs
to
run
on
the base architecture of the 8086,8088,80186,80188, and 80286.
Example: LAHF
SAHF
(Store
AH
into Flags) transfers bits
7,
6,
4,
2,
and 0 from AH into SF, ZF, AF, PF, and CF,
respectively (see figure 3-13). This instruction also provides
8080/8085 compatibility with the 8086,
8088,80186,80188,
and 80286.
Example: SAHF
PUSHF
(Push Flags) decrements SP
by
two
and then transfers all flags
to
the word at the top of stack
pointed
to
by
SP
(see figure 3-14). The flags remain unaffected. This instruction enables a procedure
to save the state of the flag register for later use.
Example:
PUSHF
POPF (Pop Flags) transfers specific bits from the word
at
the top of stack into the low-order byte of
the flag register (see figure 3-14). The processor then increments
SP
by
two.
Note that an application program in the protected virtual address mode may not alter
10PL
(the
I/O
privilege level flag) unless the program
is
executing at privilege level
O.
A program may aiter IF (the
interrupt flag) only when executing
at
a level that
is
at
least as privileged as IOPL.
76543210
ISFIZF.AF.PF.CFI
REGISTER
AH
LAHF
loads Ilva lIags Irom tha lIag raglstar Into raglstar
AH.
SAHF
storas thasa sama IIva lIags Irom
AH
Into the lIag register. The bit
position
01
each lIag Is the sama
In
AH
as
It
lain
the lIag raglater. The remaining blta are Indeterminate.
G30108
Figure 3-13. LAHF and SAHF
3-26
I