Flag control instructions

The EFlags register contains information on certain aspects of the last ALU operation as well as certain settings of the CPU (for example, the direction of string instructions); however, we have the mechanism for controlling the content of this register, up to the level of a single flag, with the following instructions:

  • Set/clear carry flag (STC/CLC): We may want to have the CF set or reset prior to certain operations.
  • Complement the carry flag (CMC): This instruction inverts the value of the CF.
  • Set/clear direction flag (STD/CLD): We may use these instructions to set or reset the DF in order to define whether ESI/EDI (RSI/RDI) should increment or decrement with string instructions.
  • Load flags into the AH register (LAHF): There are certain flags, for example, ZF, that do not have associated instructions for direct modification, therefore, we may load the Flags register into AH, modify the corresponding bit, and reload the Flags register with the modified value.
  • Store the AH register into flags (SAHF): This instruction stores the value of AH register into the Flags register.
  • Set/clear the interrupt flag (STI/CLI) (not in user land): These instructions are used on the operating system-level to enable/disable interrupts.
  • Push Flags/EFlags/RFlags register onto the stack (PUSHF/PUSHFD/PUSHFQ): LAHF/SAHF instructions may not be sufficient for inspection/modification of certain flags in the Flags/EFlags/RFlags register. With the PUSHF* instruction, we gain access to other bits (flags).
  • Retrieve Flags/EFlags/RFlags register from the stack (POPF/POPFD/POPFQ): These reload Flags/EFlags/RFlags register with the new value from the stack.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset