
BASIC INSTRUCTION SET
3.9.3Flag 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
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
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
Example: PUSHF
POPF (Pop Flags) transfers specific bits from the word at the top of stack into the
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
I
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