Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How would a register + stack based virtual machine work?

I know how register based and how stack based virtual machines work independently. I know the advantages and disadvantages of both. What I want to know is that has anyone ever tried to merge the two?

I tried to search the net for the existence of such a virtual machine, but to no avail. The best result I got was an article on a hybrid virtual machine (HyVM). If such a virtual machine was indeed created for a programming language, I would be interested in having a look at its source code to understand how it works.

Perhaps someone could point me in the right direction to find such a virtual machine, or link me to an article or blog post that elaborates in this topic.

like image 610
Aadit M Shah Avatar asked Dec 03 '12 09:12

Aadit M Shah


People also ask

How does a stack based VM work?

Working. Stack Based virtual machine creates runtime stack. VM only performs two operations directly on Java Stacks: it pushes and pops data. While reading wordcode if the instruction is encountered it will pop 2 operand from the top of the stack and perform operation on it, push the result back to stack.

What is a register based virtual machine?

Register Based Virtual Machines In the register based implementation of a virtual machine, the data structure where the operands are stored is based on the registers of the CPU. There are no PUSH or POP operations here, but the instructions need to contain the addresses (the registers) of the operands.

Why register based machine is better than stack based machine?

Under non-JIT settings, a stack-based VM will be popping and then pushing the same operands many times, while a register-based VM will simply allocate the right amount of registers and operate on them, which can significantly reduce the amount of operations and CPU time.

Is JVM stack based or register based?

The JVM is a stack-based VM where all the arithmetic and logic operations are carried out via push and pop operands and results are stored on the stack. The stack is also the data structure to store methods. Contrastingly the DVM is a register-based VM.


1 Answers

Take a look at Forth. It uses a VM, is mainly stack oriented but allows to store values almost in the way you suggest.

In addition, the VM is quite small, so it is easy to explore and to port it.

like image 65
Matthias Avatar answered Oct 01 '22 16:10

Matthias