A Python-based simulator for a MIPS processor that supports various instruction types:
- R-type (add, sub, sll, slt, xor, or, nor, jr, mult, div, mflo)
- I-type (addi, lw, sw, beq, bne)
- J-type (j, jal)
- Simulates 32 general-purpose MIPS registers
- Supports stack operations
- Implements memory hierarchy
- Supports jr $ra for function returns
- Interactive menu interface
- Append and write mode for compiler and interpreter style execution
Clone the repo to your desired location. Run the simulator from the command line:
git clone https://github.com/moneytosms/MIPS_Processor.git
cd MIPS_Processor
python processor.py- Load instructions (as hex words)
- Execute cycles
- Show all registers
- Help - Learn about MIPS
- Exit
To calculate factorial of 5, enter these instructions:
0x20080005 0x20090001 0x11000004 0x01280018 0x00004812 0x2108FFFF 0x08100002
This simulator implements a basic MIPS architecture with:
- 32 general-purpose registers
- Memory model with text, data, and stack segments
- Support for core instruction types (R, I, and J)
- Function calls via
jalandjr $ra - Stack operations
The simulator uses the standard MIPS memory layout:
0x00400000: Text segment (Code)0x10000000: Data segment (Global variables)0x7fffffff: Stack segment (grows downward)
add- Add two registerssub- Subtract two registerssll- Shift left logicalslt- Set less thanxor- Exclusive ORor- Logical ORnor- Logical NORand- Logical ANDjr- Jump registermult- Multiplydiv- Dividemflo- Move from LO register
addi- Add immediatelw- Load wordsw- Store wordbeq- Branch if equalbne- Branch if not equal
j- Jumpjal- Jump and link (function calls)
The simulator supports nested function calls with stack management. For example:
# Save return address
addi $sp, $sp, -4
sw $ra, 0($sp)
# Function body...
# Restore return address and return
lw $ra, 0($sp)
addi $sp, $sp, 4
jr $ra
The simulator has been thoroughly tested with:
- Register operations
- Memory operations
- Basic arithmetic and logical operations
- Branch instructions
- Function calls
- Complex programs (e.g., factorial calculation)
For more information about MIPS architecture and assembly:
- MIPS Reference Sheet: https://inst.eecs.berkeley.edu/~cs61c/resources/MIPS_Green_Sheet.pdf
- MIPS Assembly Programming Tutorial: https://chortle.ccsu.edu/AssemblyTutorial/index.html
- Book: 'See MIPS Run' by Dominic Sweetman
- Book: 'Computer Organization and Design' by Patterson and Hennessy
Also contains Pipeline visualization tool in a menu driven format, to run the program, enter the repository directory, run from CLI.
git clone https://github.com/moneytosms/MIPS_Processor.git
cd MIPS_Processor
python pipeline.py