Conditional Branch Instructions

The conditional branch instructions test the condition code and branch if the condition code matches the specific instruction used. The conditional branch instructions are:

The Branch Instructions

Instruction Meaning Value When Branch is Taken
  Relationship of Operands Condition Code
BH branch on high operand1 > operand2 10
BL branch on low operand1 < operand2 01
BE branch on equal operand1 == operand2 00
BNE branch on not equal operand1 != operand2 10 or 01
BNH branch on not high operand1 <= operand2 00 or 01
BNL branch on not low operand1 >= operand2 00 or 10

Some Examples

The following examples show how to use branch instructions to implement some if structures:

Pseudocode Assembler
if A > B
   .
   . (1)
   .
endif
.
. (2)
.
         CLC   A,B
         BH    ONE
         B     CONT
ONE      .
         . (1)
         .
CONT     .
         . (2)
         .
if A > B
   .
   . (1)
   .
endif
.
. (2)
.
         CLC   A,B
         BNH   CONT
         .
         . (1)
         .
CONT     .
         . (2)
         .
if A == B
   .
   . (1)
   .
else
   .
   . (2)
   .
endif
.
. (3)
.
         CLC   A,B
         BE    EQUAL
         .
         . (2)
         .
         B     AFTER
EQUAL    .
         . (1)
         .
AFTER    .
         . (3)
         .
if A > B || C <= D
   .
   . (1)
   .
else
   .
   . (2)
   .
endif
.
. (3)
.
         CLC   A,B
         BH    TRUE
         CLC   C,D
         BNH   TRUE
         .
         . (2)
         .
         B     AFTER
TRUE     .
         . (1)
         .
AFTER    .
         . (3)
         .
if A != B
   .
   . (1)
   .
else if C > D
   .
   . (2)
   .
else
   .
   . (3)
   .
endif
.
. (4)
.
         CLC   A,B
         BNE   ONE
         CLC   C,D
         BH    TWO
         .
         . (3)
         .
         B     AFTER
ONE      .
         . (1)
         .
         B     AFTER
TWO      .
         . (2)
         .
AFTER    .
         . (4)
         .


Email Me | Office Hours | My Home Page | Department Home | MCC Home Page

© Copyright Emmi Schatz 2003