Slide 6.6: LAHF instruction
Slide 6.8: XCHG instruction
Home

SAHF Instruction


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

SAHF — Store AH Register into Flags

Usage: SAHF

Flag O D I S Z A P C
Result       * * * * *

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

 Setting Sign and Carry Flags   Output 

      .code
      mov   ebx, 0             ; Clears ebx.
      mov   ah, 10000001b      ; Sets Sign and Carry flag.
      sahf                     ; Loads ah into flags.
      jnc   L1                 ; Jumps if not carry.
      inc   ebx                ; If carry, increases ebx.
 L1:  jns   L2                 ; Jumps if not sign.
      inc   ebx                ; If sign, increases ebx.
 L2:  mov   eax, ebx           ; Moves ebx to eax.
      call  WriteInt           ; Prints eax.





The following instructions will be covered in detail in Chapter 6.