DEV Community

Cover image for Codecademy Final Project: CPU Simulator
lila.code
lila.code

Posted on

Codecademy Final Project: CPU Simulator

The portfolio project for Codecademy's computer architecture course in computer science is to make a CPU simulator that shows the inner workings of a CPU and its connection to memory by processing instructions and providing console output of input processing. I chose to make an assembler to parse instruction and data input for a memory bus to store and the CPU to process using MIPS32 instruction set architecture.

Python Code

I wrote the program in VS Code using three files to split up the different parts of the simulator. The main CPU simulator file contains the assembler and CPU classes. The assembler class parses assembly language text files and outputs machine code for the CPU to process and the CPU class is the main class to operate the simulator and call the functionality of its components.

The CPU components file contains classes for the three main components of the CPU, the control unit, registers, and arithmetic logic unit (ALU). The memory file contains the parent memory class, the cache and main memory classes that inherit from the memory class, and the memory bus class that connects the CPU to memory.

The data values and instructions for the CPU are modified Codecademy files and I added an instruction file to load the data values to CPU registers from memory instead of manually moving them to the registers. This is the data instruction input file and instruction input file contains the main instructions, which include a cache operation, immediate and register addition, a jump instruction, and a halt termination instruction.

The main program file only calls instances of the assembler and CPU classes and the CPU class calls the control unit which contains the rest of the CPU component instances, including the memory bus. The memory bus then calls the cache and main memory instances, connecting the CPU to memory.

See code on GitHub

Top comments (0)