Registers are a special sort of memory inside the CPU. They can be accessed much more quickly and operations can be performed using what they contain. Pretty much any time you want to do something with data in ROM or RAM, you have to transfer it to one or more registers, perform the operation, and then (perhaps) transfer the result back again.
There are roughly 22 registers in the Z80, all with short one- or two-letter names. The ones with a single letter name can hold 8 bits (one byte); the two-letter ones hold 16 bits (two bytes). Here’s a quick guide:
This is the main 8-bit arithmetic register. A lot of instructions can only operate on
The various bits hold flags which signal what happened during recent operations, allowing conditional branching.
|General purpose registers|
We can do what we like with these, because (usually) they don’t matter. They can be accessed individually as 8-bit registers or in pairs as
These two 16-bit registers are useful as indices to something else, because you can work with what they point near to without changing the value in them. And they’re useable as 16-bit registers too.
This is where the Z80 keeps track of where in the program it’s got to.
Keeps track of the stack which we’ll come to soon.
|Interrupt Page Address|
We don’t bother with this one, because it has no real use on the SMS.
This is to do with keeping memory updated, and isn’t normally useful.
It is possible to swap these with the regular versions, but not individually.
Some of the 8-bit registers can be paired up to make 16-bit ones:
hl. You can also split
ixl, and similarly for
iy, but you rarely do that.