Difference between revisions of "Carry Flag"

From NES Hacker Wiki
Jump to: navigation, search
(Created page with "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 be...")
 
 
(One intermediate revision by the same user not shown)
Line 10: Line 10:
 
  0004:0A        ASL A          ; Left shift A 0 ← 11001000
 
  0004:0A        ASL A          ; Left shift A 0 ← 11001000
 
                                 ; This pushes the 0 into the carry flag, clearing it to 0.
 
                                 ; This pushes the 0 into the carry flag, clearing it to 0.
 +
 +
 +
==Opcodes==
 +
The following opcodes affect the carry flag.
 +
 +
{|
 +
| width="200" |
 +
* <span style="font-family:monospace; font-size:12pt;">[[ADC]]</span>
 +
* <span style="font-family:monospace; font-size:12pt;">[[ASL]]</span>
 +
* <span style="font-family:monospace; font-size:12pt;">[[CLC]]</span>
 +
* <span style="font-family:monospace; font-size:12pt;">[[CMP]]</span>
 +
| width="200" |
 +
* <span style="font-family:monospace; font-size:12pt;">[[CPX]]</span>
 +
* <span style="font-family:monospace; font-size:12pt;">[[CPY]]</span>
 +
* <span style="font-family:monospace; font-size:12pt;">[[LSR]]</span> (Cleared)
 +
* <span style="font-family:monospace; font-size:12pt;">[[PLP]]</span>
 +
| width="200" |
 +
* <span style="font-family:monospace; font-size:12pt;">[[ROL]]</span>
 +
* <span style="font-family:monospace; font-size:12pt;">[[ROR]]</span>
 +
* <span style="font-family:monospace; font-size:12pt;">[[RTI]]</span>
 +
* <span style="font-family:monospace; font-size:12pt;">[[SBC]]</span>
 +
| width="200" style="vertical-align:top;" |
 +
* <span style="font-family:monospace; font-size:12pt;">[[SEC]]</span>
 +
|}
  
  
 
[[Category: Guides]]
 
[[Category: Guides]]
 
[[Category: Processor Status Flags]]
 
[[Category: Processor Status Flags]]
 +
[[Category:Assembly]]

Latest revision as of 16:57, 5 October 2012

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.