Fetch, decode, execute

Fetch
The Program Counter (PC) starts at 0000. This means that the first address in RAM where the computer will look for an instruction is at 0000.




Decode
Now the instruction needs to be decoded. It is sent via the data bus to the control unit, where it is split into two parts. The first part is the operation code or opcode, which in this example CPU is the first 4 bits. This is the command that the computer will carry out. The second part, in this case the second 4 bits, is the operand. This is an address in RAM where data will be read from or written to, depending on the operation.The Control Unit can translate opcodes into instructions. So here the Control Unit translates the opcode 0101 into a LOAD FROM RAM instruction.
Execute
Now the command will be executed. The operand is copied to the MAR, as this is the address of the data that needs to be loaded.The data at address 0100 is then fetched from RAM and passed up the data bus to the MDR. As it is not an instruction but simply data, it is then passed to the Accumulator (Acc).
The 2nd cycle
We’ll now run through the remaining two cycles of the program. The PC now holds 0001, so we next fetch, decode and execute the instruction at that address.
- The PC is at 0001, so this is the next instruction to be fetched.
- The instruction opcode and address operand are placed in the IR, and the PC increased by 1 again.
- Now the instruction is decoded, while the address of the data to be acted upon is placed in the MAR. The instruction turns out to be ADD, which adds two pieces of data together.
- The new data is fetched from the address and eventually ends up in the accumulator, along with the results of the previous cycle.
- To finish off this stage, the two values in the accumulator are passed into the ALU, where they can be added together, as was instructed by the opcode.
- The result is then placed back into the accumulator.
The 3rd cycle
The last cycle is for the instruction at 0010. It uses the opcode 0011 which is STORE and the operand 0110, which is the last address in the RAM shown.
- The first instruction LOADed a piece of data from a specified address.
- The second ADDed this to the data found in another address.
- The final instruction STOREd the result of the addition back into a specified address in memory.
How Computers Work: Demystifying Computation

Our purpose is to transform access to education.
We offer a diverse selection of courses from leading universities and cultural institutions from around the world. These are delivered one step at a time, and are accessible on mobile, tablet and desktop, so you can fit learning around your life.
We believe learning should be an enjoyable, social experience, so our courses offer the opportunity to discuss what you’re learning with others as you go, helping you make fresh discoveries and form new ideas.
You can unlock new opportunities with unlimited access to hundreds of online short courses for a year by subscribing to our Unlimited package. Build your knowledge with top universities and organisations.
Learn more about how FutureLearn is transforming access to education