BPL (short for "Branch if PLus") is the mnemonic for a machine language instruction which branches, or "jumps", to the address specified if, and only if the negative flag is clear. If the negative flag is set when the CPU encounters a BPL instruction, the CPU will continue at the instruction following the BPL rather than taking the jump.
BPL in comparisons[edit | edit source]
- Main article: Comparisons in machine language
BPL and its counterpart BMI are often used in conjunction with instruction like CMP, CPX, CPY or SBC to compare signed numbers or simply to check for the sign. The former could be accomplished for 8-bit integers as follows (not considering an overflow condition):
LDA NumA Read the value "NumA" CMP NumB Compare against "NumB" BPL Greater_or_equal Go to label "Greater_or_equal" if "NumA" >= "NumB" ... Execution continues here if "NumA" < "NumB"
For signed integers NumA or NumB which are in range from -128 ($80) to +127 ($7F) this could lead into an overflow condition indicated by the set overflow flag (which says that the difference is less than -128 or greater than 127). In such case the negative flag has the opposite meaning.
BCS or BCC should be used accordingly for greater-than-or-equal-to or less-than comparisons of unsigned values.
Addressing mode[edit | edit source]
BPL only supports the Relative addressing mode, as shown in the table at right.
In the assembler formats listed, nn is a one-byte (8-bit) relative address. The relative address is treated as a signed byte; that is, it shifts program execution to a location within a number of bytes ranging from -128 to 127, relative to the address of the instruction following the branch instruction.
The execution time for BPL is not a fixed value, but depends on the circumstances. The listed time is valid only in cases where BPL does not take the branch. If it does take the branch, execution takes one additional clock cycle. Furthermore, if the branching crosses a page boundary, yet another cycle must be added to the execution time listed.
CPU flags[edit | edit source]
BPL does not affect any of the CPU's status flags.