CS-220, Week 5A
Fall, 1999
R. Eckert

CONDITIONAL AND UNCONDITIONAL TRANSFER OF CONTROL

(See the first few pages of Chapter 8 in your text book.)


Unconditional Jumps--

Most Common Syntax:    JMP  aaa

Transfers to the instruction having "aaa" as a label.


Conditional Jumps--

Most Common Syntax:    Jcond bbb

"cond" represents some condition (e.g. G==>greater than, Z==>if
zero, etc.); "bbb" is a label. If the condition is true, the next
instruction to execute will be the one that has the specified
label. If not, the next instruction to execute will be the next
one in sequence.

Very commonly conditional jumps are used after a CMP or TEST
instruction, or after an arithmetic instruction. What happens
depends on the condition and how the cpu flags have been affected
by the CMP, TEST, or arithmetic instruction. There are three
categories--

1. Operands in the CMP/arithmetic instruction can be signed or
unsigned (result does not depend on whether the leading bit is a
sign bit). Examples:

 mnemonic    After CMP op1,op2   After arithmetic   Jump taken if
             jump made if...     jump made if...    flags are:
-------------------------------------------------------------------
 JE, JZ      op1==op2            Zero Result        ZF=1 (ZR)
 JNE, JNZ    op1!=op2            Nonzero Result     ZF=0 (NZ)
 JP, JPE          Result has even parity            PF=1 (PE)
 JNP, JPO         Result has odd parity             PF=0 (PO)
 JCXZ                            CX=0

2. Operands in the CMP/arithmetic instruction are unsigned (leading bit
is NOT a sign bit--e.g., 0FF > 0, since 11111111b = 255 if the leading
bit is not a sign bit, and 255 is greater than zero).

 mnemonic          After CMP op1,op2      Jump taken if
                   jump made if...        flags are:
-------------------------------------------------------------------
 JB, JNAE, JC      op1<op2                CF=1 (CY)
 JBE, JNA          op1<=op2               ZF=1 (ZR) or CF =1 (CY)
 JAE, JNB, JNC     op1>=op2               CF=0 (NC)
 JA, JNBE          op1>op2                CF=0 (NC) and ZF=0 (NZ)

3. Operands in the CMP/arithmetic instruction are signed (leading bit
IS a sign bit--e.g., 0FF < 0, since 11111111b = -1 if the leading bit is
a sign bit, and -1 is less than zero).

 mnemonic          After CMP op1,op2      Jump Taken
                   or arithmetic instr    if flags are...
                   jump made if...
----------------------------------------------------------
 JL, JNGE          op1<op2
 JLE, JNG          op1<=op2
 JGE, JNL          op1>=op2
 JG, JNLE          op1>op2
 JO                There was overflow     OF=1 (OV)
 JNO               No overflow            OF=0 (NV)
 JS                Negative result        SF=1 (NG)
 JNS               Positive result        SF=0 (PL)

For all of these conditional jumps, the instruction with the transfer
label must not be more than 127 bytes forward or 128 bytes to the rear of
the jump instruction.