Assembler to emulate and execute programs written in MIPS assembly language. The assembler will emulate a 1KB RAM Space and 32 bit registers without actually using up system registers directly. This allows it to run on any processor maching with a C++14 compiler.
These instructions will get you a copy of the project up and running on your local machine for development and testing purposes.
C++14 compiler preferrably GCC.
- Clone this repo to local machine
$ git clone https://github.com/godcrampy/mips-assembler.git
-
cd into the cloned repo
$ cd mips-assembler
-
Build the program using make: (Assumes G++ installed, edit the Makefile for other options)
$ make
OR
- Build using compiler
$g++ src/main.cpp src/file-io/file-io.cpp src/parser/parser.cpp src/register-module/register-module.cpp src/ram-module/ram-module.cpp src/cpu-module/cpu.cpp -o build/mips
The assembler program will be built in the build directory. To run MIPS code, you need 3 files:
- .mips: This is the file in which you'll write the mips program
- .ram: This is the file in which you'll give ram configuration
- .reg: This is the file in which you'll give register configuration
Example MIPS Code
test.mips
lw $t0, 0($s1)
addi $t1, $zero, 6
while: log loop 0 $t0
addi $t0, $t0, 1
bne $t0, $t1, while
register.reg
$s1: 120
memory.ram
120: 1
Execution: $ ./mips ./test.mips ./register.reg ./memory.ram
Output:
loop 1
loop 2
loop 3
loop 4
loop 5
Currently the following instructions are supported:
- add
- addi
- sub
- and
- andi
- or
- ori
- srl
- sll
- lw
- sw
- log
Note: log is not a mips instruction. It has been provided to print register data to the teminal. It's syntax is: log message add register. This will print message followed by the data in the register with add value added to it.