The TEA VM is a very small, stack-based virtual machine ideally suited for use in embedded systems and the BrainStem® Modules. The VM is limited in power and scope on purpose to provide capacity to run small programs, sequences of events, or scripts on systems with very little UI and compute horsepower. Below is a description of the basic VM elements.
The TEA VM is a stack-based architecture. The size of the stack is typically quite small and recursive programs can typically blow the stack in short order. Rather than use many dedicated registers for various tasks, the TEA VM uses the stack for almost all temporary value storage. This helps keep the RAM memory footprint of the TEA VM to a minimum.
The stack is a block of memory that has an upper limit in size. A pointer called the stack pointer (sp) points to the top byte in the stack. If the stack pointer is -1, the stack is empty. Attempts to pop an empty stack result in a halting error. The last data byte pushed onto the stack is the first one that is popped off resulting in a LIFO (last in, first out) storage buffer.
Data can be pushed onto the stack from program memory (typically literals or I/O ports), and from the stack itself. Data can be popped from the stack into I/O ports. There are also functions for incrementing and decrementing the stack pointer,
All access to and from the VM is in the form of I/O ports. This is a fixed index namespace and each VM implementation typically implements a subset of the possible I/O ports. Accessing an I/O port that is not implemented on a give VM implementation results in an error.
The TEA opcodes allow for invalid states in coding such as stack overflow, stack underflow, divide by zero, and illegal IO operations. These errors are typically avoided when using the TEA compiler. If such an error should occur, the VM halts execution and reports the error. Execution cannot be resumed and the program running on the TEA VM at the time of error can be considered "dead".