CIS-77 Home http://www.c-jump.com/CIS77/CIS77syllabus.htm

CPU Flags and Data Manipulation


  1. Adding and Subtracting Integers
  2. The Processor Flags (Condition Codes)
  3. Carry Flag
  4. Overflow Condition
  5. Overflow Condition, Cont
  6. Overflow Condition, Cont
  7. INC and DEC Instructions
  8. INC and DEC Instructions, Cont.
  9. INC and DEC Example
  10. CLC, STC, CMC - Direct Carry Flag Manipulation
  11. Overflow Flag Examples
  12. The LAHF and SAHF Instructions
  13. The NEG Instruction
  14. The SHL Instruction, Shift Logical Bit Left
  15. The SHR Instruction, Shift Logical Bit Right
  16. The SAR Instruction, Shift Arithmetic Right

1. Adding and Subtracting Integers



2. The Processor Flags (Condition Codes)



3. Carry Flag



4. Overflow Condition



5. Overflow Condition, Cont



6. Overflow Condition, Cont



7. INC and DEC Instructions



8. INC and DEC Instructions, Cont.



9. INC and DEC Example




10. CLC, STC, CMC - Direct Carry Flag Manipulation



11. Overflow Flag Examples



12. The LAHF and SAHF Instructions



13. The NEG Instruction



14. The SHL Instruction, Shift Logical Bit Left


  • SHL is one of the Bit Manipulation Instructions:

            mov al, 75h
            mov cl, 3
            shl al, cl
    
  • The instruction format is

    • SHL destination, count

    where  1 <= count <= 31.

  • All bits in the destination operand are shifted left count times.

  • The less-significant bit (LSB) is filled with 0 each time.

  • The most-significant bit (MSB) is placed into carry flag CF.

  • Other flags are modified according to the final result.

  • Execution of  SHL AL, CL :

      Execution of SHL AL, CL


15. The SHR Instruction, Shift Logical Bit Right



16. The SAR Instruction, Shift Arithmetic Right


  • Same as SHR, except that most-significant bit (MSB) is shifted back to itself.

  • This preserves the original sign of the destination operand, because MSB is the sign bit.

  • Each shift divides the destination operand by 2, while preserving the sign.

  • For example,

        mov cl, -74 ; 2's complement of -74 is 0B6h
        sar cl, 1   ; CL is now -37, or 0DBh
    
  • Note that LSB is shifted into the carry flag CF.

  • Operation of  SAR CL, 1 :

      Operation of SAR CL, 1