I Built a Simple MIPS CPU Simulator in Python 🧠

Published: (January 8, 2026 at 06:47 PM EST)
1 min read
Source: Dev.to

Source: Dev.to

Why I Built It

In the Computer Architecture module within the Computer Science course, I learned the fundamental concepts of registers, memory, and instructions that explain how a CPU works. As part of the CS104 project, I decided to put that theory into practice by building a small MIPS‑style CPU simulator in Python, which allowed me to observe step‑by‑step how instructions are executed and directly connect what I learned in class with hands‑on experimentation.

What the Program Does

The simulator models a very small CPU with:

  • Registers
  • Main memory
  • A program counter (PC)
  • A fetch–decode–execute loop

It supports basic MIPS‑like instructions such as:

  • ADD
  • ADDI
  • LW
  • SW
  • BEQ
  • HALT

Instructions are loaded from a text file and executed one by one, printing register states after each step.

Demo

Demo of the simulator showing registers updating after each instruction

Seeing the registers update after each instruction makes the CPU behavior easy to follow.

How It’s Built (Brief)

The project is written in Python and organized into:

  • A CPU class to handle instruction execution
  • A Memory class to simulate main memory
  • Simple instruction parsers

The code is heavily commented and designed for clarity rather than performance.

Source Code

Full explanation and documentation are available in the README.

Back to Blog

Related posts

Read more »