Stack VM vs Register VM
That "register-based" means the VM uses hardware registers. It does not — the registers are slots in a frame, indexed by the instruction. The difference is in the operand encoding, not in where the values live.
Stack-based virtual machine
When you want the smallest, simplest compiler and instruction encoding — expressions lower to postfix with no allocation decisions at all.
Register-based virtual machine
When interpretation speed matters and you can afford a register allocator in the bytecode compiler.
| Aspect | Stack-based virtual machine | Register-based virtual machine |
|---|---|---|
| Operands | Implicit — taken from and returned to the operand stack. | Explicit slot indices encoded in the instruction. |
| Instruction count for a + b * c | More: every value is pushed and popped. | Fewer: operands are named, so no shuffling instructions. |
| Instruction size | Small, often one byte. | Larger — the operand indices have to fit. |
| Compiler complexity | A post-order walk of the AST is a working code generator. | Needs slot allocation, which is register allocation under another name. |
| Dispatch overhead | Higher — more instructions dispatched per unit of work. | Lower, which is the entire argument for it. |
| Real examples | JVM bytecode, CPython, WebAssembly’s value stack. | Lua 5, Dalvik, several research interpreters. |