The Central Processing Unit or CPU is device of programmable logic that performs sequential instructions. Sound good, but what does it mean? Basically, it mean the CPU reads an instruction, does what the instruction says to do, and then reads the next instruction and keeps repeating this process. The CPU reads these instructions from the memory, so the instructions are really just numbers called Machine Code. The CPU decodes these numbers in a part of the CPU called the Instruction Decode Unit. The Data the CPU works with is also numbers stored in memory so the operations done to the numbers must be mathematical in nature. This work is done in the Arithmetic Logic Unit part of the CPU. Because the CPU needs to store some things temporarily I will also need some small memory within it. This memory is called a register.
It will be easier to learn the concepts if we limit our discussion to a relatively simple CPU and use specific data and address sizes throughout this discussion. We will use an 8 bit machine so when we talk about data it will be a byte of data in this discussion. Once you start thinking about larger machines, this could be called a "bite" of data. Our CPU will use a 16 bit address bus and this will be referred to as an address word.
A register is a small piece of memory. In our CPU we will need a 16 bit register since we have a 16 bit address bus. The address register is commonly called the Program Counter or PC register. This name makes sense if you remember that the CPU reads the instructions sequentially. In other words, the register contains the address of an instruction and then increments or counts to the next address to point to the next instruction.
Because the CPU will be performing math operations on the data we will need a place to store the data byte. This will be an 8 bit register since it is holding data from our 8 bit memory. If the CPU is adding a series of numbers together, this register will accumulate the answer. It only makes sense to call this register the "Accumulator".
Lets imagine we are adding numbers to the Accumulator and the Accumulator is currently at 255, or 1111 1111 in binary. If we add a 1 to this we will end up with 256, which is impossible to write in an 8 bit register. The Accumulator will increment to 0000 0000 and "flag" that there is a problem by setting a bit called the "Overflow Flag". It may also set a bit called a "Carry Flag". This is similar to the way most of us have been taught to add numbers in the decimal system and is discussed more throughly in a page called Binary Addition and Subtraction found in the Computer Math section.
if the Accumulator is currently at 0 and we attempt to decrement, or subtract a one a similar situation occurs. The CPU will setting an "Underflow Flag" and possibly a "Borrow Flag". Often it is nice to be able to compare two numbers. This is done by subtracting them and if the answer is zero then we know both are identical. This is indicated by setting a "Zero Flag".
A good mental image of the purpose of flags is to think of a flagman at a roadway construction site. The flag is "raised" (the normal usage of the term in computer talk) when something important is happening. The programmer of the CPU may or may not choose to check the flag. All of these flags are binary values, just a 0 or a 1. All of them are grouped together into one register called the "Flag Register".
Although computers often show the time of day, the type of clock we are talking about here is a piece of logic that continually toggles from 0 to 1 and back to 0. This serves a purpose in the CPU similar to a Sargent calling cadence to troops marching. It keeps all the parts moving along in unison. No part of the CPU will get ahead of other parts.
Clocks keep getting faster and faster. The microprocessors of the 1970's made an off to on and back to off cycle in about 0.000001 second. Another way of saying this is the clocks operated at 1 MHZ or 1 million cycles per second. The last time I looked I saw computers with clocks operating at 3 GHz or 3 billion cycles per second.
There is not much to talk about here except that this part of the CPU is the part that connects the internal parts of the CPU together and connects the internal parts to the data bus, address bus and the correct part of the Arithmetic Logic Unit. The design of this part of the processor dictates what the actual Machine Code will be to perform a particular function.
A small side note related to this is an on-going debate. It takes some time to decode the instructions and if one can reduce the number of instructions to be decoded, one might save time. This is especially true if this includes the most often used instructions. On the other side of the debate are those that say a processor with a large set of instructions can do more complex operations with fewer instructions. One group is promoting RISC (Reduced Instruction Set Computers) and the other is promoting CISC (Complex Instruction Set Computers). It is looking as if the CISC group has won in the marketplace.
The Arithmetic Logic Unit modifies the number in the Accumulator is some kind of predetermined way. This can be by doing what most of us think of as simple arithmetic such as adding or subtracting a number from memory or another register. It could be incrementing or decrementing the Accumulator value. It can also be more digital logical things such as ANDing or ORing the acuumulator with another number or even just shifting the bits in the accumulator register to the left or to the right. This is the fuctions most of us think of when we think of a computer "churning out numbers".
A Preview and a Warning
The next page will discuss in a little more detail the kinds of instructions we will encounter and a little more detail about the amount of time required to perform the instructions. It will be helpful if you read about the Hexadecimal numbering system before reading CPU Part II.
CPU Part III will develop a very small machine code program to add two 16 bit numbers on our 8 bit machine. To really understand that operation, it is helpful to read Binary Addition and Subtraction. None of this math is really complicated, and is very similar to the math learned in the early elementry school grades. Do not let the 4 letter M word scare you (Math) it is worth the effort. Besides, should you really hate the math, there is always the Contact the Author page where you can let all your frustrations out at yours truely.