BRC - Branch if carry flag set Command
Branches if the carry flag is set. The carry flag is set when the result of an operation results in a value greater than 255 (0xff) or if the result is less than zero.
This flag indicates that there is a value left over from a calculation or a value was borrowed for the calculation.
This flag can be set and cleared in a number of ways. It is handy for checking a threshold or interrogating individual bits in a byte.
This is the opposite of the BCC command.
Syntax
-
CMP Command Comparing a larger value to a smaller accumulator value
-
ADD Command that results in a value higher than 255
-
SUB Command that results in a value less than 0
-
INC Command with 255 in the accumulator
-
DEC Command with 0 in the accumulator
-
SHL Command with an accumulator value above 127 (MSB Set)
-
SHR Command with an odd value in the accumulator (LSB Set)
-
ROL Command with an accumulator value above 127 (MSB Set)
-
ROR Command with an odd value in the accumulator (LSB Set)
Examples
Example 1
Ways to set the carry flag.
{
LDA #0x05 //put the fixed hex value 0x05 into the Accumulator.
CMP #0x06 //0x05-0x06 = -1 Set the Carry and Minus flags
BRC Label //The carry flag is set so the task will branch to the label
LDA #100 //Load a fixed decimal value of 100
ADD #160 //Add a fixed decimal value of 160, 100+160=260, Carry flag will be set
BRC Greater //The carry flag is set so the task will branch to the label
LDA #0xFF //Load a value of 255
INC //Add 1, This will set the carry flag
LDA #0x00 //Load a value of 0
DEC //Subtract 1, This will set the carry flag
LDA #133 //Load a value of 133
SHR //Move the LSB into the carry flag, flag is set
}