Program to decode and execute MIPS instructions on a set of registers. CCS 1B class project, authored by Rohil Shah.
- Clone the repository
- Place your hex program in
program.txt
- Run the emulator using
$ ./emulate
- View results!
Note: archive.txt
contains other programs used for testing.
Below is a video of me emulating a program that outputs even integers from 0 to 20. I chose this example because it makes use of j
and bne
, a simple test of my program counter implementation.
even_numbers.mov
Below is another video of me emulating a program that recursively outputs the sum of the integers from 1 to n, where n is read from user input. I chose this example because it makes use of syscall
, jal
, jr
, lw
, sw
, a more involved test of my stack/memory implementation (especially $ra
).
one_to_n.mov
There's plenty to say, but here are three of the most interesting/critical pieces:
- I chose to make memory byte-addressable (as in MIPS), and arbitrarily allocated 8 KB. I initialized my stack pointer to the top, and since I don't define dynamic/static/reserved memory domains, the stack is free to expand to the entire 8 KB (slightly less than this because of the instructions themselves).
- The 4-byte instructions are streamed into memory from the input file starting from index 0x0, using
tp
, to keep track of the next available byte in memory.
- The fetch/execute cycle a) reads
pc
,pc + 1
,pc + 2
,pc + 3
into a single instruction, then b) does high-level dispatching of the instruction to the appropriate handlers.