~A register based bytecode virtual machine implementation by smv.
Lightweight and fast, written under 1400 lines of code.
Currently the docs are in making (or being "transported" from past projects) so for now there's only BYTECODE and INSTRUCTIONSET. Updates are major TODO.
This VM is primarily meant to be embedded into C. Practically nobody should be using it barebones without something like a JIT compiler built on top of it. But there's nothing stopping you from doing that. (evil laughter?)
This is mostly a personal project, something that can be embedded into larger systems.
Know more:
- Instruction set
- Bytecode
- List of examples: examples/
The VM is meant to be embedded into C but it can be used as a standalone, to run assembly as well as smvm bytecode.
To use SMVM as a standalone VM:
- Build the VM:
make dev- Run an assembly file:
make run_asmv FILE=examples/test.asmv
# or directly:
./out/smvm examples/test.asmv- Run tests:
make testTo embed SMVM in your C program:
- Install the library:
make install- Include the headers in your C file:
#include <smvm/smvm.h>- Basic usage example:
#include <smvm/smvm.h>
int main() {
smvm vm;
smvm_init(&vm);
char *code =
"puts \"hello, word! here's my lucky number: \""
"mov ra 42\n"
"puti ra\n"
"halt";
smvm_assemble(&vm, code);
smvm_execute(&vm);
smvm_free(&vm);
return 0;
}- Compile your program with:
cc your_program.c -lsmvm- Build the development version:
make dev- Install the library system-wide:
make install- Build libraries only:
make out/libsmvm.a # Static library
make out/libsmvm.so # Shared libraryFor more build options:
make help