
For most people a computer is a magical box that does amazing things from showing the latest videos whilst on the move, or playing a game with amazing graphics and sound with friends online or even something simple like writing and reading emails. The computer is like a genie – “phenomenal cosmic power, in an ity city living space” Aladdin.
The reality is that computers are complex with things happening billions of times a second at the atomic level. However, computers where built by humans and so they are understandable if we start at a high level and then slowly go through the layers of engineering to see how it works.
Level 0 – the logical level
At this level we don’t need to know anything about electronics or computing but just how the concept works. For computers we need to define what a computer does and that is process input to an output based on instructions. Easy. We do this all the time. Let’s say the process is addition – adding numbers together. The input is two numbers and the output is the result of adding them together.
| Input | Process | Output |
| 1 5 | 1 + 5 | 6 |
This may seem over simplistic (which it is) but this is at the heart of every computer: input > process > output. At this level input is called data (and yes it would be datum when singular) and the process is called an instruction.
When you read the above you can work out where the numbers are but for machines we need to tell the machines where to get that information from. To do this we store the data in an address in this example address 0 and 2.
| Data Address | Data Value | Process | Output |
| 0 1 2 | 1 5 | address:0 (1) + address:2 (5) | 6 |
The advantage of this is we can change what is in the different addresses so the process can add different numbers and output the result. This is how calculators work. You press a number button which is stored in memory and is also displayed to the screen. You then select a process, like addition (+). Then select another number which is the same process as the first number. Now there are two numbers in memory and a process – addition. Finally you press the equals (=) button. This executes the calculation in the calculators arithmetic engine: 1 + 5 = 6. The result is stored in memory and displayed on the screen.
This pattern is how a computer works:
- Store data (the numbers) or the instructions (the maths operations) in memory
- Fetch the data from memory
- Put the data and instruction together (decode them)
- Execute the data and instructions to get an answer
It’s more or less that simple for a computer. There are a few things we need to add to make it more like a computer you are used to which gets to the heart of what a computer does compare to a calculator. Let’s say we want to add 1 to the result of the last calculation 1+1=2, 2+1=3, 3+1=4 … . To allow this to happen we need to have a way of moving everything forward once the calculation is done so we don’t trip over ourselves. To do this we need a beat, a rhythm to move the stuff from memory to the arthimetic engine to do the calculation and store the result. There are two things in a computer that does this: 1) the clock and 2) the program counter. The clock keeps the beat or keeps time like a clock ticks 60 times a minute with each second being the same length. This beat or tick works with the program counter to move the program from 0 at the start to say 60 if the clock tick 60 times a minute. This would be the frequency of the clock. Frequency is measured in cycles per second with a universal unit of the hertz. 1 Hertz is super slow. Modern computers have clock speed in the Gigahertz range (1,000,000,000 cycles/second) but that just means it can do things very fast – remember it’s still a simple process. The clock works with the program counter with the program counter keeping the score – every time the clock ticks a cycle completes and the program counter goes up by one and what ever the number is is where the program has to get it’s information from memory.
To summarise what we have covered so far.
- Memory to store instructions or data (numbers in our example) both to start and the result as we may use the result in the next instruction
- Arithmetic engine for the doing the arithmetic
- Clock and counter to move through the instructions in the right order and not get confused where things are
These are the very basic parts we need to do some level of computing. But … we need to improve, tweak these three components to make it go from a logical level to one that works.
Memory and Registers
First we need to refine how we store data. Unlike a calculator which is a slow process limited by pressing buttons a computer has to be faster as it makes billions of calculations (executing instructions) a second. To make things faster we have different forms of memory when we look to process instructions and data. Before we get into some of the details remember apart from Read Only Memory (ROM) all memory is volatile – it is only held when power is going through the computer – once the power goes the memory is lost (this is correct at this time and level – it gets more complicated when we look at soft-power when a computer is “turned-off” or when a computer copies normal memory to a stable state as a working back-up like when your computer crashes and you have recovered files. Importantly this is not in the GCSE).
In our example calculator example we stored the input from a button press into temporary storage or memory, just like your memory when you are doing a job or calculation. For things we will need but are not working on that is stored in RAM or random access memory (specifically it’s called Dynamic RAM or DRAM). It’s called random access as the computer doesn’t have to go through a list of stuff searching for something but be given an address and go directly there quickly which is important when you’ve got a demanding job like the CPU.
When it comes to memory RAM (specifically DRAM) is pretty fast as it needs to move data from multiple inputs to the CPU and record anything sent back. But it’s not the quickest – that is a specialist form of memory similar to DRAM called Static RAM or SRAM. The difference between the two is due to the way that data is written to them with SRAM capable of being written to faster and being more stable (DRAM needs to be refreshed to keep everything in place whilst SRAM does not). The speed and stability of SRAM make it perfect way of storing data that the CPU needs very quickly. Note: DRAM and SRAM are not covered in the GCSE but I wanted to call out the different types of RAM.
The memory stores that the CPU reads from and writes to are called registers. Like all registers the CPU registers store data but unlike other registers the CPU registers are just holding areas needed to complete a CPU process. Registers are named connected to other parts of the computer through circuits called buses as they transport things from one end to another.
There are many registers in a typical CPU but for this introduction we just need to know they are small and very fast areas of storage that the CPU will need.
The final memory type is cache. Cache like the name suggests stores data in small amounts locally for the CPU in SRAM. Cache has similar speed to the registers but it’s further away from the CPU compared to the registers. Cache is used to store data that will be used multiple times so instead of going back to the RAM to be told to add the last two numbers go to a local “cached” instruction which is a lot quicker. Cache memory really comes into play when we look at multi-core processors that I’ll cover later as we need to understand one CPU with one core at the moment.
In summary there are many types of memory. Apart from ROM all are volatile – the data is lost when the power goes off. DRAM is RAM external from the CPU and stores all the things the CPU will be or has worked on. SRAM is internal RAM as it is on the CPU chip and makes up the CPU registers and cache.
CPU Registers
We need to give some detail on the registers that are in the CPU as these are part of the how the CPU processes. There are xxx registers in the CPU and then all store only one piece of data at a time. I’ll go through them in order of use.
- Program Counter (PC) – holds the memory address of the instruction for each cycle e.g. 1 means go look at address 1 for an instruction
- Memory Address Register (MAR)– holds the memory address next to be fetched from memory (can be DRAM or cache). The program counter value is copied to the MAR so the program is read in the correct sequence.
- Memory Data Register (MDR) – holds the data or instruction returned from memory that the MAR fetched or data produced from a doing a calculation that will be returned back to RAM. Importantly the MDR is used for both staging data and instructions to be
- Current Instruction Register (CIR) – hold the current instruction that the control unit will decode and then execute. Note: for the OCR GCSE this register is not included but it is included in other GCSEs. For OCR the instruction is copied to the control unit which decodes and then executes the instructions. More on instructions in a bit.
- Accumulator – holds the data that will be worked on by the ALU or holds the data that ALU has already worked on which will be returned to the MDR before saving to RAM or passed onto another component of the computer like the graphics card. Although we don’t call the accumulator a register it is.
The MAR and MDR (and CIR)are the primary registers that fetch and store data and instructions from memory before passing them on the secondary registers in the control unit (CU) and arithmetic logic unit (ALU). The CU and ALU are the processes of the central processing unit with the CU unpacking and ALU on working on instructions and data.
What makes up Memory? Data and Instructions (with addresses)
A lot has been said about memory and how it’s move around in and out of the CPU but what actually is memory – what’s it made up of?
First computers are really only have two things – data and processors. Data is stored before it’s processed or is created after processing and is then stored. Storage of data is either in primary storage – memory, which is temporary or ‘volatile’ (it’s not stable, not it’s explosive), or secondary storage – drives, which is permanent (they are called drives as the first ones had drive mechanisms). A drive can be either a hard disk drive or a solid state drive. The difference it’s important at the moment. Both primary and secondary storage can be written and read as many times until the electrical components give out. Flash memory is also a form of secondary storage as it’s not memory and stable.
The stuff that makes up memory is one or two things:
- data (well, it’s datum for the singular of data, plural) – a number, letter, symbol
- instruction – a verb, a doing thing, add, subtract, compare
“Data” held in memory will hold both data and instructions. Instructions have two parts: a verb and a location i.e. add 5. The add part hopefully is obvious but the 5 that’s trickier. The 5 is an address to find data in RAM like the address of house in at a town, or a location of something in a warehouse. At this address there will be a number as the instruction is add. If it wasn’t a number then there would be an error as the CPU can’t add a non-number to a number (if you’re thinking, “yeah you can: 6 + a = 6a” that’s not adding but appending. But we’ll get to that when we get to programming and operations and datatypes. For now memory has either instructions with an address to data, and data (but it’s datum when it’s singular which it is but anyway it’s not an English).
The Processor of the CPU
So far we have covered memory and that it stores data and instructions. We have also covered temporary storage of memory in registers as either instructions or data. We also mentioned a the program counter that keeps everything beating to the same time and lastly we touched on a store of data that will be worked on or has just been worked on as the accumulator. Great. But what does the actual processing? The action – the money maker?
The processor is all the components put together like the parts of an engine. However the bit where the fuel goes in and the bang goes off (or rotates if it’s electric) and drives the pistons the CPU is called the arithmetic (and) logic unit (ALU) and it does two things: 1) arithmetic (maths and stuff) and 2) comparing things (equal to, more than, less than stuff). At the heart of the ALU is some very complex electronics with transistors and capacitors which I don’t anyone really understands. For this (and my level) the ALU executes an instruction and returns the result like 1 ADD 1 return 2. It’s important to remember that unlike maths we do in school the computer uses equals differently to us humans. Equals to a computer means that the data held in its calculation is the same as something else is is comparing it to. So 1 add 1 is two data points returning 1 data point 2.
The Control Unit – keeping things under control
The last thing we need to mention is the hard working but not very glamorous is the control unit that keeps everything in check and does the decoding (unpacking and reading) of the instructions that have fetched from memory. The CU contains the program counter or clock, to keep things running at the same pace (trillions of times per second) – it needs to be controlled.
A recap of all the pieces for our computer to work
- RAM (volatile memory where programs are loaded into from the hard drive). Place where CPU fetches instructions and data from before processing and returns data to afterwards.
- Program Counter – keeps the all the parts moving together in the same time. Also tells what line everyone is singing from.
- Holding Registers: Memory Address Register (MAR), Memory Data Register (MDR), Current Instruction Registry (CIR)
- Buses: routes that data travels along – address bus is for addresses, data bus is for data, and the control bus is controls. Different buses(roads) as signals have to travel at the same time and they would clash otherwise.
- Control Unit: decode instructions and
- Accumulator: holds data either to be processed or the result of a process
- Arithmetic and Logic Unit
Now we have all the pieces, the architecture, that we need to show how the CPU works.
Fetch – Decode – Execute: the process
The overall process for a CPU is done through 3 cyclical steps:
- Fetch – go and get something to work on and bring it back
- Decode – setup the instruction (if an instruction is brought back) for …
- Execution – crank the handle and process the instruction with the data that is loaded
OK. Sounds easy but let’s break it down to include the components we have described and see if it still makes sense. To help with this we need a super simple program
Add Two Numbers
English …
Welcome!
Enter your first number: <user enters number from keyboard>
Enter your second number: <user enters number from keyboard>
<display first number + second number>
Python Code …
num1 = int(input(“Enter your first number:”))
num2 = int(input(“Enter your second number:”))
num3 = num1 + num2
print(num3)
Hopefully that is clear and don’t worry about the python code. All you need to know is we are taking in two number, add them together and then outputting the result.
We start assuming we have entered two numbers already and for this example the numbers are 1 and 2 so the result will be 3. The loaded program in memory looks like the following table. To Help tell the difference between addresses and numbers I’ve made the address start at 100 but they can start at any number increasing by one after each fetch.
| Memory Address | Data |
|---|---|
| 100 | LOAD 104 |
| 101 | ADD 105 |
| 102 | STORE 106 |
| 103 | |
| 104 | 1 |
| 105 | 2 |
| 106 |
Fetch – the first instruction
- Program counter starts at 0 (zero)
- 0 (zero) is copied to the Memory Address Register (MDR) along the control bus. MDR set to 0.
- MDR goes to RAM memory address 0 along the address bus and copies what is at address 0 in this case LOAD 104
- What is at address 0 is copied to the Memory Data Register (MAR) via the data bus (LOAD 104)
- If the data returned is an instruction it is copied to the Current Instruction Register (CIR) (LOAD 104)
- The data from the CIR (or the MDR if we just exclude the CIR for simplicity) is copied to the Control Unit for the next stage (Decode). With a CIR and MDR we can separate out instructions and values.
- Program counter increases by 1 to 101
That is the end of the fetch cycle. You can see we have just fetched something from memory but we don’t know what it is yet. The control unit, CIR, Accumulator, and ALU have not been used in this part of the cycle. With the fetch complete can start but it is possible for a fetch to be happening at the same time.
Decode
- Control unit decodes (read and setup) the data copied from the MDR – LOAD 4
That’s it. The decode is simple as it unpacking what it has been given and then getting ready to do the last stage – Execute.
Execute
Control Unit executes the instruction in this case LOAD 104. It’s helpful to break this into two parts: 1) LOAD – this means put something in the accumulator for a later. 2) 104 – look in memory at address 104 for the thing that will be load – in our example the number 1 (or whatever the person entered)
- Control Unit set to ready to load something into the accumulator due to the LOAD instruction
- Control Unit updates the MAR via the control bus with address 104 (from our LOAD 104)
- MAR sends a signal to memory for data at address 104 – which is the number 1
- Data is copied from the memory to the MDR now holding number 1
- MDR value is copied to the accumulator
That is the end of the execute and the end of the fetch-decode-execute cycle. At this point we have the number 1 loaded in the accumulator – not very exciting. We have to do another cycle to add the second number.
Do the maths – ADD
I’ll summarise this bit to save a bit of time. The fetch is the same but the MAR is looking at address 1 as the program counter has increased by 1 (0+1). At address 1 we have ADD 105. A little care is needed here as it can be tempting to miss what we are doing and just add 105 to 1. Remember [instruction : address location]. At the end of the fetch the Control Unit has the instruction ADD 105.
Decode – setup for an addition with the value from address 105 which is our second number: 2.
Execute. Now it gets a little more interesting. ADD is an arithmetic instruction so we need the ALU.
First the number in the accumulator is copied to a slot in the ALU. It’s taken from the accumulator first to ensure we are doing the arithmetic in the right order and the accumulator is freed up.
Next we do the same as before – we get the MAR to look at address 105 and return it to the MDR which copies the data to the accumulator exactly like the first round but it also copies the value to the ALU taking up another slot. We now have 2 numbers an mathematical operator setup.
The ALU adds the two number (1 + 2 ) and stores the result back in the accumulator. That’s the end of this FDE cycle. Now the final part.
Return the result – Store
The last part of this program is to print the result to the screen. Everything is the same as before. This time we fetch STORE 106. Decode STORE 106 which means store the data that is in the accumulator to memory address 106. Memory address 106 is empty so the data in the accumulator is stored there.
This value is then printed to the screen. How the value is printed to the screen is beyond the scope of this example.
This brings us to the end of the CPU architecture and the CPU cycle. We have covered a lot but with these basics understood it will massively help your computer science development because at the end of the day program fails when the CPU can’t work properly.
Next > Memory and Storage

