Registers

The NES runs with a modified 6502 CPU has 6 main registers that are used both directly and indirectly for almost all aspects of NES Programming. These Registers are the Accumulator(A), Indexes(X and Y), Program Counter(PC), Stack Pointer(S), and Status Register(P). Most registers on the NES are 8-bits, with some exceptions, such as the Program Counter. There are many more registers. They will be included here relatively soon.

Accumulator

Written shorthand in assembly as A The accumulator is an 8-bit register that is the general purpose register for the NES that is primarily used for arithmetic. Many instructions store the results of their operations in the A register, so it is important to not use it for variable storage all the time and care must be taken for important values within the register to not get unintentionally overwritten.

Index Registers X and Y

The NES has 2 index registers, X and Y. They are both 8-bits in size. These registers are helpful for storing temporary variables, but are more important for their use as "indexers", for addressing multiple addresses in memory with logical loops. Some instructions use only the X or Y register exclusively for indexing, while some registers use both. This can be seen on the Instruction Set page that shows the addressing modes of each opcode on the system.

Program Counter

The Program Counter, also known as PC, tells the processor which address in the system memory to execute next. It is one of the few NES registers to be 16 bits in size. This register is universal to virtually all computing systems and it has virtually the same function. Every time an instruction is executed the PC will advance at least 1 to 3 bytes forwards, depending on the lenth of the opcode plus parameters (as seen in the Instruction Set page). If an instruction that is executed is a branching or jumping instruction, the program counter will change to whatever the specified address is. The state of the PC register is critical, because if it gets assigned to an invalid address or into a data address, the program will start to run garbage code and will with almost 100% certainty crash, requiring a reset of the system to recover.

Stack Pointer

Shortened to S, The S register is an 8-bit register that is usually only assigned once, which is at the start of the program to tell it where the stack space in memory is located. The S register is used to read and write to the stack space in memory. If you want to store a temporary variable in memory, you could "push" it on the stack with the S register and then "pull" it off the stack when you need to access it again. If you use a jump to subroutine(JSR) instruction to jump to an arbitrary location in memory, the S register will write or push the 2 bytes in the PC to the stack so that the program will know where to go when execution in the subroutine finishes. When a Retrun from Subroutine(RTS) instruction is encountered, the stack will pull 2 bytes off of the stack and write them to the PC then add 1 to the counter so that the program flow goes back to the instruction right after the JSR call.

Status Register

The Status register, shortened as P, stores several 1-bit flags indicating the current state of the processor. A table is provided below to explain the purposes of the different flags in the register.
The layout of the bits is as follows: (bit 7)NVxx-CIZC(bit 0)