BCC Instruction (Branch if Carry is Cleared/ Branch Less Than)
If the carry flag is clear, changes the execution position to the specified location.
BLT is an alias of BCC.
BCC Overloads
| Opcode | Syntax | Addressing Mode | Bytes | Cycles | Notes |
|---|---|---|---|---|---|
| 90 | BCC near BLT near | PC Rel. | 2 | 2 | 1, 2 |
Notes
- Add 1 cycle if the branch is actually taken
- Add 1 cycle in emulation mode if the branch target crosses a page boundary
Flags Affected
--------
This instruction does not change the status flags.
Description
If the carry flag is clear, the BCC instruction changes the program’s execution position to the address indicated by the signed 8-bit offset given as the operand, relative to the current program counter.
It is normally executed together with a comparison such as the CMP instruction, but depending on the purpose it may be used together with other instructions.
The following example is a simple for-loop implementation using a comparison and the BCC instruction. It computes the sum of the integers from 1 to the specified number.
Note that code equivalent to this example can be written more concisely by using other instructions.
; BCC for-Loop Sample
; Calculate sum[k=1 to n] k ($10 = n)
REP #$30
LDA $10
STA $02 ; $02 = n
STZ $00 ; $00 = sum = 0
LDX.w #$0000 ; X = k = 0
.loop
INX ; k = k + 1
TXA ; A = k
CLC
ADC $00 ; A = sum + k
STA $00 ; sum = A
CPX $02 ; k - n
BCC .loop ; if n > k then goto loop
Examples
Branching on unsigned magnitude
A BCC instruction after a CMP instruction branches when “A is less than the compared value (unsigned)”.
LDA $10
CMP.b #$80
BCC .small ; branch when $10 < $80
; we get here when $10 >= $80
Handling the carry from an addition
Skips processing of the upper digit when the ADC result produced no carry.
; add the 8-bit value $12 to the 16-bit value $10/$11 (A is 8-bit)
LDA $10
CLC
ADC $12
STA $10
BCC .done ; if there was no carry, leave the high byte as is
INC $11
.done
See also
BCS instruction
BEQ instruction
BMI instruction
BNE instruction
BPL instruction
BRA instruction
BRL instruction
BVC instruction
BVS instruction