Sega Master System / Mark III / Game Gear
Sega8bit & SMS Power! 2013 Event - 10th August 10 weeks and 6 days from now
Registers are fast memory areas inside the CPU which are used to temporarily store data. In most cases, you must copy data from memory into a register before performing an operation on it, or use a register as an index into memory.
The Z80 has 26 accessible bytes of this kind of internal memory, whose bytes (sometimes words) all have their own names. Some internal registers also exist. The registers (with their number of bits in parentheses) are:
|A (8)||F (8)||A' (8)||F' (8)|
|B (8)||C (8)||B' (8)||C' (8)|
|D (8)||E (8)||D' (8)||E' (8)|
|H (8)||L (8)||H' (8)||L' (8)|
|IX (16)||IY (16)|
|SP (16)||I (8)||R (8)|
Each group has its special property:
A, B, C, D, E, H, and L can be directly accessed by the instructions of the CPU, and the pairs BC, DE and HL can be treated together as if they were 16-bit registers. In this case B, D and H are the more significant bytes (holding the greater powers) of these words, respectively. A and F are actually independent of each other, but they are sometimes paired.
IX and IY are 16 bits long, and they are very similar to HL in functionality. These three are often used to address the memory, i.e. to determine which byte of the memory we are referring to. IX and IY are only divisible into 8-bit parts using undocumented instructions. These instructions are actually officially defined in later versions of the CPU, and they work on every Z80, even on the older ones. The term 'undocumented' is rather traditional. IX is divided into IXH and IXL, while the two halves of IY can be referred to as IYH and IYL.
SP is the stack pointer. The stack is a place where the values of 16-bit register pairs can be saved for later retrieval.
I stands for the Interrupt Vector; it is not normally used on Sega 8-bit hardware.
R is the Refresh register, whose value is incremented by the Z80 as it reads instructions from memory (only affecting the low seven bits). The value read from the R register can be used as a (not very) random number, or used as part of a more complex random number generator.
PC is the abbreviation for Program Counter, and it always contains the address of the next instruction to be executed. It cannot be accessed directly by any of the instructions, but can be manipulated using the stack.
F is the Flags register; its bits give information about the results of the operation carried out by the preceding instruction(s). It cannot be accessed directly either.
The registers denoted by apostrophes are the shadow registers. They always come in pairs. There are special instructions that exchange the values of the shadow registers with their corresponding pairs, and neither of the other instructions can access them. They are normally used for saving data, but in a different manner than that of the stack.
All the registers have some kind of special role. These roles are connected to certain instructions, and will be explained by the documentation for those instructions. Besides these special roles, most of the registers can be used for general purpose data storage. The exceptions are F, PC, R and I; SP can be used for storing data temporarily, but this usage is not recommended.