Registers - Falmouth-Games-Academy/comp310-wiki GitHub Wiki

6502 Registers

PC ~ Program Counter

The program counter is a 16bit register which stores the address of the next instruction the processor should execute. During execution, the program counter will update automatically as it processes instructions. Certain instructions will change the state of this register. For example, JMP.1(http://www.obelisk.me.uk/6502/registers.html)

P ~ Processor Status

This register contains the state of the processor after the last instruction was executed. This register is an 8bit register with each bit acting as a flag to denote different states. To read the processor status it must first be pushed onto the stack with the PHP command or by causing an interrupt.2(http://codebase64.org/doku.php?id=base:6502_registers)

To read more about each bit and the flags they represent see Processor Status FLAGS

S ~ Stack Pointer

The 6502 architecture has a stack that can hold up to 256bytes of memory. The stack pointer stores an 8-bit offset to a memory address in the stack. Stack memory addresses are between $0100 - $01FF. The stack pointer value points towards the memory address where the next element added to the stack will be stored. The stack pointer is automatically updated when an element is either pushed onto or pulled from the stack.

To learn more about the stack and how it works see Stack.

A ~ Accumulator

The accumulator is the most important 6502 register. There are lots of very useful machine language instructions like copying the contents of a memory location into the accumulator or modify the contents of the accumulator or another register directly, without affecting any memory. 5(http://nesdev.com/6502.txt)

Unlike the index registers X and Y, the accumulator has a direct connection to the Arithmetic and Logic Unit (ALU), which is why many operations are only available on the accumulator 2(http://codebase64.org/doku.php?id=base:6502_registers)

X ~ Index Register(X)

The X index register is very important. It has most of the instructions from the accumulator, but there are other instructions that only the X register can do. The X register is commonly used to hold counters or offsets for accessing memory. This is the register used for addressing data with indices, it even has a special mode which allows you to have a vector table on the zero page. 2(http://codebase64.org/doku.php?id=base:6502_registers) 1(http://www.obelisk.me.uk/6502/registers.html) 5(http://nesdev.com/6502.txt)

Y ~ Index Register(Y)

The Y register has lots of similar instructions to the X register, but it has the least operations available.

Image Of where the registers are Located (Edited)

Imgur3(http://www.weihenstephan.org/~michaste/pagetable/6502/6502.jpg)

Note that some say that this diagram is not complete, "It is good for explanatory purposes, but omits a lot of detail." 6(https://www.quora.com/How-come-the-X-and-Y-registers-in-a-MOS-6502-Atari-C64-Apple-II-etc-can-be-incremented-decremented-and-compared-if-theyre-not-connected-to-the-ALU-as-shown-in-the-link)

Picture Processing Unit's Registers

The PPU has 8 registers in the CPU which are memory-mapped. These usually are situated between memory positions $2000 - $2007 6(https://wiki.nesdev.com/w/index.php/PPU_registers). These addresses are Memory Mirrored 7(https://wiki.nesdev.com/w/index.php/Mirroring) in every 8 bytes between $2008 and $3FFF. This means that the memory may be accessed at multiple addresses, causing what seems to be duplication. This is occurs when a full address is not completly decoded (when the chip ignores one or more address lines). These addresses are incompletely decoded as this would take a lot more pins on a chip. Hence this was used to reduce the amount of hardware needed to create the NES.

PPU Registers, Addresses

PPUCTRL - $2000 - Used to help the CPU and PPU communicate

PPUMASK - $2001 - Controls the rendering of sprites and backgrounds and colour effects.

PPUSTATUS - $2002 - Reflects the states of various functions inside the PPU. Often used to determine timing, like at what pixel to draw a certain sprite.

OAMADDR - $2003 - Controls the address of the OAM (Object Attribute Memory) to access. OAM is the internal memory used to contain the list of sprites to display 8(https://wiki.nesdev.com/w/index.php/PPU_OAM).

OAMDATA - $2004 - Allows you to write OAM data.

PPUSCROLL - $2005 - Used to control which pixel from the nametable should be rendered in the top left corner of the screen.

PPUADDR - $2006 - Writes to VRAM to allow the PPU and CPU to share information from each others memory. As the two are not on the same bus they cannot share their memory without this.

PPUDATA - $2007 - Read/Write to the VRAM data register.

OAMDMA - $4014 - Port located on the CPU. Can be used to load bytes from the CPU to the PPU's internal OAM.

Bonus Content

While the 6502 had few registers compared with similar CPUs at that time. It contained instruction sets for an addressing mode called "zero page". This mode could "reference the first 256 words ($0000 - $00FF) in memory"[4]. Developers could consider these slots like registers as the opcodes required less program memory and fewer CPU cycles.[4]

References

[1] http://www.obelisk.me.uk/6502/registers.html

[2] http://codebase64.org/doku.php?id=base:6502_registers

[3] http://www.weihenstephan.org/~michaste/pagetable/6502/6502.jpg

[4] https://spectrum.ieee.org/tech-history/silicon-revolution/chip-hall-of-fame-mos-technology-6502-microprocessor

[5] http://nesdev.com/6502.txt

[6] https://wiki.nesdev.com/w/index.php/PPU_registers

[7] https://wiki.nesdev.com/w/index.php/Mirroring

[8] https://wiki.nesdev.com/w/index.php/PPU_OAM