Tell me more ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I was reading about JVM and Android, and the technical differences between them, and one important it that one VM was stack based, and the other register based.

I studied assembler in College, & I know that many non virtual platforms, use both. Do you know any Virtual Machine that uses both techniques, and runs on Windows or Linux?

Update (1): The reason, im doing this, is because Im working on a "pet project" programming language, and I want to see the effect (destination code) on a virtual machine.

share|improve this question
1  
While many platforms might be able to use one, one of them is usually the predominant one. x86 assembler does support stack operations, but only pushing/poping state and everything else works on registers. Is that what you mean? – Joachim Sauer May 21 '12 at 7:29
@Joachi Saur: Yes, altougth, I also read that some stack machines allow some kind of array mixture like "peek" not the top item, but, "peek" or "read" stack[5] item, sort of – umlcat May 22 '12 at 14:47
@JoachimSauer: I thought that x86 had things like *p1 + *p2 as instructions. – DeadMG May 22 '12 at 15:28

2 Answers

Lua has such a structure, from my recall, and LLVM does also, where it's registers are SSA.

share|improve this answer
Right, I forgot LUA has a virtual machine. I read it once. Without dimish the LUA progr. lang. by itself, I wonder what if another progr. lang. support that same V.M. ;-) – umlcat May 22 '12 at 15:37

.NET CLR is not specifically "stack-based", due to a number of restrictions and a very limited choice of stack operations. And of course it features local variables (which are virtually the same thing as registers). Most of the .NET JIT implementations would reconstruct expression trees or register assignments from the "stack"-based code. Then the result is going to be translated into an SSA, with no stack operations at all. Since it is not supposed to be interpeted, its "stack"-based nature is totally irrelevant.

JVM is a bit more like a full-blown stack VM, but still most of the JIT compilers would do their best in getting an SSA form (i.e., purely register-based) out of it. A verifyability requirement (and a typed stack) ensures that it is always possible to do so. But when interpreted, JVM could act as a stack machine, with all the advantages and drawbacks. Dalvik developers were interested in the interpretation in the first place, but now, with JITs, their choice of the VM architecture does not make much sense.

If you're interested in the pure stack-based machines, take a look at Forth. Anything else would be a mixture of a sort.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.