The script and a detailed instruction on how to run it can be found on the Github repo here !
As I used Pattern Matching in the code, please note that Python 3.10.0 (or later) is required to run the script.
This is a Python script simulating how MIPS instruction is fetched, parsed, and executed. There is a simulation of the main memory, cache memory, and the General Purpose Register. A more detailed look at the design of the script can be found in
README.md in the repo.
This was by far the toughest project in the Computer Science track, and I actually completed CS105 first before circling back to this project! A big part of the difficulty for me was understanding the Computer Architecture in the first place, especially the MIPS assembly language. I had to research the topic online, but many materials were meant for graduate students and were impenetrable to me. If anyone else finds themselves in the same boat as me, I would like to share some YouTube lectures that really, truly, greatly helped me in actually starting to understand ISA and MIPS, and without which I would never have been able to even attempt this project:
- David Black-Schaffer’s Introduction to Computer Architecture (it’s a series)
- Tahia Tabassum’s Introduction to MIPS Computer Architecture (also a series)
script.py through the terminal takes one compulsory argument, which is a
.txt file containing the MIPS instruction. Codecademy’s sample MIPS instruction is included in the repo as
instruction_input.txt while I’ve also included a longer MIPS instruction
Two test files called
test2.py can also be run to simulate more instructions–no external
.txt file is required to run these as the registers and the main memory are already preprogrammed with some data.
test2.py in particular gives a good overview of how the cache simulation works.
The complete list of MIPS instructions that this program can take can be found in the
README.md file in the repo.
Ultimately this is just a really simple program and only a very crude simulation (for example, the script’s simulation of the Control actually judges if the data/instruction the PC is pointing at in the memory address is a valid instruction, but I understand that the CPU actually doesn’t do this and checking for valid instruction is something left to the programming language or OS to do) based on a still-very rudimentary understanding of this incredibly difficult topic I have not even scratched the top off! If you’ve given it a run, do let me know
PS. sorry about the repost–-this tag wasn’t available yet when I first posted this. I’ve requested to delete the previous post.