Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

39 Commits

Repository files navigation

BytecodeVM

A basic Virtual machine operating on bytecode.

It operates on a stack and shares memory for instructions and data (van neumann architecture).

It can compile to a binary file and run from a file, or compile and run directly from the assembly file.

Currently a command line program but I plan to integrate it into ETEngine as a visual node based programming language. Commands:

  • compile [filename.bca] compiles a .bca assembly file to a binary .bce executable
  • run [filename.bce] runs a bytecode executable file
  • cRun [filename.bca] compiles and directly runs an assembly file without saving the executable

Instruction Set

OpcodeDescription
LITERALPush next 4 bytes
LITERAL_ARRAYGet x from next 4 bytes; Push x sets of 4 bytes - temporary
LOAD ; LOAD_ARG ; LOAD_LCLPop a; Push RAM[a]
STORE ; STORE_LCLPop b; Pop a; RAM[b] = a
ADDPop b; Pop a; Push a + b
SUBPop b; Pop a; Push a - b
LESSPop b; Pop a; Push a < b
GREATERPop b; Pop a; Push a > b
NOTPop a; Push !a
EQUALSPop b; Pop a; Push a == b
JMPPop a; goto a;
JMP_IFPop b; Pop a; if a goto b
CALLput current state in a stack frame; store RTN; Pop a; goto a;
RETURNRestore to previous stack frame; append working stack; goto RTN
PRINTPop x; for x Print Pop - temporary, will be a library function based on null terminated strings
PRINT_INTPop a; Print string of a
PRINT_ENDLStart a new line in console

LOAD and STORE have segment modifiers that can be used as base addresses within functions

SegmentDescription
LCLpointer to first local variable
ARGpointer to first argument
Variable TypeDescription
statica fixed address variable, referenced directly
argumenta variable that sits in the working stack of the previous function's frame
locala local variable within the stack frame of the current function

There is no concept of scope so all variables should be unique Variables are declared implicitly upon their first occurance with the exception of arguments Variables declared before the first function are static, after the first function they are local

The assembler also features Symbols (variables and labels)

  • Variables start with # and are statically allocated at compile time
  • Jump labels start with @
  • Subroutines start with $ and are followed by argument declarations

Planned

I plan to add:

  • indexed library function support (executes function at pushed index)
  • Dynamic memory allocation
  • Support for standard types int float char bool (maybe short, long, double etc) unsigned or signed
  • Built in support for variable length arrays, strings and vectors

About

A basic Virtual machine operating on bytecode with a stack and Van Neumann Architecture. Built in Assembler.

Topics

Resources

Stars

19 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages