基于堆栈的机器依赖基于寄存器的机器上? [英] Stack-based machine depends on a register-based machine?

查看:174
本文介绍了基于堆栈的机器依赖基于寄存器的机器上?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

普通的CPU(例如,Android设备)是基于寄存器的机器。 Java虚拟机是基于栈的机器。但基于栈的机器依赖基于寄存器的机器上工作吗?不能基于堆栈的机器上运行寂寞的,因为它不是一个操作系统?是否有不同的JVM的任何基于栈的机器的例子吗?有些人说1操作数2操作数;你为什么需要这个?

Normal CPUs (for example, Android devices) are register-based machines. The Java virtual Machine is a stack based machine. But does a stack-based machine depend on a register-based machine to work? Can't stack-based machines run lonely, because it is not a OS? Are there any stack-based machine examples except the JVM? Some are saying 1 operand, 2 operand; why do you need this?

推荐答案

在JVM没有提到寄存器存在的任何地方。从它的角度来看,内存只有少数几个地方,如每个线程栈,方法区,运行常量池,等等。这表示存在,如果你想真正实现了坚持的JVM物理设备,你' ð几乎肯定需要的寄存器来保存一些执行某些字节codeS的时候,还是保持在旁边一些额外的划痕信息生成的临时值。例如,尝试寻找了 multianewarray 指令,看你是否能实现它没有登记。 : - )

The JVM does not mention the existence of registers anywhere. From its perspective, memory exists in only a few places, such as the per-thread stack, the method area, runtime constant pools, etc. That said, if you wanted to actually implement a physical device that adhered to the JVM, you'd almost certainly need registers to hold some of the temporary values generated when executing certain bytecodes, or to maintain some extra scratch information on the side. For example, try looking up the multianewarray instruction and see if you could implement it without registers. :-)

一个并行可以在实际的CPU这些天的是,虽然有专用集可用于编程寄存器,大多数CPU具有基本多个寄存器在内部使用用于各种目的找到。例如,大多数的MIPS芯片有一个巨大的用于流水线寄存器数。他们认为像从previous指令的控制位。我会被风吹走,如果86是有什么不同。

One parallel you can find in real CPUs these days is that while there are dedicated set of registers available to programmers, most CPUs have substantially more registers that are used internally for various purposes. For example, most MIPS chips have a huge number of registers used for pipelining. They hold things like the control bits from previous instructions. I would be blown away if x86 was any different.

要记住的是,它不是寄存器,真正定义了如何基于寄存器的机与基于堆栈的机器工作。在大多数的架构,你有O(1)寄存器,专门供内部使用。即使是JVM有这些 - 每个方法都有一个局部变量阵原本持有该函数的参数,但是也可以被用来作为暂存空间,如果需要的话。有关堆栈机,从其他机器区别他们更重要的是如何扩展内存的工作。在大多数计算机,内存是随机访问,你可以从你想在任何时间任何地点读取。也就是说,有N个存储位置,你有O(n)的内存读取在任何时间。在基于堆栈的机器上,你只能访问堆栈顶部的几个景点,所以你只需要可读在任何一个时间O(1)存储位置。

The thing to remember is that it's not registers that really define how a register-based machine versus a stack-based machine work. In most architectures, you have O(1) registers that are dedicated for internal use. Even the JVM has these - each method has a "local variables array" that originally hold the function's parameters, but can also be used as scratch space if need be. The more important part about stack machines that differentiates them from other machines is how the extensible memory works. In most computers, memory is random-access and you can read from any location you want at any time. That is, with n memory locations, you have O(n) memory readable at any time. In stack-based machines, you only have access to the top few spots of the stack, so you only have O(1) memory locations readable at any one time.

在理论上,因为JVM应该重新present一个完整的虚拟机,你可以有一个启动了,只是跑了JVM没有任何操作系统的计算机(或者说,JVM将是操作系统,和你的节目也只是Java字节codeS和类文件)。

In theory, because the JVM is supposed to represent a full virtual machine, you could have a computer that booted up and just ran a JVM without any OS (or rather, the JVM would be the OS, and your "programs" would just be Java bytecodes and class files).

有一些其他的基于堆栈的语言,它的第一个跳转到心灵第四。我提到第四,因为它明确地基于堆栈的语言;你所做的一切是措辞操纵操作数栈的条款。什么是酷这个与问候你原来的问题是第四曾经是非常受欢迎的摄影爱好者的,因为你可能真的很容易移植到嵌入式设备。为了得到一个完整的第四跨preTER工作,你并不需要一个真正强大的操作系统 - 你只需要在命令除preTER。第四是不是受欢迎,这些天,但它仍然是一个非常酷的语言。

There are a few other stack-based languages, of which the first that jumps to mind is Forth. I mention Forth because it's explicitly a stack-based language; everything you do is phrased in terms of manipulating an operand stack. What's cool about this with regards to your original question is that Forth used to be extremely popular among hobbyists because you could really easily port it to embedded devices. To get a full Forth interpreter working you don't need a really powerful OS - you just need the command interpreter. Forth isn't as popular these days, but it's still a really cool language.

另外一个基于堆栈的语言,它是广泛使用的是的PostScript ,它已经失去了很多的地面PDF,但仍然广泛使用在你需要渲染可扩展的图形在各种不同的平台环境。这在技术上是一个图灵完备的编程语言,但很少有人使用这种方式。

Another stack-based language that's in wide use is PostScript, which has lost a lot of ground to PDF but is still used extensively in environments where you need to render scalable graphics on a variety of platforms. It technically is a Turing-complete programming language, though few people use it that way.

这篇关于基于堆栈的机器依赖基于寄存器的机器上?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆