CPU Fetch Decode Execute simulator for OCR A Level

CPUs work by following the fetch decode execute cycle.

Von Neumann CPU Simulator showing the fetch decode execute cycle
Von Neumann CPU Simulator showing the fetch decode execute cycle

At Key Stage 3, students in the UK need to have a good idea of the process as a whole:

The fetch decode execute cycle is the loop that CPUs constantly follow in order to get, understand and do each instruction in a program.

At Key Stage 3, students need to understand the role of different parts of a CPU in the Von Neumann model.

A Von Neumann CPU has one memory store (RAM) which stores both data (variables) and instructions (program code).

Registers are fast but small memory locations that can store one item of data or one instruction.

The Little Man Computer model is popular at both Key Stage 3 and Key Stage 4 because it simplifies what happens inside a CPU down to just three registers: an instruction register, an accumulator and a program counter with a very limited instruction set.

For A Level, some additional components have to be understood which makes the Little Man Computer model appear too limited to be used to explain all of the necessary theory. Students also need to be able to explain the purpose and function of:

  • The Memory Address Register (MAR) and Memory Data Register (MDR)
  • The Address Bus, The Control Bus and the Data Bus.

To help fill those gaps, I’ve built a CPU simulator based on the diagram shown in the Craig’n’Dave video below:

The simulator lets you enter in any values into the memory store (as binary, denary or hex) and then either run the whole code or step through each stage in the fetch decode execute cycle.

You can try the simulator here or download the source here.

This tool is designed as a teaching aid to allow teachers and students to step through each line in a binary computer program with an explanation of what each register and bus is doing at every stage.

I hope it’s useful. Let me know if you spot any mistakes or ideas for improvement.

Musical micro:bit sings Happy Easter

singing micro:bit
python code to make a micro:bit sing

This term in Computing Y8s have been looking at the ways that computers can store, manipulate and display images. Amongst other things, we’ve been using BBC micro:bits to create images, animations and games.

One thing we didn’t get time to look at this term was the data representation of sound.

Maplin (the people who sell all sorts of electronic gadgets and maker kit) have launched a competition where you have to use a BBC micro:bit to create a musical instrument so if anyone’s keen on experimenting over the Easter holidays you can have a lot of fun and possibly win £1,000 worth of gadgets.

This is my entry to the competition, to try to win the maker bundle to share out as prizes at the STEM club I run on Monday lunchtimes at Fulford School, York.

The idea is pretty simple: the latest version of micropython for a micro:bit allows you to write code that will get your micro:bit speaking. You can change the pitch of the speech to make it sound like it’s singing and you can change the speed of the speech to make each word last more or less time.

The code below hooks up the built-in accelerometer to the pitch and speed so that you can tilt your micro:bit to get it singing.

I’ve coded in a series of random Easter messages but you can change the text on line 10 if you want to get it singing your own lyrics.

The singing works in the simulator on create.withcode.uk as long as you’re using chrome, firefox or edge. Sadly, I haven’t made it work in Internet Explorer yet – you can download the audio it generates but it wont let you play it automatically.

Have fun, and see what you can create! But if you use my code and win the £1,000 prize I’ll expect my share of the goodies!

What can you make your micro:bit sing?

Happy Easter.

Free tools for teaching data representation of images with python

Free tools for teaching data representation of images with python

In Computing at KS3 in England, students have to learn how images can be stored and manipulated using binary data.

Pupils should be taught to:

…understand how instructions are stored and executed within a computer system; understand how data of various types (including text, sounds and pictures) can be represented and manipulated digitally, in the form of binary digits

This can be a tough part of the curriculum to cover in the limited time available to most schools but it can also be a really exciting way of bridging the gap between the Computer Science and iMedia / IT facets of the course.

In order to follow up from a series of lessons using Photoshop to create and manipulate high quality graphics, I wanted students to be able to understand how the images that they’d just created were stored on a computer.

There are some excellent ‘unplugged’ resources out there where students can see how simple images can be represented by binary data but I wanted Y8 students to be able to write, edit and debug some simple python code that showed them how computers store and process images.

There are two main ways that computers use binary data to represent images. This blog post details how you can use free web based tools to get students to explore how computers can represent and manipulate both bitmap and vector images.

Data representation of images: Bitmap images
Data representation of images: Bitmap images
Data representation of images: Vector images
Data representation of images: Vector images using

The next page gives some activity ideas for getting students to understand how vector images work.