DEV Community

ptrick72
ptrick72

Posted on

Simple CPU Simulator

As part of my final project for the computer architecture module of the computer science path in codecademy, I have made a simple CPU simulator in python.

I have created classes the mimic the functionalities of a CPU and memory bus. The CPU has register that is randomly initialized with values between 0 and 100. I have put the instructions in a txt file. I fetch and parse these instructions from the input file.

I have implemented the following MIPS instructions:

  • ADD with operands Rd Rs Rt
  • SUB with operands Rd Rs Rt
  • HLT with no operands

ADD is for adding register values. SUB is for subtracting register values and HLT is to halt the CPU.

Once started, the file is lodaed, the insctructions are executed. The initials register values are displayed, the single execution steps are displayed and the final register values are displayed.

Obviously, there are lot of things that can still be added like more instructions, error handling, cache, input validation, …

You can get the code here:
https://github.com/ptrick72/CPU_Simulator

Top comments (0)