B

VAX11

 

B         BRANCH ON (CONDTION)

 

Purpose

test condition code

Format

opcode displ.bb

Operation

if condition then PC ß PC + SEXT (displ);

Condition codes

N ß N;

Z ß Z;

V ß V;

C ß C;

Exceptions

none

Opcodes

CONDITION             

12 Z EQL 0                 BNEQ,            Branch on Not Equal (signed)

                                    BNEQU, Branch on Not Equal Unsigned

13 Z EQL 1                 BEQL, Branch on Equal (signed)

                                    BEOLU, Branch on Equal Unsigned

14 {N OR Z}EQL 0    BGTR, Branch on Greater Than (signed)

15 {N OR Z}EQL 1    BLEQ, Branch on Less Than or Equal                          (signed)

18 N EQL 0                 BGEQ, Branch on Greater Than or Equal                                 (signed)

19 N EQL 1                 BLSS,  Branch on Less Than (signed)

1A {C OR Z}EQL 0    BGTRU, Branch on Greater Than                                             Unsigned

1B {C OR Z}EQL 1    BLEQU, Branch Less Than or Equal                            Unsigned

1C V EQL 0                BVC, Branch on Overflow Clear

1D V EQL 1                BVS, Branch on Overflow Set

1E C EQL 0                 BGEQU, Branch on Greater Than or Equal                               unsigned

                                    BCC    Branch on Carry Clear

1F C EQL 1                 BLSSU, Branch on Less Than Unsigned

                                    BSC     Branch on Carry Set

Description

The condition codes are tested and if the condition indicated by the instruction is met, the sign-extended branch displacement is added to the PC and PC is replaced by the result.

Notes

The VAX- conditional branch instructions permit considerable flexibility in branching but require care in choosing the correct branch instruction. The conditional branch instructions are divided into 3 overlapping groups:

1. Overflow and Carry Group

            BVS                 V EQL 1

            BVC                V EQL 0

            BCS                 C EQL 1

            BCC                C EQL 0

These instructions are typically used to check for overflow (when overflow traps are not enabled), for multiprecision arithmetic, and for other special purposes.

2. Unsigned Group

            BLSSU            C EQL 1

            BLEQU           {C or Z} EQL 1

            BEQLU           Z EQL 1

            BNEQU           Z EQL 0

            BGEQU           C EOL 0

            BGTRU           {C OR Z} EQL 0

These instructions typically follow integer and field in structions where the operands are treated as unsigned integers, addressed instructions, and character string in structions.

3. Signed Group

            BLSS               N EQL 1

            BLEQ              {N OR Z} EQL 1

            BEQL              Z EQL 1

            BNEQ             Z EQL 0

            BGEQ              N EQL 0

            BGTR              {N OR Z} EQL 0

These instructions typically follow integer and field instructions where the operands are being treated as signed integers, floating point instructions, and decimal string instructions.

 

 

 

Example 1 - BEQL

 

The following program shows the usage of BEQL opcode.

 

.text

 

main: .word 0

 

      # first case - Z should be 1 (Equal)

      movb $0, r1

      beql eq1

      calls $0, prn_not_eq

      jmp next_stage

eq1:  calls $0, prn_eq

 

      # second case - Z should be 0 (Not Equal)

next_stage:

      movb $1, r1

      beql eq2

      calls $0, prn_not_eq

      jmp end_prog

eq2:  calls $0, prn_eq

 

end_prog:

      pushl $0

      calls $1, .exit

 

prn_not_eq: .word 0

      pushal not_eq

      pushal format

      calls $2, .printf

      ret

prn_eq: .word 0

      pushal eq

      pushal format

      calls $2, .printf

      ret

 

.data

 

eq:         .asciz "Equal"

not_eq:     .asciz "Not Equal"

format:     .asciz "%s\n"

 

 

 

 


 

Example 2 – BNEQ, BNEQU

 

Almost the same as the previous example, this program shows the usage of BNEQ, BNEQU opcodes.

 

 

.text

 

main: .word 0

 

      # first case - Z should be 0 (Not Equal)

      movb $0, r1

      bneq eq1

      calls $0, prn_not_eq

      jmp next_stage

eq1:  calls $0, prn_eq

 

      # second case - Z should be 1 (Equal)

next_stage:

      movb $1, r1

      bnequ eq2

      calls $0, prn_not_eq

      jmp end_prog

eq2:  calls $0, prn_eq

 

end_prog:

      pushl $0

      calls $1, .exit

 

prn_not_eq: .word 0

      pushal not_eq

      pushal format

      calls $2, .printf

      ret

prn_eq: .word 0

      pushal eq

      pushal format

      calls $2, .printf

      ret

 

.data

 

eq:         .asciz "Equal"

not_eq:     .asciz "Not Equal"

format:     .asciz "%s\n"

 

 


 

Example 3 – BGTR

 

.text

 

main: .word 0

 

      movb $10, r1

      movb $5, r2

 

      # first case - should be True

      cmpb r1, r2

      bgtr eq1

      calls $0, prn_false

      jmp next_stage

eq1:  calls $0, prn_true

 

      # second case - should be False

next_stage:

      cmpb r2, r1

      bgtr eq2

      calls $0, prn_false

      jmp end_prog

eq2:  calls $0, prn_true

 

end_prog:

      pushl $0

      calls $1, .exit

 

prn_false: .word 0

      pushal lbl_false

      pushal format

      calls $2, .printf

      ret

prn_true: .word 0

      pushal lbl_true

      pushal format

      calls $2, .printf

      ret

 

.data

 

lbl_true:   .asciz "True"

lbl_false: .asciz "False"

format:     .asciz "%s\n"

 

 


Example 4 – BGEQ

 

.text

 

main: .word 0

 

      movb $10, r1

      movb $5, r2

 

      # first case - should be True

      cmpb r1, r2

      bgeq eq1

      calls $0, prn_false

      jmp next_stage

eq1:  calls $0, prn_true

 

      # second case - should be False

next_stage:

      cmpb r2, r1

      bgeq eq2

      calls $0, prn_false

      jmp end_prog

eq2:  calls $0, prn_true

 

end_prog:

      pushl $0

      calls $1, .exit

 

prn_false: .word 0

      pushal lbl_false

      pushal format

      calls $2, .printf

      ret

prn_true: .word 0

      pushal lbl_true

      pushal format

      calls $2, .printf

      ret

 

.data

 

lbl_true:   .asciz "True"

lbl_false: .asciz "False"

format:     .asciz "%s\n"