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>- pushsrcto programm stackpop <dst>- pop the top of programm stack and write it todstcall <function>- push instruction pointer of next line to programm stack and callfunctionexec <function>- just callfunctionwithout pushing anything to stackcopy <src> <dst>- copy fromsrctodstload <src> <dst>- copy fromsrctodst, however heresrchas larger address thatdstadd <src> <dst>- addsrctodstand write result todstsub <src> <dst>- substractsrcfromdstand write result todstisequal <var1> <var2>- push the result ofvar1 == var2to programm stackif <flag>- ifflagis 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 variablevaron new lineprintconst <const>- print string constantconston new linescan <var>- read integer variablevarfrom 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_namestatic { ... }- 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