liveBook · Manning

SEC instruction

As explained in Classic Game Programming on the NES: Make your own retro video game

The SEC instruction is a 6502 processor instruction that sets the carry flag.

SEC, short for SEt Carry, sets the 6502 processor’s carry flag. Place it before SBC when subtracting two 8-bit numbers: SBC subtracts the source from register A and subtracts one more when the carry flag is clear. section 4.1.2

Listing 4.9 Subtracting a value from the A register
sec              #1
sbc <source>

Use SEC immediately before SBC to prepare the carry flag for subtraction. section 4.1.2

Subtracting a direct value

With A equal to $06, SEC followed by SBC #$05 leaves A equal to $01. section 4.1.2

How Classic Game Programming on the NES: Make your own retro video game covers it

How deep it goes
Explains the flag dependency and demonstrates direct, memory, zero-page, indexed, and indirect subtraction forms.
Examples
Demonstrates SEC with direct values and values stored in absolute, zero-page, indexed, and indirect memory locations.
What it assumes
Uses the A register, carry flag, and SBC while introducing their interaction through small subtraction examples.
What you can do after
Apply it via SBC to perform reliable 8-bit subtraction in 6502 assembly.
How it connects
Connects the carry flag, SBC, the A register, and 6502 memory addressing modes.

This explainer was generated by Manning's knowledge graph from the text of Classic Game Programming on the NES: Make your own retro video game. The section links point to the parts of the book it draws on.