DEV Community

Alberto
Alberto

Posted on

I Built a Simple MIPS CPU Simulator in Python đź§ 

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, and HALT

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


Demo

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
  • A simple instruction parsers

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


Source Code

đź”— GitHub Repository:

👉 https://github.com/thecoder507/cpu_simulator_python

(Full explanation and documentation are available in the README.)

Top comments (0)