Does a stack-based machine depend on a register-based machine?

Conventional CPUs (such as Android devices) are case-based machines. The Java Virtual Machine is a stack-based machine. But does a stack-based machine depend on registry-based work? Can stack-based machines run lonely because it's not an OS? Are there stack based examples other than the JVM? Some say 1 operand, 2 operand; why do you need it?

+3
source share
2 answers

The JVM does not mention the existence of registers anywhere. From his point of view, memory exists only in a few places, for example, in the stack stream, method area, pools of the constant runtime environment, etc. However, if you want to actually implement a physical device that is tied to the JVM, d will almost certainly need registers to store some temporary values ​​generated when certain bytecodes are executed, or to store additional error information on the side. For example, try to find the multianewarray instruction and see if it can be implemented without registers. multianewarray

At present, one parallel can be found in real processors, since while for programmers there is a special set of registers, most processors have significantly more registers that are used internally for various purposes. For example, most MIPS chips have a huge number of registers used for pipelining. They contain things like the control bits of previous instructions. I would be blown away if x86 were different.

It should be remembered that it does not register, which really determines how the machine is based on registers compared to the machine based on the stack. In most architectures, you have O (1) registers intended for internal use. Even the JVM has it all - each method has a "local array of variables" that initially contains the parameters of the function, but can also be used as a scratch space if necessary. The more important part of stacked machines that sets them apart from other machines is how expandable memory works. On most computers, memory has random access, and you can read from any location you want at any time. That is, with n memory locations, you can read O (n) at any time. On stack-based machines, you only have access to the top few points of the stack, so you can only have O (1) memory cells that can be read at any given time.

In theory, since the JVM should represent a complete virtual machine, you might have a computer that booted up and just started the JVM without any OS (more precisely, the JVM will be the OS, and your “programs” will be just Java bytecodes and class files )

There are several other stack-based languages, of which the first that comes to mind is Forth . I mention Forth because it is clearly a stack-based language; everything you do is formulated in terms of managing the operand stack. What's cool about this regarding your initial question is that Forth was extremely popular among fans because you really could easily transfer it to the embedded devices. To get the full Forth interpreter, you don't need a really powerful OS - you just need a shell. Forth is not so popular these days, but it's still very cool.

Another stack-based language that is widely used by PostScript , which has lost many of its foundations for PDF, but is still widely used in environments where you need to render scalable graphics across platforms. This is the Turing technical programming language, although few people use it that way.

+7
source

I know that you have already chosen your answer, but I would like to consider the whole thing strong>.

While most physical processors are essentially registration machines, stacked machines were the physical processors. Burroughs' B5000- and B6000 machines , for example, or RTX2000 chips used in space flight (originally implemented by Chuck Moore in gate logic and later commercialized). UCSD Pascal p-Machine was implemented directly in hardware by various developers.

In terms of computational power, registration machines and stacks are roughly equivalent. (It depends, of course, on the exact models of the registration systems or stack you are dealing with.) Stack machines have the advantage of simplicity, small size, and extensibility. Registration machines are usually faster. Registration machines can emulate stacked machines (that is, all BP and SP registers in x86 architecture, after all!), And stacked machines themselves can simulate registered machines, if necessary.


edited to add

I almost forgot to point you to a book that details stack computers. Koopman is a bit of a fanboy for the stack computers, and his prediction that they were the “new wave” was terribly wrong, but it's interesting to read.

+6
source

All Articles