Basic virtual machine based on Von Neumann architecture. Implemented specific assembler that compiles code into binary file that could be executed by virtual machine.
vnvm assembler <code.asm> [out.bin]
- build binary file from assembler code
vnvm exec <filename.bin>
- execute binary file
Commands take variables, constants or functions' names as arguments. In commands with two arguments (except load
) first argument has only one byte to code address of variable and second argument has two bytes to code address. So first variable should be defined as global, otherwise an error is likely to appear.
push <src>
- pushsrc
to programm stackpop <dst>
- pop the top of programm stack and write it todst
call <function>
- push instruction pointer of next line to programm stack and callfunction
exec <function>
- just callfunction
without pushing anything to stackcopy <src> <dst>
- copy fromsrc
todst
load <src> <dst>
- copy fromsrc
todst
, however heresrc
has larger address thatdst
add <src> <dst>
- addsrc
todst
and write result todst
sub <src> <dst>
- substractsrc
fromdst
and write result todst
isequal <var1> <var2>
- push the result ofvar1 == var2
to programm stackif <flag>
- ifflag
is true (equals1
), then execute next line, else skip next linereturn
- pop the top of programm stack and return to the address written in popped topexit
- exit programm, the return code is written to instruction pointerprint <var>
- print integer variablevar
on new lineprintconst <const>
- print string constantconst
on new linescan <var>
- read integer variablevar
from input
var {
var 0
another_var 17
...
}
const {
string Here's a string
hello_world Hello, World!
...
}
def {
function {
static {
static_var 10
...
}
<commands>
...
push &static_var
add var &static_var
...
return
}
...
main {
static {
static_var 15
...
}
<commands>
...
exit
}
}
var { ... }
- definition of global integer variables, template for each line is<name> <value>
const { ... }
- definition of global string constants, template for each line is<name> <string>
def { ... }
- definition of functions, includingmain
, which is an entry point of programm<function_name> { ... }
- definition of functionfunction_name
static { ... }
- definition of static integer variables, template for each line is<name> <value>
- the rest part of function is its code, static variables should be used in code with
&
before name