EmbedVM – Embedded Virtual Machine

EmbedVM is a specialized virtual machine designed for use in embedded systems. Embedded systems are typically constrained by resources such as memory, processing power, and energy, which necessitates the use of highly efficient and compact software. The role of an embedded virtual machine like EmbedVM is to run bytecode, which is a portable, intermediate code that a virtual machine executes, rather than running native machine code directly on the hardware.

Key Features of EmbedVM:

  • Compactness: EmbedVM is designed to be small and lightweight to fit on the limited memory of microcontrollers commonly used in embedded systems.
  • Portability: By running bytecode, it abstracts the program from the hardware, allowing for the same code to run on different devices without modification, as long as the EmbedVM is implemented on those systems.
  • Flexibility: Programmers can update the bytecode running on embedded devices without having to change the underlying firmware, which can be advantageous in scenarios where updating firmware is difficult or risky.
  • Resource Efficiency: EmbedVM is tailored to make efficient use of the resources in an embedded environment, ensuring that applications do not consume more processing power or memory than necessary.

Pros and Cons of Using EmbedVM in Embedded Systems:

Pros:

  • Ease of Software Updates: Since EmbedVM runs bytecode, developers can deploy updates and new features to embedded systems without re-flashing the entire firmware.
  • Code Reusability: Programs developed for one system running EmbedVM can be reused in another system with a different architecture without significant changes.
  • Development Efficiency: It enables software development to proceed in a high-level language rather than device-specific assembly, often accelerating the development process.

Cons:

  • Performance Overhead: Running bytecode through a virtual machine introduces some overhead compared to running native compiled code directly on the hardware.
  • Additional Complexity: The inclusion of a virtual machine in an embedded system introduces an additional layer of complexity that might not be necessary for simple applications.
  • Resource Use: Though EmbedVM is designed for efficiency, it might still require more resources (both in terms of memory and CPU usage) than the most minimal firmware written specifically for a given set of hardware.

In conclusion, EmbedVM represents an interesting solution for embedded systems where the benefits of portability and ease of updates can outweigh the performance and complexity drawbacks inherent to using a virtual machine. It exemplifies a trade-off that engineers and developers in the field of embedded systems often have to consider: the flexibility of software versus the requirements of highly constrained hardware environments.

EmbedVM is a small embeddable virtual machine for microcontrollers with a C-like language frontend. It has been tested with GCC and AVR microcontrollers. But as the Virtual machine is rather simple it should be easy to port it to other architectures.

The VM simulates a 16bit CPU that can access up to 64kB of memory. It can only operate on 16bit values and arrays of 16bit and 8bit values. There is no support for complex data structures (struct, objects, etc.). A function can have a maximum of 32 local variables and 32 arguments.

Besides the memory for the VM, a small structure holding the VM state and the reasonable amount of memory the EmbedVM functions need on the stack there are no additional memory requirements for the VM. Especially the VM does not depend on any dymaic memory management.

EmbedVM is optimized for size and simplicity, not execution speed. The VM itself takes up about 3kB of program memory on an AVR microcontroller. On an AVR ATmega168 running at 16MHz the VM can execute about 75 VM instructions per millisecond.

All memory accesses done by the VM are parformed using user callback functions. So it is possible to have some or all of the VM memory on external memory devices, flash memory, etc. or „memory-map“ hardware functions to the VM.

The compiler is a UNIX/Linux commandline tool that reads in a *.evm file and generates bytecode in vaious formats (binary file, intel hex, C array initializers and a special debug output format). It also generates a symbol file that can be used to access data in the VM memory from the host application.

EmbedVM is free software licensed under the ISC license (a GPL compatible licence that is similar in terms to the MIT license or the 2-clause BSD license).

Link to the sources and all currently available documentation (subversion repository):

A Quick Introduction to EmbedVM (YouTube):

In papers and reports, please refer to EmbedVM as follows: Clifford Wolf. EmbedVM: A small embeddable virtual machine for microcontrollers. https://www.clifford.at/embedvm/, e.g. using the following BibTeX code:

@MISC{EmbedVM,
        author = {Clifford Wolf},
        title = {EmbedVM: a small embeddable virtual machine for microcontrollers},
        howpublished = "\url{http://www.clifford.at/embedvm/}"
}