The CPU and the Fetch Decode Execute cycle
The Central Processing Unit (CPU) is the brain of the computer. It is the component that does all of the clever calculations. It reads the instructions in a program, decides what to do about each instruction and then sends out signals to all of the different pieces of hardware to make things happen. This is quite a complicated idea so we need to produce a model (an abstraction) that we can start working with.
Programs are simply sets of instructions that a programmer has written. When you want to 'run' a program, you might double-click on it in a computer system to 'open' it. When we double-click on it, we are sending an instruction to the operating system to go and find the program on the hard drive, copy it and put the copy in RAM. You can see a copy of part of a program on the left. We won't worry about what the instructions all mean. We will just accept that this is what a typical set of program instructions looks like.
a) To 'run' a program, the CPU has to get the first instruction in the program.
b) It puts the address of the instruction it wants to fetch on the address bus.
c) The computer then fetches the instruction given by this address.
d) It fetches the instruction by putting it on the data bus.
e) The instruction is passed back to the CPU.
f) The CPU then 'decodes' the instruction.
g) What this simply means, is it decides what to do with the instruction.
h) Then, once it has decided what to do, it does it!
i) Carrying out an instruction is called 'executing' the instruction.
j) The CPU sends out signals to all of the other hardware components so that the instruction is executed.
That's it! The CPU has fetched an instruction, decoded it and then executed it. When it has finished one instruction, it does the next one, and the next one and the next one. In fact, this is all the CPU does, all day long.
The Program Counter
We know that computers have different types of memory. One type of memory is RAM. Another type of memory is the Register. Registers are very fast and they help the CPU carry out this process of FETCH - DECODE - EXCEUTE. One register, for example, is called the Program Counter. You can think of it as a box that holds a number. Its job is to keep track of the next address that the CPU must fetch, once the CPU has finished its current instruction (the CPU can only work on one FETCH - DECODE - EXECUTE cycle at a time).
For example, if the first instruction to be carried out in a program in RAM was in memory location 2435 (see the diagram above), the operating system puts 2435 into the Program Counter. Now, when the CPU is ready to run the program, it looks in the Program Counter, sees 2435 and fetches whatever is at that location. Automatically, once 2435 has been fetched, the Program Counter increases by one, to 2436. When the CPU has finished fetching, decoding and executing the instruction, it simply goes back to the Program Counter, looks at the address in there and repeats the above process, increasing the Program Counter by one every time an instruction has been fetched. This is a very simple but effective way for the CPU to know what to do next. The thing is, the CPU can do all of this really quickly - billions and billions of times a second!!
Another register worth mentioning at this point briefly is the Accumulator. This is simply the special register where data is worked on. Again, you can think of it as a box. If I wanted to add 4 to 7, for example, I would fetch 4 from RAM and put 4 in the Accumulator. I would then get 7 from RAM and add that to whatever was in the Accumulator. I would then store the result briefly in the Accumulator before moving it back to somewhere in RAM to be used later. All calculations of any description are done using the Accumulator. In fact, CPUs often have a few of these important registers, to help them process data quickly.
Not all CPUs are made equal
How fast a CPU can go is very broadly given by its clock speed. This is measured in Hertz. 1 Hertz means '1 cycle every second'. 30 Hertz means '30 cycles in a second' and so on. CPUs have a crystal attached to them that vibrates. For example, you might have a 2.3 GHz processor. This means that the processor's crystal vibrates at 2 300 000 000 times every second. Now, if it takes one clock cycle for the processor to do one FETCH - DECODE - EXECUTE instruction, that means you can do two billion three hundred million instructions every second!
Actually, it's not really quite as simple as this but the clock speed is a very broad indicator of how fast the processor can go. Other factors include what the processor is made of - Some components are designed to go faster and are more reliable than others. That's why some processors cost more than others. Another factor is how many 'cores' a processor has got. A 'core' is like a mini processor within the main processor. Some of you may have a CPU at home in your computer that is 'dual core' or 'quad core'. The more cores, the better the likely performance because you can do more things at once, generally speaking!
Q1. Copy and paste the table into a word processor. Link up the words on the left with the descriptions on the right by drawing lines between them.
|Decode.||The place where you can find programs you are currently using.|
|The CPU.||The C in CPU.|
|1 Hertz.||These are used to send addresses and data between the CPU and RAM.|
|Accumulator.||A mini processor within the main processor.|
|Hard disk.||The place where you can find the address of the next instruction to fetch.|
|Core.||The brain of the computer.|
|Busses.||You do all the calculations here.|
|Program Counter.||This comes before 'Execute'.|
|Central||The CPU doesn't work directly with this to run programs.|
|RAM.||1 cycle every second.|
Q2. Write out as a series of steps how the CPU executes an instruction.
Q3. What is the maximum number of instructions the CPU work on at any one time?
Q4. This type of processor design is known as a Von Neumann processor. Use the Internet to find out why.
Q5. What is the unit used to measure 'cycles per second'?
Q6. What does a CPU do at the end of a FETCH - DECODE - EXECUTE cycle?
Q7. Give reasons why some processors can work faster than others.
a) Look up 'pipeline processors'. In what way do they work differently to the Von Neumann processor described here?
b) Look up 'maths co-processor'. What does one of these do that makes it different to a Von Neumann processor?