Mips 数据布局计算
我正在密歇根大学自学计算机架构。我不明白为什么 d 的内存布局从 312 开始到 319 而不是 308 http ://www.flickr.com/photos/45412920@N03/4442695706/。 ( http://www.flickr.com/photos/45412920@N03/4442695706/ ) 也许我不理解指定的黄金法则http://www. flickr.com/photos/45412920@N03/4441916461/sizes/l/ 这里( http://www.flickr.com/photos/45412920@N03/4441916461/sizes/l/)好吧。
I am self studying computer architecture offer at Michigan university. I do not understand why the memory layout for d starts at 312 to 319 instead of 308 http://www.flickr.com/photos/45412920@N03/4442695706/. ( http://www.flickr.com/photos/45412920@N03/4442695706/ )
Maybe I did not understanding the Golden rule specified http://www.flickr.com/photos/45412920@N03/4441916461/sizes/l/ here( http://www.flickr.com/photos/45412920@N03/4441916461/sizes/l/ ) well.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
第二个链接显示MIPS无法打包变量,因此它们占用的地址必须落在字边界上。
如果short是半字对齐,则占用两个字节,int是字对齐,所以占用4个字节,double必须是双字对齐,所以占用8个字节。
为了在这些位置对齐。
最低有效位 (LSB) 中的零表示每隔一个或每 2 个字节(半字对齐),2 个零表示每第 4 个字节,每 8 个字节有 3 个零。
double 必须双字对齐,因此它不能从 308 (100110100) 开始,因为它只是字对齐 (2 LSB = 0),它必须从下一个双字对齐 312 (100111000) 开始
The second link shows that MIPS cannot pack variables, therefore the addresses they take up must fall on word boundaries.
if short is half word aligned, it takes up two bytes, int, is word aligned so it takes up 4 bytes, double must be doubleword aligned so it takes up 8 bytes.
In order to align at these places..
A zero in the Least Significant bit (LSB) would indicate every other or every 2 bytes (half word aligned), 2 Zeros indicates every 4th byte, and 3 zeros every 8th byte.
The double must be double word aligned so it can not start at 308 (100110100) because it is only word aligned (2 LSBs = 0) it must start at the next double word alignment 312 (100111000)
MIPS 上的内存访问是字对齐的,这意味着一次读取内存 32 位/4 字节。由于变量“b”是单个字节,因此它实际上读取地址300-303。如果变量“c”从 301 开始,处理器必须知道“b”只是一个字节,并将其他字节清零,并可能将其移至 LSB 位置(或者编译器必须这样做)。不管怎样,在 4 字节边界(4 的倍数)上进行所有内存访问会更有效。
有关详细信息,请参阅数据结构对齐。
Memory access on the MIPS is word aligned which means that is reads the memory 32 bits/4 bytes at a time. Since variable "b" is a single byte, it actually reads addresses 300-303. If variable "c" were to start at 301, the processor would have to know that "b" is only a byte and zero out the other bytes and possibly shift it to the LSB position (or the compiler would have to do it). Either way, it's more efficient to just alight all memory access on 4 byte boundaries (multiple of 4).
See Data Structure Alignment for more info.