CPU 如何知道变量的大小以正确读取它?
好吧,我在这类话题上很直率,如果我完全不合规矩的话,我很抱歉。我会尽力说清楚。
在内存中,当读取命令时,CPU 如何知道它必须读取 4 字节字符串或 10 字节字符串才能处理该命令?或者另一个命令,CPU 知道它必须读取 int64 的大小才能正确读取数据才能使用它?大小存储在某处吗?可能是计算出来的?
Well I'm quite blunt on this type of subject, so sorry if I'm completely out of line on things. I'll try to be clear.
In memory when commands are being read for say, How does the CPU know that it has to e.g. read a 4 byte string or a 10 byte string to work with for that command? or another command, the CPU knows that it has to read the size of an int64 to correctly read the data to work with it? is the size stored somewhere? possibly calculated?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
数据大小通常编码在指令中,或者隐式已知。以 x87 为例:
The data size is usually encoded in the instruction, or is implicitly known. In for example x87:
让我们看一下字符串来部分回答这个问题,在 C 中,必须以空值终止字符串(即以空字节或
\0
结尾),因此读取到字符串是一项简单的工作。空字节。对于固定类型的数据(例如
int
),编译器将通知 CPU 它正在处理 int,并且编译器和 CPU 将使用相同的体系结构,它们的int
的长度相同。Let's look at strings for a partial answer to this, in C one has to null-terminate one's strings (i.e. end it with a null byte or
\0
) therefore it's a simple job of reading up to the null byte.On fixed types of data (let's say an
int
) then the compiler will inform the CPU that it's dealing with an int and as both compiler and CPU will be working with the same architecture, theirint
s will be the same length.