Very simple interpreter made in rust. Inspired by assembly (specially mips32), though not being a simulator.
The program will read a file and run the instructions imperatively. If during the execution of an instruction there is an error, the program will stop its execution.
Does not support inline comments.
I am not glad at all with the implementation, due that in order to find the labels I need to watch all the document, feels like cheating :(
Labels are set with @[A-Z]
. You can use any name that contains only caps letters.
The interpreter will search for the label @MAIN
, and will start the execution there
The simulator stores 32 registers, which can be accessed with $[reg]
.
- Register 0 maintains the value zero and cannot be changed.
LI $[reg] [Imm]
-> $reg = ImmMOVE $[reg0] $[reg1]
-> $reg0 = $reg1ADD $[reg0] $[reg1] $[reg2]
-> $reg0 = $reg1 + $reg2SUB $[reg0] $[reg1] $[reg2]
-> $reg0 = $reg1 - $reg2MUL $[reg0] $[reg1] $[reg2]
-> $reg0 = $reg1 * $reg2DIV $[reg0] $[reg1] $[reg2]
-> $reg0 = $reg1 / $reg2REM $[reg0] $[reg1] $[reg2]
-> $reg0 = $reg1 % $reg2PRINT $[reg]
-> print $regJUMP @[label]
-> set instruction counter to label's one.BEQ|BNE|BLT|BLE|BGT|BGE $[reg] $[reg] @[label]
-> set instruction counter to label's one if condition is true.EXIT
-> terminates the execution.SKIP
-> skip the line. Equivalente to // or an empty line.PUSH $[reg]
-> push in the stack the value in the $[reg].POP $[reg]
-> put in the $[reg] the value in stack's pop.
- Basic usage (basic arithmetic, basic data transfer).
- Basic system calls (print, exit)
- Unconditional jumps.
- Conditional jumps.
- Stack operations.