Section
06 Part 06 – Signed Branches (BGE, BGT, BLE, BLT) |

“Truth is certainly a branch
of morality and a very important one to society.” ~Thomas Jefferson |

Introduction

These
branches are designed to branch if larger or smaller than a specific value. These deal with signed results,
that is to say for using a byte; 80 is
the lowest value whilst 7F is
the highest.

So
when comparing say FE to 02. FE will
be considered lower than 02.

The BGE
Instruction

BGE – Branch on Greater than
or Equal

The destination operand will be added to the PC, and
the 68k will continue reading at the new offset held in PC, if the following
conditions are met:

- The N and V flags are both clear
- The N and V flags are both set

Otherwise,
the instruction is ignored.

Examples

This
instruction uses the N and V flags together to detect if the result is greater than
or equal:

cmpi.w #$0020,d0 bge.s Is20OrHigher move.w #$0000,d0 Is20OrHigher: |

We’ll
pretend d0 contains 00009800, the CMP is word, so the
comparison is 0020 & 9800.

- 9800 is
**not**higher than or equal to 0020, so the branch is ignored.

Now
let’s pretend d0 contains 00000492. The comparison is 0020 & 0492.

- 0492 is higher than 0020, so the 68k will branch to “Is20OrHigher”

The BGT
Instruction

BGT – Branch on Greater Than

The destination operand will be added to the PC, and
the 68k will continue reading at the new offset held in PC, if the following
conditions are met:

- The Z, N and V flags are all clear
- The Z flag is clear, but the N and V
flags are both set

Otherwise,
the instruction is ignored.

Examples

This
instruction uses the Z, N and V flags together to detect if the result is
greater than:

cmpi.w #$0020,d0 bgt.s IsHigher move.w #$0000,d0 IsHigher: |

We’ll
pretend d0 contains 00000020, the CMP is word, so the
comparison is 0020 & 0020.

- 0020 is
**not**higher than 0020, so the branch is ignored.

Now
let’s pretend d0 contains 00000492. The comparison is 0020 & 0492.

- 0492 is higher than 0020, so the 68k will branch to “IsHigher”

The BLE
Instruction

BLE – Branch on Less than or
Equal

The destination operand will be added to the PC, and
the 68k will continue reading at the new offset held in PC, if the following
conditions are met:

- The Z flag is set
- The N flag is clear, but the V flag
is set
- The N flag is set, but the V flag is
clear

Otherwise,
the instruction is ignored.

Examples

This
instruction is the polar opposite of BGE:

cmpi.w #$0020,d0 ble.s Is20OrLower move.w #$0000,d0 Is20OrLower: |

We’ll
pretend d0 contains 00009800, the CMP is word, so the
comparison is 0020 & 9800.

- 9800 is lower than 0020, so the 68k will branch to “Is20OrLower”

Now
let’s pretend d0 contains 00000492. The comparison is 0020 & 0492.

- 0492 is
**not**lower than or equal to 0020, so the branch is ignored.

The BLT
Instruction

BLT – Branch on Lower Than

- The N flag is
clear, but the V flag is set
- The N flag is set,
but the V flag is clear

Otherwise,
the instruction is ignored.

Examples

This
instruction is the polar opposite of BGT:

cmpi.w #$0020,d0 blt.s IsLower move.w #$0000,d0 IsLower: |

We’ll
pretend d0 contains 00000020, the CMP is word, so the
comparison is 0020 & 0020.

- 0020 is
**not**lower than 0020, so the branch is ignored.

Now
let’s pretend d0 contains 00008492. The comparison is 0020 & 8492.

- 8492 is lower than 0020, so the 68k will branch to “IsLower”