Getting to Know the Z80
The Z80 System
Standard Architecture
The Stack
Instructions and the PC
Internal Structure


So, now we move from the outside of the Z80 to the inside. The Z80's basic, internal system is diagrammed for you below. I could easily throw at you the entire internal CPU diagram, but it's too much for now. So, best to look at it in little parts and then throw the huge diagram at you at the end when you can fully understand what you're looking at. Again, this is a logical representation. If you look back at the picture of what it actually looks like inside the Z80 from under a microscope on the last page, this is not what you'll see:



Now that we're inside the Z80, let's look at what we have there. This is the basic arrangement, the registers, for example, will be detailed later. First thing to get out of the way are the buses again. Indicated are the external data and address buses; we already went over them in the last part. The other thing you see here is the internal bus in red. As you can figure out, this is the pathway of information inside the Z80 itself, again, represented logically.

On the right we have our CU (control unit), the synchronizer of the entire system. Directly to the left of this is the ALU (arithmetic-logical unit). The ALU has a special register on its left input, called the accumulator. The accumulator is a register that can store all the results of the calculations (like what you did in binary math) performed by the ALU while programs running. The ALU has the ability to shift and rotate bits, something you will learn more about in the future. Just know that it's the main register we'll be using for loading, storing and doing math on binary data. You'll be putting the accumulator into your code a lot.

Next, to the left of the ALU, we have our flags (notice the shifter is attached to the upper flag, indicating the carry if you perform a rotate). The flags, as a whole, are typically called the 'status register.' They are responsible for intermediate or final results of an outcome performed by the ALU. As we know from binary math, this is especially important if the outcome of a calculation leads to a carry or overflow. The bits in the flags can be tested by special instructions. This may lead to changes in your program that need to be recognized and dealt with, such as the all important sprite collision factor when two things on screen, such as a character and a bullet, collide. So, depending on the flag and the condition, they can be used to indicate events in your game.

On the left of the flags, you'll see the registers. They've been organized separately just to illustrate. The first two on the left are the general-purpose registers, used by the ALU to manipulate data. The number available to be used in the Master System is six. Bits here are transferred to or from the data bus.

Registers are typically called 'general purpose' because they can be manipulated by the programmer. They can contain anything in bytes to be used, functioning as the CPUs internal memory source. Registers are typically paired so one can function as a data storage device and the other as a temporary form of internal memory. If you check the huge diagram in the section titled 'Internal Structure,' you'll see that the Master System's registers are labeled with symbols like B' and B. This indicates the pair, one is labeled with a letter and the ' symbol, the other just the letter. Together, they can be used to store 2 bytes.

Then you have the address registers, indicated to the left of the general purpose registers. These are 16-Bit registers for storing addresses. They essentially create the address bus and are thus connected to it, which you can see coming out below them. Here's a more detailed image of the address registers using another diagram, taking out the other items you learned about above so we can focus on them:



Contents of these registers are loaded via the internal data bus. Even though they're 16-Bits, the Master System handles 8-Bits, so the data must be accessed through two transfers, not one. In order to differentiate between these 2 bytes if necessary, they are labeled as high or low (H or L). Labeling them can pinpoint which part you want to work with (bits 15 through 8 or 7 through 0). Every CPU has at least two address registers, the Master System included. MUX stands for multiplexer, it's a special device that enables the selection of high or low and puts the data into a single source, the data bus. Now let's look at the address registers separately.

First you have the index register, of which there are two (referred to as IX and IY). As a whole, it can be referred to itself as IX, but because of what I just said, that can be a little confusing. It enables indexing, accessing blocks of data in the memory with a single instruction. A byte added to the contents of IX, called the displacement, is used to generate an address.

Next we have the stack pointer, SP. The SP indicates the address of the top of the stack. We'll learn all about the stack in the next lesson, for now let us just state that the stack is the way data is organized in the Z80. The SP indicates the top of it.

Finally, we get to the program counter, PC. The PC contains the address of the next instruction and keeps programs running smoothly. Programs are sequential, occuring one after the other. After you perform one, it is necessary to bring the next from the memory into the CPU so it can perform this function. First, the data of PC is sent into the address bus to the memory. The memory then reads the data to know the address and sends a word (block of data, not 16-Bits) back to the CPU from this address, which is thus an example of what we call an instruction. Instructions are commands given to the CPU to run programs. These is what you'll be working with in your code.

So, that's it for this part. This concludes the first look inside the Z80. Next, we need to move on to an explanation of the stack in order to understand how data is being moved around in the Z80 before we go further into the interior and finally get to that beast diagram I've been referring to that isn't even up yet. Click below when you're ready. Again, be certain you at least understand the above, you don't have to have it memorized, but it needs to make sense to you. If it doesn't read, read, read again, or post away on the forum for things you need clarified or think need clarified.

Next Page

Main Page
 
Copyright © 2021 Sega8bit. All Rights Reserved.
Contact Us