Carry Flag

From NES Hacker Wiki
Jump to: navigation, search

The Carry Flag (C) is bit 0 of the Processor Status Register. For addition and logical operations, this bit holds the the most significant bit that is carried beyond the 8 bits of a byte. However, in subtraction operations, the flag is cleared to 0 if borrow is required, but set to 1 if borrow is not required.

Examples

The example uses left shift on values that have bit 7 on and off. The 7th bit in left shift is moved into the carry flag.

0001:A9 00     LDA #$80        ; Load A with 128 = 10000000
0002:0A        ASL A           ; Left shift A 1 ← 00000000
                               ; This pushes the 1 into the carry flag, setting it to 1.
0003:A9 64     LDA #$64        ; Load A with 100 = 01100100
0004:0A        ASL A           ; Left shift A 0 ← 11001000
                               ; This pushes the 0 into the carry flag, clearing it to 0.


Opcodes

The following opcodes affect the carry flag.