Section 06 Part 04 – The BPL & BMI Instructions

 

“Memory is a magnet. It will pull to it and hold only material nature has designed it to attract.” ~Jessamyn West

 

 

 

Introduction

 

These two are conditional branches that will branch depending on the N flag.  It should be noted that these branch instructions have two sizes; .s for short and .w for word.  For details see Section 05 Part 03 (The BRA Instruction).

 

 

 

The BPL Instruction

 

BPL – Branch on PLus (Positive)

 

If the N flag of the CCR is clear, the destination operand will be added to the PC, and the 68k will continue reading at the new offset held in PC.  If the N flag is set, the instruction is ignored.

 

 

 

Examples

 

This is simply based on whether or not the result is positive:

 

          cmpi.w    #$0020,d0

          bpl.s     FlagNIsClear

          move.w    #$0000,d0

 

FlagNIsClear:

 

 

We’ll pretend d0 contains 2400001E, the CMP is word, so only the 001E is taken into account.  001E - 0020 = FFFE.  You’ll notice the result is negative, so the N flag is set.  The 68k will not branch to “FlagNIsClear”.

 

If the result were positive, the N flag would be cleared, and the 68k would jump to “FlagNIsClear”.

 

 

 

The BMI Instruction

 

BMI – Branch on MInus (Negative)

 

If the N flag of the CCR is set, the destination operand will be added to the PC, and the 68k will continue reading at the new offset held in PC.  If the N flag is clear, the instruction is ignored.

 

 

 

Examples

 

This is the opposite of BPL:

 

          cmpi.w    #$0020,d0

          bmi.s     FlagNIsSet

          move.w    #$0000,d0

 

FlagNIsSet:

 

 

Again, pretend d0 contains 2400001E, the CMP is word, so only the 001E is taken into account.  001E - 0020 = FFFE.  The result is negative, so the N flag is set.  The 68k will branch to “FlagNIsSet”.

 

If the result were positive, the N flag would be cleared, and the 68k would simply ignore the branch and continue.

 

 

 

Previous Part

Main Page

Next Part