A C++ console program that decodes and executes 32-bit MIPS machine code instructions given as 8-digit hex values.
You enter an 8 digit hex instruction, and the program:
- Converts it to a 32 bit binary string
- Decodes the opcode, registers, and fields
- Executes the instruction against a small set of simulated registers and memory
- Prints the updated register and memory contents
Type exit to quit.
R-type:
add,sub,and,or,xor
I-type:
addi,lw,sw,beq,bne
- 16 registers (
$0to$15), though only$0to$8are writable by instructions - 16 memory locations (
mem[0]tomem[15]) $0is hardwired to 0, same as real MIPS
g++ -o mips_sim hex_instructions.cpp
./mips_sim
On Windows with MinGW:
g++ -o mips_sim.exe hex_instructions.cpp
mips_sim.exe
Entering an add $1, $2, $3 instruction as its 8-digit hex encoding will print the decoded instruction, the register values used, the result, and which registers changed.