liveBook · Manning

Accumulator register

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

The accumulator register, or A register, is the 6502 CPU register used as a primary operand for arithmetic, logical, comparison, and data-transfer instructions.

The accumulator, also called the A register, is the 6502’s main working register for many calculations. An instruction takes the value already in A, combines it with a direct value or a value read from memory, and leaves the result in A. This makes A the place to load a starting value before arithmetic or bit operations, then save or reuse the finished value. section 4.1.1 section 4.5.2

Use the A register as a short, explicit sequence:

Add a value and verify A

To turn $01 into $06, clear carry, load $01 into A, then add $05: `clc`, `lda #$01`, `adc #$05`. After running the code in the assembler simulator, the debug display shows `A=$06`. The same pattern works when the second value comes from an absolute address, zero-page address, or indexed address. section 4.1.1

Subtraction follows the same accumulator pattern but uses a different carry preparation. With `sec`, `lda #$06`, and `sbc #$05`, A becomes $01. Setting carry matters because SBC also subtracts an extra 1 when carry is clear. section 4.1.2

For bit work, A is both an input and destination. AND keeps bits that are 1 in both values; EOR flips positions selected by 1 bits in the other value; ORA ensures positions are set when either value has a 1. Each operation compares corresponding bits of A with a direct value or memory value and writes the byte result to A. section 4.5.2

Table 4.14 Commands for using the stack (view table figure)

Command

Name

pha

Push A—Pushes the contents of the A register onto the stack

php

Push P—Pushes the contents of the P register onto the stack

pla

Pull/Pop A—Pops the top item off the stack and stores it in the A register

plp

Pull/Pop P—Pops the top item off the stack and stores it in the P register

When A must be preserved while another calculation uses it, PHA pushes its current contents onto the stack and PLA later restores the top stack value into A. section 4.6

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

How deep it goes
Works through addition and subtraction addressing forms, carry setup, logical bit effects, and saving A on the stack.
Examples
Demonstrates direct, absolute, zero-page, indexed, and indirect arithmetic, plus bytewise AND, EOR, and OR results.
What it assumes
Starts with explicit instruction sequences and simulator checks rather than assuming prior assembly experience.
What you can do after
Apply it via 6502 instructions to calculate values, modify bits, inspect results, and preserve A temporarily.
How it connects
Connects the accumulator to carry flags, ADC, SBC, addressing modes, logical operations, and the stack.

Related concepts

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.