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:
Register | Name/use |
---|---|
a | Accumulator This is the main 8-bit arithmetic register. A lot of instructions can only operate on a . |
f | Flag The various bits hold flags which signal what happened during recent operations, allowing conditional branching. |
b , c , d , e , h , l | 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 bc , de and hl . hl is a "super-register" a bit like a because it can do more maths. |
ix , iy | Index registers 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. |
pc | Program Counter This is where the Z80 keeps track of where in the program it's got to. |
sp | Stack Pointer Keeps track of the stack which we'll come to soon. |
i | Interrupt Page Address We don't bother with this one, because it has no real use on the SMS. |
r | Refresh This is to do with keeping memory updated, and isn't normally useful. |
a' , f' , b' , c' , d' , e' , h' , l' | Alternate registers 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: b
and c
become bc
, d
and e
become de
, and h
and l
become hl
. You can also split ix
into ixh
and ixl
, and similarly for iy
, but you rarely do that.