liveBook · Manning

Hardware register

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

A processor register is a small, directly accessible storage location holding an instruction operand, address, or processor state value.

A hardware register is a small storage location inside the processor. The 6502 uses registers to perform calculations and move information, making them faster to access than external memory. Because the 6502 has very few registers, programs regularly move values between registers and RAM. section 3.2 section 3.2.2

Registers are not general-purpose variables with unlimited capacity. They hold the temporary values needed for operations such as adjusting an object’s coordinates or adding a player’s score, while longer-lived game data remains in memory. section 3.2 section 3.3

The principal 6502 registers have distinct jobs:

  • A, the 8-bit accumulator, performs primary arithmetic operations and accesses memory. section 3.2.2
  • X and Y, each 8 bits, act as indexes in some addressing modes. section 3.2.2
  • PC, the 16-bit program counter, points to the next instruction to execute. section 3.2.2
  • S, the 8-bit stack index, indicates where the next stack element will be written. section 3.2.2
  • P, the 8-bit status flag, records CPU state and information about the previous instruction’s result. section 3.2.2
Table 3.5 The registers available in a 6502 processor (view table figure)

Register

Size (bits)

Description

A

8

Also called the accumulator. It is the primary register for arithmetic operations and accessing memory.

X

8

Used as an index in some addressing modes.

Y

8

Used as an index in some addressing modes.

PC

16

Also called the program counter. It points to the address of the next instruction to be executed.

S

8

Also called the stack index. It indicates where the next element will be written to the stack.

P

8

Also called the status flag. It contains the current state of the CPU or information about the result of the previous instruction.

Use the register table to compare each register’s size and role before choosing where a value belongs. section 3.2.2

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

How deep it goes
Defines the 6502 registers and their roles, but stops short of a full assembler tutorial or detailed instruction walkthrough.
Examples
Uses player-ship location, player score, music progress, object coordinates, and register-role diagrams and tables.
What it assumes
Assumes familiarity with bits, bytes, and memory as storage, while introducing registers as processor variables.
What you can do after
Apply it via 6502 assembly by loading game data into registers for calculations and moving results back to memory.
How it connects
Connects registers with RAM, ROM, zero-page memory, addressing modes, arithmetic, the stack, and processor status.

Also explained in

Compare how 4 books explain hardware register →

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.