3-4-1 Conditional Branch Instructions

All conditional branch instructions have the following 2-byte machine code format:

where the second byte gives an 8-bit signed (2's complement) displacement relative to the address of the next instruction in sequence.

Figure 3-29 Correspondence between branch distances, values of D8, and branch addresses.

Distance (in decimal)D8 (in hexadecimal)Branch Address
-12880(IP)-128
...
...
-2FE(IP)-2
-1FF(IP)-1
000(IP)
101(IP)+1
202(IP)+2
...
...
1277F(IP)+127

As an example of how the assembler determines the value of D8, consider the following sequence:

0050    AGAIN:    INC    CX
0052              ADD    AX,(BX)
0054              JNS    AGAIN
0056    NEXT:     MOV    RESULT,CX
where the column on the left gives the effective address of the first byte of each instruction. Because
0050Effective branch address
- 0056(IP) when JNS branch decision is made
-6
the assembler will set the value of D8 to FA.

Figure 3-30 Conditional branch instructions.

NameMnemonic and FormatAlternate MnemonicTest Condition*
Branch on zero, or equal
JZ     OPR
JE
ZF = 1
Branch on nonzero, or not equal
JNZ    OPR
JNE
ZF = 0
Branch on sign set
JS     OPR
SF = 1
Branch on sign clear
JNS    OPR
SF = 0
Branch on overflow
JO     OPR
OF = 1
Branch on no overflow
JNO    OPR
OF = 0
Branch on parity set, or even parity
JP     OPR
JPE
PF = 1
Branch on parity clear, or odd parity
JNP    OPR
JPO
PF = 0
Branch on below, or not above or equal (unsigned)
JB     OPR
JNAE,JC
CF = 1
Branch on not below, or above or equal (unsigned)
JNB    OPR
JAE,JNC
CF = 0
Branch on below or equal, or not above (unsigned)
JBE    OPR
JNA
CF ZF = 1
Branch on not below or equal, or above (unsigned)
JNBE   OPR
JA
CF ZF = 0
Branch on less, or not greater or equal (signed)
JL     OPR
JNGE
SF OF = 1
Branch on not less, or greater or equal (signed)
JNL    OPR
JGE
SF OF = 0
Branch on less or equal, or not greater (signed)
JLE    OPR
JNG
(SF OF) ZF = 1
Branch on not less or equal, or greater (signed)
JNLE   OPR
JG
(SF OF) ZF = 0

*If the test condition is met (IP)(IP)+sign extended D8; otherwise (IP) are unchanged and the program continues in sequence.

Flags: No flags are affected.

Addressing modes: Mode is relative to IP. OPR must represent a label that is within -128 to 127 bytes of the instruction following the branch instruction.


Table of Contents | Next page | Previous page

This is page 33.