简体   繁体   English

MIPS中的阵列地址

[英]Array address in MIPS

In Section 2.14 (pp 141) in Patterson and Hennessy (5th Ed), the authors write that "to set array[i] to 0, we must first get its address. Start by multiplying i by 4 to get the byte address: loop1: sll $t1, $t0, 2 ". 在Patterson和Hennessy(第5版)的2.14节(第141页)中,作者写道:“将array[i]设置为0,我们必须首先获取其地址。首先将i乘以4得到字节地址: loop1: sll $t1, $t0, 2 “。

I do not understand why we must multiply by 4 to get the byte address. 我不明白为什么我们必须乘以4才能得到字节地址。 Could it be because 1 word = 32 bits, which is 4 bytes? 可能是因为1个字= 32位,即4个字节吗?

Yes, memory [chip] is addressable by individual bytes, so the very first word occupies four addresses: 0, 1, 2, 3. Each is 8 bits = 1 byte, together they form 32 bit value = 1 word (in MIPS world word = 32 bits). 是的,内存[芯片]可以通过单个字节进行寻址,因此第一个字占用四个地址:0、1、2、3。每个都是8位= 1字节,它们一起形成32位值= 1个字(在MIPS世界中) word = 32位)。 The order of them can be configured IIRC, but usually little-endian is assumed, so when loading whole word , the four bytes 0x12 0x34 0x56 0x78 form a word value 0x78563412 . 它们的顺序可以配置为IIRC,但通常采用小尾数法,因此在加载整个word ,四个字节0x12 0x34 0x56 0x78形成字值0x78563412

So to read consecutively by-words you have to adjust your address by +-4. 因此,要连续读取单词,您必须将地址调整+ -4。 If you have byte array, then the address can be adjusted by +-1, and half-words occupy 2 bytes, so +-2 addressing would do. 如果您具有字节数组,则可以通过+ -1来调整地址,并且半字占用2个字节,因此+ -2寻址即可。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM