Most of us are familiar with virtual machines (VMs) as a way to test out various operating systems, reliably deploy servers and other software, or protect against potentially malicious software. But virtual machines aren’t limited to running full server or desktop operating systems. This tiny VM is capable of deploying software on less powerful systems like the Raspberry Pi or AVR microcontrollers, and it is exceptionally fast as well.
The virtual machine is built from scratch, including the RISC processor with only 61 opcodes, a 64 bit core, and runs code written in his own programming language called “Brackets” or in assembly. It’s designed to be modular, so only those things needed for a given application are loaded into the VM. With these design criteria it turns out to be up to seven times as fast as comparably small VMs like NanoVM. The project’s creator, [koder77], has even used its direct mouse readout and joystick functionality to control a Raspberry Pi 3D camera robot.
For anyone looking to add an efficient VM to a small computing environment, [koder77] has made the project open-source on his GitHub page. This also includes all of the modules he has created so far which greatly expand the project’s capabilities. For some further reading on exceedingly tiny virtual machines, we featured this project way back in 2012 which allows users to run Java on similar hardware.
I wonder how much faster this is than other academic VMs like Spim or Mars.
It seems to be lightweight, needs 10MB for a text mode application – a bit more like CHIP-8 used to need.. Not sure how the other VMs compare to this, however.
Did you mean 10KB? Because 10 MB is not lightweight. Even 10KB is pushing “not lightweight” territory for a truly lightweight VM, given how small you can make lisp and forth VMs.
> In pure console text I/O programs not linked with SDL library, the memory footprint is very low. About 10 MB RAM only as shown in the taskmanager by running a minimal test program!
That’s from the Github page. I agree that 10 MB isn’t exactly lightweight. It’s not heavy in terms of modern desktop or mobile operating systems (for example, Raspbian on the Pi), but in terms of the low resource AVR microcontrollers the article suggests are a good target, 10 MB is a huge amount of memory. (In fact, most AVR chips I’m aware of don’t even have half that.)
Otherwise, fascinating idea. Writing a VM is a great way of testing a theoretical processor architecture. I’ve written a VM for an audio processor I designed, and not only was it useful for testing, it was also a fun experience! (No, it’s not currently available anywhere. There are still a few missing features, and I haven’t had time to work on it in…5 years or so, I think. Maybe someday.)
You can get it down to 5.5 MB RAM, if you don’t link the VM to the JIT-compiler library.
I did a test with my LOW_RAM setting switched to on in the settings.h include file. Now the VM needed only 1.2 MB RAM for a simple hello world program! But then all allocated lists and are cut down to a minimum. And complex programs won’t work with this!
And CHIP 8 ran on machines with 2kB or 4kB
Wasn’t the original interpreter 512 bytes of 1802?
Yep, I got a chance to play with an original home-built 1802 kit back in the ’70s; it had 4K total RAM and the interpreter was in the first 512 bytes.
From when “real” coders didn’t even use brackets and coded directly in hex.
Um, why exactly do you use a new ISA and not simply Risc-V?
If its a learning experience then yeah, more power to you. If you want to use it broadly in real life applications something that is small and already existing would have had made much more sense.
IMHO writing an emulator for real hardware would need a lot more work! You had to implement every instruction in your VM. I decided to develop my own simple but powerful instruction set. As I commented above: you can get the RAM usage down to 5.5 MB, if there is no JIT-compiler library linked.
not what I would call light weight, it’s out by a few orders of magnitude.. less than 32K ram is light weight now days (up from less than that a few years ago..). The one I wrote and use often runs quite complex things in 20K., which after all is quite a lot of 1 and zeros….