MIPS Simulator


Technologies: C++, Bash, Command Line


Field: Computer Architecture, Software Engineering


Completed: November 2018

MIPS Simulator was a second-year pair project as part of EE Computer Architecture II module. The project was designed to put our lesson learning into practical use by creating a CPU simulator that would execute binary files based on the MIPS assembly language rules. My personal aim in the project was to solidify my understanding of software and digital design by abstracting the hardware components to create a simple software flow. All MIPS commands were supported in our simulator design. Another deliverable was to provide a testbench for the simulator to run unit tests on each command supported by our or any other simulator. My role in the project was predominantly focussed in two areas:


Designing the Instruction Set Architecture (ISA) [C++]: For the program to simulate the MIPS architecture, we needed to design an Arithmetic Logic Unit (ALU) which would perform the same operations that take place on registers. I started by researching the MIPS ISA and using the resources provided in lecture to understand the process of decoding a binary instruction (the input to our simulator). Using simple bitmasks and shifts, I designed a function to decode the binary input and extracted the relevant function codes that were required to execute the respective instructions. This step was necessary to allocate the instructions to each of the three types: R, I and J. Subsequently, my next task was to create a function to execute the instructions: passing the extracted data as arguments for each instruction to execute. For example, the ADD instruction manipulates three registers: register source, register target and register destination. This process was repeated for every instruction as per given specification for the project (52 instructions).


Designing the testbench [Bash]: One of my key learnings in this project was designing a comprehensive and reliable test bench to validate the reliability of our design. It was the most interesting aspect yet most challenging for me because I had to learn a new scripting language within a short time. Upon independent research and online tutorials, I quickly picked up the syntax of the language and found similarities with C++. The bash script was able to automate the process of piping binary files into our simulator and checking the simulator output against the golden reference to determine pass/fail. This allowed us to focus on writing good quality tests to measure performance of simulators.


Upon reflection, this project was very challenging yet equally rewarding. I learned a scripting language in a short period of time but more importantly applying my learning from lectures in a true engineering fashion. For example, to make the ALU more robust and comprehensive, I decided to return error codes after each instruction with help of if/else loops. This flagged up any issues whilst executing instructions and significantly helped to debug as we knew exactly the type of error. This saved us great amount of time and a learning I took forward in all my future projects. Having good unit tests/testbench helps significantly to keep track and set milestones as the programs are built.


A link to the project source code on GitHub can be accessed here.

← Back to Projects