What are differences between stack- and register-based virtual machine's bytecode commands?

For example Python has stack-based virtual machine.

But Lua has register-based vm.

So, what are the differences between bytecode commands?

  • $\begingroup$ I rewrite my question. Maybe now it is more focusing. (Sorry for my english) $\endgroup$ Commented Jun 8, 2023 at 7:03
  • $\begingroup$ Maybe this question should be rephrased to be a pro/con on stack vs registers? $\endgroup$
    – kouta-kun
    Commented Jun 8, 2023 at 15:11
  • $\begingroup$ Stack and registers are machines and ISAs features. Why are you asking about VMs in particular? $\endgroup$
    – Longinus
    Commented Jun 9, 2023 at 1:06
  • 1
    $\begingroup$ The last edit was too much in conflict with the original question and invalidated the existing answer; if the author wants to ask that question it's probably ok, but we shouldn't change it underneath them or add commentary to that extent. $\endgroup$
    – Michael Homer
    Commented Jun 9, 2023 at 3:09

1 Answer 1


Register-based VMs (most often) need a way to specify operand registers for each instruction (i.e. add rax, rbx), while stack-based VMs get away with operating on the top of the stack (i.e. add just takes the pops the two stack items and pushes the sum back). I know that Python's bytecode also includes some convenience instructions to, for example, duplicate the top of stack, or to rotate the top three stack items around (DUP_TOP, ROT_THREE, and there's more like this). (EDIT: I've just checked, and they appear to have been replaced with a more general COPY(i) and SWAP(i) in Python 3.11). A register-based VM would have no real need for these, since they can be easily expressed through register manipulations without any observable performance hit


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .