Rejestry

Z ZX Spectrum Wiki
Wersja Pear (dyskusja | edycje) z dnia 10:20, 30 maj 2014

(różn.) ← poprzednia wersja | przejdź do aktualnej wersji (różn.) | następna wersja → (różn.)

Registers are sections of very expensive RAM inside the CPU that are used to store numbers and rapidly operate on them. At this point, you only need to concern yourself with these 8-bit registers: A, B, C, D, E, F, H, and L.

The single-letter registers are 8 bits in size, so they can store any number from 0 to 255. Since this is oftentimes inadequate, they can be combined into four register pairs: AF BC DE HL. These, along with IX and IY, are 16-bit, and can store a number in the range 0 to 65535.

Although for the most part register use is interchangeable, it is common coding practice to use them in this particular manner: 8 Bit registers

A is also called the "accumulator". It is the primary register for arithmetic operations and accessing memory. B is commonly used as an 8-bit counter. C is used when you want to interface with hardware ports. D is not normally used in its 8-bit form. Instead, it is used in conjuncture with E. E is again, not used in its 8-bit form. F is known as the flags. It is the one register you cannot mess with on the byte level. It's uses will be discussed later in the Flags and Bit Level Instructions Section. H is another register not normally used in 8-bit form. L is yet another register not normally used in 8-bit form. I is the interrupt vector register. It is used by the calculator in the interrupt 2 mode. R is the refresh register. Although it holds no specific purpose to the OS, it can be used to generate random numbers. IXH The higher (first) byte of the IX register. Note that I is not the higher byte of IX. Combines with IXL to make the IX register. IXL The lower (second) byte of the IX register. When combined with IXH these two registers make up the IX register. IYH Again, this is the higher byte of the IY register. Note that IYH is different from both I and IXH. Combines with IYL to make the IY register. IYL The lower byte of the IX register. Combines with IYH to make the IY register. 16 Bit Registers

AF is not normally used because of the F, which is used to store flags. BC is used by instructions and code sections that operate on streams of bytes as a byte counter. Is also used as a 16 bit counter. DE holds the address of a memory location that is a destination. HL The general 16 bit register, it's used pretty much everywhere you use 16 bit registers. It's most common uses are for 16 bit arithmetic and storing the addresses of stuff (strings, pictures, labels, etc.). Note that HL usually holds the original address while DE holds the destination address. PC The program counter. It hold the point in memory that the processor is executing code from. No function can change PC except by actually jumping to a different location in memory. SP The stack pointer. It holds the current address of the top of the stack. IX is called an index register. It's use is similar to HL, but it's use should be limited as it has other purposes, and also runs slower than HL. IY is another index register. It holds the location of the system flags and is used when you want to change a certain flag. For now, we won't do anything to it.