java - Stack-based machine depends on a register-based machine? -


normal cpus (for example, android devices) register-based machines. java virtual machine stack based machine. stack-based machine depend on register-based machine work? can't stack-based machines run lonely, because not os? there stack-based machine examples except jvm? saying 1 operand, 2 operand; why need this?

the jvm not mention existence of registers anywhere. perspective, memory exists in few places, such per-thread stack, method area, runtime constant pools, etc. said, if wanted implement physical device adhered jvm, you'd need registers hold of temporary values generated when executing bytecodes, or maintain scratch information on side. example, try looking multianewarray instruction , see if implement without registers. :-)

one parallel can find in real cpus these days while there dedicated set of registers available programmers, cpus have substantially more registers used internally various purposes. example, mips chips have huge number of registers used pipelining. hold things control bits previous instructions. blown away if x86 different.

the thing remember it's not registers define how register-based machine versus stack-based machine work. in architectures, have o(1) registers dedicated internal use. jvm has these - each method has "local variables array" hold function's parameters, can used scratch space if need be. more important part stack machines differentiates them other machines how extensible memory works. in computers, memory random-access , can read location want @ time. is, n memory locations, have o(n) memory readable @ time. in stack-based machines, have access top few spots of stack, have o(1) memory locations readable @ 1 time.

in theory, because jvm supposed represent full virtual machine, have computer booted , ran jvm without os (or rather, jvm os, , "programs" java bytecodes , class files).

there few other stack-based languages, of first jumps mind forth. mention forth because it's explicitly stack-based language; phrased in terms of manipulating operand stack. what's cool regards original question forth used extremely popular among hobbyists because port embedded devices. full forth interpreter working don't need powerful os - need command interpreter. forth isn't popular these days, it's still cool language.

another stack-based language that's in wide use postscript, has lost lot of ground pdf still used extensively in environments need render scalable graphics on variety of platforms. technically turing-complete programming language, though few people use way.


Comments

Popular posts from this blog

linux - Mailx and Gmail nss config dir -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -