Condition Flags

For the 8086

Conditional branches in the Intel 8086/88 are made on the basis of a number of condition flags. The condition flags are set by most of the arithmetic instructions. For example, the ZF (Zero) flag is a 1 if the result of the last operation was 0.

The CMP is another instruction that sets the condition flags. This instruction compares the value in a register with another value from a register or memory by computing the difference between the first value and the other value and setting the condition flags on the basis of the result. It does not change either of the values. Thus,

CMP DX,AX

compares the content of DX with the content of AX by subtracting a copy of the value in AX from a copy of the value in DX and sets all of the condition flags appropriately.

     Flag Name    Meaning if Flag On     On Name     Off Name
     --------------------------------------------------------      
        ZF        Result zero               ZR         NZ
        SF        Sign Negative             NG         PL
        OF        Overflow occurred         OV         NV
        CF        Carry                     CY         NC
        AF        Auxiliary carry           AC         NA
        PF        Parity even               PE         PO
        TF*       Trap (for Debugging)      --         --
        IF*       Interrupt enabled         EI         DI
        DF*       Direction down            DN         UP
     ---------------------------------------------------------------
     *  This is not a condition flag; it controls processor actions.

     Some commands that act on the state of various flags. 
     ---------------------------------------------------------------
        JS        Jump on Negative Value  (Branches if SF=1)
        JNS       Jump if Positive Value  (Branches if SF=0)
        JZ        Jump on Zero            (Branches if ZF=1)
        JE        Jump if Equal           (Same as JZ)
        JNZ       Jump if Not Zero        (Branches if ZF=0)
        JNE       Jump if Not Equal       (Same as JNZ)
        JAE       Jump if Above or Equal  (Tests Zero and Sign) 
     ---------------------------------------------------------------
There is more than one name for some instructions. For example, tests for Zero (JZ) and equality (JE) are the same. Following an arithmetic operation, JZ determines if the result is zero. Following a comparison, JE determines whether the compared values are identical. Since a comparison is based on an arithmetic operation (subtraction), there is no difference.

6502 CPU