Slide 6.5: MOVSX instruction
Slide 6.7: SAHF instruction
Home

LAHF Instruction


The LAHF instruction (load status flags into AH) copies the low byte of the EFLAGS register into AH.

LAHF — Load Register AH from Flags
Usage: LAHF

Flag O D I S Z A P C
Result                

Copies bits 0-7 of the flags register into AH. This includes flags A, C, P, S, and Z other bits are undefined.
      AH := S Z ? A ? P ? C
Clocks
Operands 286 386 486 Size Bytes
  2 2 3 1

The EFLAGS register is a 32-bit register. Nine of its bits are shown below. Use this instruction, you can save a copy of the flags in a memory variable or test several flags at once.

EFLAGS Register
Control Flags Status Flags
T D I O S Z A P C
Trap Direction Interrupt
-enable
Overflow Sign Zero Auxiliary
Carry
Parity Carry

 Checking for Zero Bit   Output 

      .code
      sub   eax, eax
      lahf
      test  ah, 01000000b
      jnz   L1
      mov   eax, 0     ; not zero
      jmp   L2
 L1:  mov   eax, 1     ; zero
 L2:  call  WriteInt




  The TEST instruction performs an implied AND operation between each pair of matching bits in two operands and sets the flags accordingly.