Overview of the CPU 6510 Register Set for the C64


One of the most important things before you write any Machine Code for your C64 is knowing what the Registers of the CPU 6510 are, what they do and how you can use them in your programs.

RegisterFull NameSizePrimary Function
AAccumulator8 BitArithmetic and Logical Operations
XIndex Register X8 BitIndirect Indexed or Absolute Indexed Addressing Modes
YIndex Register Y8 BitIndirect Indexed or Absolute Indexed Addressing Modes
In conjunction with Accumulator to form 16 Bit values
PC / IPProgram Counter16 BitStore Memory Address of currently executing Instruction
PStatus Register8 BitSaves the states of the Processor Flags
CPU 6510 Register Set

The CPU 6510 has essentially the same register set as the CPU 6502 which is its direct predecessor. For your programs you will use the Registers A, X and Y most of the time. When you have to check for a certain status you will look into the Status Register (P). The Program Counter (PC) stores the Memory Address of currently executed instruction. One can manipulate it with Jumps, Breaks and Interrupts.

Now that you know the primary usages of the Registers maybe you want to know how these are applied and what else you can do with them. Read on for a detailed description.

Detailed Functionality of the C64 Registers

Although you can use most of the Registers to store whatever you want in them, as long as it fits in size, they have special purposes you should be aware of. The special purposes of the Registers are summarized in the following paragraphs.

Please note that all code examples are in the C64 Machine Code. You can assemble them with the ACME Assembler in default configuration although other Assemblers may also work.

Accumulator

The Accumulator Register, simply referred to as A in the Machine Code, is primarily used for arithmetic and logical operations. The result of these operations will be stored in this register and many instructions implicitly refer to it. Often times you will find yourself using a mixture between explicit and implicit access to the Accumulator. Look at the following example for simple addition.

Index Register X

The Index Register X is used for the Indirect Indexed Addressing Mode and the Indexed Absolute Addressing Mode. In both cases you load a value into the X Register which is then used as an Offset to the given address. This is useful if you want to go through some consecutive addresses in a loop. You just increment X and add it to the given Base Address in each iteration. Look at the following example for a view on Indexed Absolute Addressing Mode with Register X.

The Indirect Indexed Addressing Mode is pretty much the same, with the significant difference that the Base Address is stored in the memory and therefore is accessed indirectly. Please note that addresses are read with LSB first, so if you store $00 at $02 and $42 at $03 and then read and indirect address with ($02), the resulting address would be $4200. The next example illustrates this fact. Also keep in mind that this works only in the Zero Page Addressing Space.

The CPU 6510 has a total of 13 Addressing Modes which are not all described here. The goal is to understand how Indexed Addressing with the Index Registers works.

Index Register Y

The usage of the Y Register is basically the same as the X Register, as it has the same addressing modes. However, one can also use the Y in conjunction with the Accumulator in order to do things that need 16 Bit of space. It can either form a Memory Address Location or it can form 16 Bit Signed Values which you need in Floating Point Arithmetic. In that case the low byte of the Address is stored in the Accumulator and the high byte is stored in the Index Register Y, referred to as (A/Y). The example shows the usage as a Address Location in Memory.

For an example on how to do Floating Point Arithmetic you can visit Codebase 64 (opens in new tab), as this would go way beyond scope here.

Program Counter PC

The Program Counter is also known as the Instruction Pointer (IP). It is the only 16 Bit Register in the CPU 6510 and it stores the Memory Address of the currently executing instruction on the C64. You can modify the Program Counter with the usage of some instructions like branching or jumping. When the CPU fetches an instruction from the Memory, the value of the Program Counter is issued on the Address Bus and automatically incremented by the CPU.

Status Register P

The Status Register P is a 8 Bit Register, but its value is not considered as a whole. You’d rather watch each Bit individually. These are then called Flags and therefore the Status Register is also called Flag Register. We will not go into detail about what these flags mean, but rather view how you can read and write them. There are instructions that manipulate the flags, and you can get a flag value with the help of bit masking.

You can also save the current Status Register on the Stack and retrieve it later with the two Machine Code Commands PHP and PLP.

Show Current C64 Register Values

If you run your code in Debug Mode in an IDE like C64 Studio, you have a window where you can see all the Registers with their current values. This could look something like this:

C64 Registers and their current values in C64 Studio Debug Mode
C64 Registers and their current values in C64 Studio Debug Mode

As you go through your code step by step you can see how the instructions affect the values of the different Registers. This is an invaluable help if you want to understand how a program works or if you’re chasing a nasty bug.

C64 Registers used in a Program

If you want to see the usage of some of the Registers in action, you can read my Hello World in the C64 Machine Code Example, for instance.

Marco Lieblang

Professional Programmer since 2003, passionate Programmer since the mid 90's. Developing in many languages from C/C++ to Java, C#, Python and some more. And I also may know a bit about Assembly Languages and Retro Systems.

Recent Posts