Implementing the Mano machine in Python

When I was studying the “computer architecture” course, we used the Mano machine model describe a theoretical computer, which is simple enough to understand but powerful enough to be Turing complete and run real programs (although the programs are written in a very minimalist assembly language, containing only 25 instructions)

I wanted to implement this model for two main reasons:

  1. To better understand the course material
  2. Practice TDD with Python

I will describe the main components of my implementation


A simple class representing a register (constructed with the word size). The Mano machine contains a few registers, and having a unified class for them was helpful for the common register operations: shift left/right, increment, etc. The registers are used inside the Computer class, for example for address pointer (ar), program counter (pc), accumulator (ac), carry flag (e) and more.


This class represents the computer RAM. It is very simple (basically it’s an array), allowing only to read/write a word in an address


This is not strictly needed for the computer to run, but it allows to write programs in an assembly language and load them into memory. You can see some examples of simple programs in the tests


This is where it all comes together. While the computer runs (until the HLT instruction is seen), it will take an instruction from memory and execute it. Most of the work in this class is related to how to execute each of the supported instructions (that’s why it’s so long). Instructions can manipulate the memory or the registers, jump to different parts of the program (looping) and do I/O

This is basically it, you can check out the code here:

I would also like to implement a more accurate simulation of registers / logic gates flow with something like FRP. Hope I’ll find the time :)

One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.