C64 Bedtime Coding (ENG) – The CPU Registers (#03)

(Article by Phaze101)

The CPU Registers

The 6510 CPU Registers

In the previous article it was shown that the CPU is using its own Registers which are just memory locations within the CPU, and these permit the CPU to perform its functions.

The 6510 processor has 3 Registers. These are called the A register which is short for the Accumulator, the X register and the Y register. There is also the Status Register (SR) and the Program Counter (PC) plus the Stack Pointer (SP).

The Accumulator (A)

This is used to store an 8-bit number from 0 to 255 or $FF. You can load a value from memory to the Accumulator. It is also possible to load a number directly to the A register. We can also transfer the Accumulator register value to memory.

The accumulator is the only register that can be used for arithmetic operations such as addition and subtraction.

The X and Y Registers

These registers are in a way identical to the accumulator. They can hold an 8-bit value. It is also possible to load a value from memory and store it in these registers. Same thing as the Accumulator you can also load a number directly to them. You can also store the contents of the X and Y register into memory.

The X and Y registers can also be used for indexing and this is a powerful feature of these registers. I will cover this in greater detail when I will be explaining the addressing modes.

The Status Register (SR)

The status register has a serious of flags which are flipped (switched on or off) according to the operations that the CPU performs. It is 8 bits wide.

An example of this is when an operation results in a zero then the Zero flag is set.

Here is a list of the Status Register flags

The Stack Pointer (SP)

The Stack Pointer controls the Stack. The Stack can be compared to a stack of plates. The plate on the top is always the plate taken and if you add another plate it goes on top of the current plates.  This means that the stack uses the method LAST IN FIRST OUT (LIFO).

The stack is used by the system to keep track of the return addresses of the machine language routines, track of interrupt calls and it is used to save contents of internal registers (A, X, Y). The stack is located on Page One of the memory address range that is from $100 (256) to $1FF (511). Each page is 256 bytes hence $100 is page 1. Page Zero is from 0 to 255 of $0 to $FF.

The first number placed on the stack goes to memory location $1FF (256) and subsequent entries are push downward toward the $100 (256)

If the Stack had to be filled up, the system normally crashes. For now, just know that it can only contain a maximum of 256 numbers.

The Basic and the Kernal make heavy use of the stack.

Program counter (PC)

The program counter is a 16 Bit register that can have a value from 0 to 65535. The job of the program counter is to tell the CPU where the current instruction is. This register can’t be accessed directly.

If the instruction is a jump or a branch the new Program Counter (PC) is loaded with the new value and thereby transferring control to some new program memory address location.

CPU Registers layout

Next Week

This is all for the time being. I hope you enjoyed reading it. As always if you have issues please message me. Next article it is too long, and I will have to divide it. This time I will keep you in suspense.

I would like to thank all those of you that wrote to me and expressed how much they are enjoying the series. I hope I will be able to keep up to the level now since you have put me on the spot 🙂

After the next 2 articles things should start taking shape so it is well worth learning the theory.

Coding is fun 😊

 

All Articles

 

English

Article 3
https://sys64738.org/2019/03/c64-bedtime-coding-eng-the-cpu-registers-03/

Article 2
https://sys64738.org/2019/03/c64-bedtime-coding-eng-machine-language-02/

Article 1
https://sys64738.org/2019/03/c64-bedtime-coding-introduction-basics-01/

 

Italian

Articolo 3
https://sys64738.org/2019/03/c64-bedtime-coding-ita-i-registri-della-cpu-03/

Articolo 2
https://sys64738.org/2019/03/c64-bedtime-coding-ita-linguaggio-macchina-02/

Articolo 1
https://sys64738.org/2019/03/c64-bedtime-coding-introduzione-e-basi-01/