Skip to main content

MIPS Simulator


About The Project

This program takes in a machine code object file (that is generated by my accompanying assembler program) from standard input and simulates the program's execution. This simulator is interesting because it basically tracks the status of all your registers and data segment at each increment of the program counter. It operates very similarly to how most assembly simulation GUI programs show all register states and let you step through the execution. However, this program just prints the execution to a log file and not a GUI.

Supported Directives:

  • .text (switch to the text segment)
  • .data (switch to the data segment)
  • .word w1, ... , wn (store n 32-bit integer values in successive memory words)
  • .space n (allocate n words)

Supported Instructions:

  • addiu
  • addu
  • and
  • beq
  • bne
  • div
  • j
  • lw
  • mfhi
  • mflo
  • mult
  • or
  • slt
  • subu
  • sw
  • syscall

System Call CodeArgumentExplanation
1$a0 = integerPrint an integer value followed by a newline character to standard output
5Read an integer value from standard input and assign the value to $v0
10Exit the simulation

TypeExplanation
Illegal InstructionIllegal combination of opcode and funct field values
Illegal Instruction AddressPC is referencing an addresss outside of the text segment
Illegal Data AddressLoad or store referencing an address outside of the data segment
Divide By ZeroInteger divide by zero

Example Input File:

Example Output:

The sample program reads an integer specifying the number of integers to sum. Then it reads those integers from stdin. Then prints the output. For example, 3 integers, 5 + 10 + 15 = 30

Generated Log.txt File

A log.txt file is also generated each time a program is simulated. This includes disassembled instructions, register values and current values of the words in the data segment for every instruction executed.