Tiny interpreter for assembly-like language.
By default memory (stack in particular) value type is int64_t
, to change it iterpreter should be recompiled (see MemoryValueType
alias). Requirements to this type is to:
- be DefaultConstructible
- be CopyConstructible
- be Constructible from string (you can write wrapper for non-trivial types and throw
ArgumentConstructionException
in case of parsing failure) - Support arithmetic operations.
Use -h
/--help
for usage.
Commands are case insensitive, labels are declared like_so:
. Each command should be on next line, arguments are separated with spaces. Comments should be on separate line and start with //
(note space after slashes here - it is required). See examples/
for details.
Command | Semantics |
---|---|
begin | Tells processor where execution should start |
end | Finishes program |
push value | Pushes value on stack |
pop | Removes value from stack |
pushr reg | Pushes value from register reg on stack |
popr reg | Removes top value from stack and writes it into register reg |
add | Adds to top stack values and pushes result on stack (operands are popped) |
sub | Substracts 2nd top stack value from top one and pushes result on stack (operands are popped) |
mul | Multiplicates 2 top stack values and pushes result on stack (operands are popped) |
div | Divides 1st top stack value from 2nd top one and pushes result on stack (operands are popped) |
out | Prints (into stdout) top stack value and removes it |
outr reg | Prints (into stdout) reg register value |
in | Reads (from stdin) value and pushes it on stack |
jmp label | Unconditional jump in label label |
jeq label | Jumps if two top stack values are equal |
jne label | Jumps if two top stack values are not equal |
ja label | Jumps if 1st top stack value is bigger than 2nd top |
jae label | Jumps if 1st top stack value is not less than 2nd top |
jb label | Jumps if 1st top stack value is less than 2nd top |
jbe label | Jumps if 1st top stack value is not bigger than 2nd top |
call label | Call of a function located on label label |
ret | Returns from function (use "end" in outermost scope) |