Register-based model

A register-based virtual machine (VM), such as the DEMON Virtual Machine (DVM), takes a different approach to processing operations compared to stack-based VMs. It models CPU registers, making explicit use of operand locations within its instructions. For instance, when performing an addition operation in a register-based VM, the operation can be written as:

• ADD AX, BX, CX ; This adds the values in registers AX and BX and stores the result in CX.

Unlike stack-based VMs, register-based systems do not require PUSH or POP instructions, which significantly simplifies and accelerates the operations. In contrast to stack-based systems, the addresses of the operands (in this case, AX, BX, and CX) must be explicitly stated.

The register-based model has other advantages as well, one of which is the opportunity for optimization that isn't possible in a stack-based model. If the same operation is conducted twice, a register-based model can optimize it to perform the operation only once, storing the result for reuse. This results in significantly improved execution speed.

The downside to this model is that each instruction must explicitly state the operand address, leading to a larger average instruction size compared to stack-based systems. While the stack-based approach offers brevity due to not needing to explicitly state the stack address, a register-based VM requires the inclusion of operand locations in each operation code (OPCODE), which enlarges individual instructions.

However, as demonstrated by Dalvik when compared to the Java Virtual Machine (JVM), the overall code base can be significantly reduced in size even with larger individual instructions. This makes the register-based VM an efficient choice for a blockchain system, striking a balance between operational speed and code base size.

Last updated