BCC

From C64-Wiki
Jump to: navigation, search

BCC (short for "Branch if Carry is Clear") is the mnemonic for a machine language instruction which branches, or "jumps", to the address specified if, and only if the carry flag is clear. If the carry flag is set when the CPU encounters a BCC instruction, the CPU will continue at the instruction following the BCC rather than taking the jump.

BCC in comparisons[edit]

Main article: Comparisons in machine language

BCC and it's "counterpart", BCS, are often used after a "compare" instruction (either CMP, CPX, or CPY) in conjunction with comparing unsigned 8-bit integers, like e.g.:

LDA NumA   Read the value "NumA"
CMP NumB   Compare against "NumB"
BCC Less   Go to label "Less" if "NumA" < "NumB"
...        Execution continues here if "NumA" >= "NumB"

For signed integers, this method fails if NumA and NumB have different arithmethic signs (i.e. one negative, the other positive) — instead, BPL and BMI should be used for greater than/less than-style comparisons of signed bytes.

Addressing mode[edit]

Opcode Addressing
mode
Assembler
format
Length
in bytes
Number of
cycles
Dec Hex
144 90 Relative BCC nnnn 2 2*

BCC only supports the Relative addressing mode, as shown in the table at right. In the assembler formats listed, nnnn is a two-byte (16-bit) address.
The execution time for BCC is not a fixed value, but depends on the circumstances. The listed time is valid only in cases where BCC does not take the branch. If it does take the branch, ececution 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]

BCC does not affect any of the CPU's status flags.