Registers

Registers are the processor's working memory; you can think of them as hands. Imagine the memory as a giant bookshelf - you want to go and replace book 74523 and book 263. First, you need to take 74523 in your hand, then take 263 in your other hand, and put 263 in its place, and then carry 74523 to where 263 was.

The register memory is, again, infinite loops: Flip Flops or SRAM cells, or other kinds but with the same idea. They can store bits of information that the rest of the CPU can use - for example, the ALU can use them to calculate things, or the Control Unit can make decisions where to jump next.

Z80 has 14 registers, the famous 6502 chip has 22, while ESP32-C3 has 32, and the M1 chip has 600, but the program can use only 32 of them. Z80 registers hold 1 byte (8 bits) of data. Some registers can be used by our program and some cannot. For example, there are status registers that contain various flags that carry information from the previous instructions, such as whether the result of the instruction is zero or if it is overflowing, etc.

The Program Counter (PC) register (also called Instruction Pointer, or IP) is a register which remembers which instruction we are about to execute. A Jump, for example, means setting the IP to specific values, and then at the next clock tick, it will load the instruction from that address.

With some registers you can do whatever you want - put any data, read any data, do operations on them, etc. These are called 'general purpose registers', and others like IP or the flags register are called 'special purpose registers'; they only do what they are supposed to do. For example, one of the ESP32-C3 registers is just zero - it's always zero. You can write to it, it will do nothing; you can read from it and it will always read zero.

In our computer, we will use the SN74LS373 register, check out this bad boy:

It has 8 data inputs D0-D7, 8 outputs Q0-Q7, Clock input C, and Output Control OC. On the inside, it has a bunch of D flip flops. SN74LS374 is a 3-state register, meaning the output can be HIGH, LOW, or floating, meaning it's disconnected. We will explain later why the floating state is needed.

https://www.ti.com/lit/ds/symlink/sn74ls374.pdf

The difference between '374 and '373 is how the C pin works; in '374 it is Clock pulse triggered.

In order to write data into '374, we have to set the bit pattern on D0-D7, and then pulse the clock. On the rising edge of the clock, it will store the pattern.

           _____
CLK  _____/     \_____ 
          ↑

To read the data, we just need to disable OC and read from Q0-Q7; it will have the last stored pattern.

If we use '373 then C is Chip Select, meaning data can change only if C is enabled.