Giles Booth Turns a BBC micro:bit Into a Four-Instruction, Five-Bit Educational CPU
Considerably less powerful than the BBC micro:bit itself, Booth's five-bit CPU is designed for educational use — and could be upgraded soon.
Maker and educator Giles Booth has published a guide to turning a BBC micro:bit development board into a very simple CPU — effectively creating a basic computer based on five-bit words, using the LED matrix as a display.
"Could you create your own processor with a small instruction set using a micro:bit," asks Booth. "This is what I came up with. A micro:bit CPU. I decided my micro:bit CPU would be a 5-bit computer, rather than 8-bit as you might expect. This is because I want to show the contents of memory, instructions and so on using the LEDs on the micro:bit’s display, which is made up of 5 rows of 5."
"The top row of LEDs shows the program counter as a binary number. Dark LEDs are zeroes, lit LEDs are ones. Here the number is 00010 in binary, or step 2 in base 10. This counts up as we step through the program. Unlike a real CPU, we’re not going to use a clock to automatically step through instructions, we’re going to do this manually by pressing button B."
"The middle row shows the contents of the memory at the address shown on the top row, again as a binary number. So here we see that memory location 00010 contains 10000. The bottom row is the output. This is blank until we write something to it, which as it happens this program just has, because 10000 is an instruction code to write the contents of a register (like a variable) to the display output."
The result is a very basic computer offering a fraction of the capabilities of the underlying microcontroller which drives the BBC micro:bit itself. With just five bits per word of memory, there's only room for four instructions: Load, Add, Output, and Halt. "It's only got 4 because remember I’ve decided only to use a 5-bit word," Booth explains, "and if I’m going to be able to include any meaningful address data I think I need at least 3 bits to store the address. That only leaves 2 bits for actual instructions."
Designed to get users thinking about how computers work at their lowest level, Booth already has some plans for upgrading the CPU: "One idea I have is to split the instruction and address data," he explains, "allowing many more instructions — 32 in fact — and the ability to create much more useful programs that have more maths functions and which can include ‘if’ statements by jumping to different memory locations depending on the results of calculations."
Booth's full write-up is available on his website, along with links to download the firmware and source code.