6502-assemblylisted
Install: claude install-skill Yuki001/nes-skills
# 6502 Assembly Language
Complete reference for programming the MOS 6502 and its derivatives. Covers the
instruction set, addressing modes, common algorithms, optimization techniques, and
platform-specific considerations.
## Architecture Overview
The 6502 is an 8-bit processor with a 16-bit address bus (64KB addressable memory).
### Registers
| Register | Width | Purpose |
|----------|-------|---------|
| **A** (Accumulator) | 8-bit | Primary arithmetic/logic register |
| **X** (Index X) | 8-bit | Index register, counter, transfers |
| **Y** (Index Y) | 8-bit | Index register, counter, transfers |
| **SP** (Stack Pointer) | 8-bit | Points into page $01 ($0100–$01FF) |
| **PC** (Program Counter) | 16-bit | Address of next instruction |
| **P** (Processor Status) | 8-bit | Flag register: `NV-BDIZC` |
### Status Flags (P register): `NV-BDIZC`
| Bit | Flag | Name | Set when |
|-----|------|------|----------|
| 7 | **N** | Negative | Result bit 7 is set |
| 6 | **V** | Overflow | Signed arithmetic overflow |
| 5 | - | (Unused) | Always 1 |
| 4 | **B** | Break | BRK instruction (on stack only) |
| 3 | **D** | Decimal | BCD mode enabled (SED/CLD) |
| 2 | **I** | Interrupt Disable | IRQ disabled (SEI/CLI) |
| 1 | **Z** | Zero | Result is zero |
| 0 | **C** | Carry | Unsigned overflow / borrow inverse |
### Memory Map (General)
| Range | Purpose |
|-------|---------|
| `$0000–$00FF` | **Zero Page** — fast access, used as pseudo-registers |
| `$0100–$01FF` | **Stack** — grows