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:
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.
Now
let’s pretend d0 contains 00000492. The comparison is 0020 & 0492.
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:
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.
Now
let’s pretend d0 contains 00000492. The comparison is 0020 & 0492.
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:
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.
Now
let’s pretend d0 contains 00000492. The comparison is 0020 & 0492.
The BLT
Instruction
BLT – Branch on Lower 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:
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.
Now
let’s pretend d0 contains 00008492. The comparison is 0020 & 8492.