Skip to content

A basic 16bits VM, with a simple assembler based on GAS but simplified.

License

Notifications You must be signed in to change notification settings

roackim/BasalVM

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

77 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Basal Virtual Machine

A basic 16bits VM, written in C++ capable of interpreting basal bytecode, using 32bits instructions. The VM automatically allocate 2^16 words of 16bits. this represent ~130ko of memory. It is quite performant, being able to execute ~20k instructions in 0.5 ms.

Dependencies

- gcc
- make

Building

make

The project is compiled with a very large set of warnings enabled, which you can see typing "make flags". It should compile without any warning being prompt, except a few from Static Analysis.

Usage

Currently the assembler and the VM are coupled together, meaning you can only use the vm on textual representation of the bytecode:

./main <basm_file>

ex : 	./bin/main examples/GameOfLife.basm

Basal Assembler

proto-assembler based on GNU assembly, but simplified. can assemble 20k basal assembly lines to instruction code under 0.1s.

It has severals features such as dereferencing registers, using immediate values or direct addresses. Check Doc.md for more details. You can also check the code sample in bin/example, you'll find an implementation of Conway's Game Of Life as well as other programs.

#Examples:

You can find example programs in the examples folder, these have been hand programmed, but ultimately this assembler should be used as a backend for a compiler.

Game of Life, randomly instanciated:

make gof

Game of life running on basal VM

Display the first elements of the Fibonacci sequence (bin/examples/fibonacci.basm):

#--------------------
# Fibonacci Sequence
#--------------------

:BEGIN
	copy    0,  ax
	copy    1,  bx
	copy    15, cx  

	disp    '{', char
	disp     bx, mem

:LOOP   # loop to calculate fibonacci sequence
	sub     1,  cx
	cmp     0,  cx
	jump END if EQU 

	copy    bx, dx
	add     ax, bx
	copy    dx, ax

	call Inter
	disp    bx, mem

	jump LOOP
	
:Inter  # separate numbers in display
	disp    '\,',   char
	disp    '\s',   char
	ret

:END    # end program
	disp    '}',    char
	disp    '\n',   char
	exit

About

A basic 16bits VM, with a simple assembler based on GAS but simplified.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published