为什么在MIPS中内存地址增加4? [英] Why are memory addresses incremented by 4 in MIPS?

查看:456
本文介绍了为什么在MIPS中内存地址增加4?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果某个东西存储在0x1001 0000,那么下一个东西存储在0x10010004.如果我正确的话,在32位体系结构中的内存块每个都是32位.那么0x1001 0002会指向32位的后一半吗​​?

If something is stored at 0x1001 0000 the next thing is stored at 0x1001 0004. And if I'm correct the memory pieces in a 32-bit architecture are 32 bits each. So would 0x1001 0002 point to the second half of the 32 bits?

推荐答案

首先,MIPS体系结构中的内存地址不增加4.MIPS使用字节寻址,因此您可以从内存中寻址任何字节(请参见例如lbu读取单个字节,lhlhu读取半字).

First of all, memory addresses in MIPS architecture are not incremented by 4. MIPS uses byte addressing, so you can address any byte from memory (see e.g. lb and lbu to read a single byte, lh and lhu to read a half-word).

事实是,如果读取的字长为32位(4个字节,lw),则两个连续的字将相距4个字节.在这种情况下,您可以在第一个单词的地址上加4以获得下一个单词的地址.

The fact is that if you read words which are 32 bits length (4 bytes, lw), then two consecutive words will be 4 bytes away from each other. In this case, you would add 4 to the address of the first word to get the address of the next word.

此外,如果您要阅读单词,则必须以4的倍数对齐它们,否则会出现对齐异常.

Beside this, if you read words you have to align them in multiples of 4, otherwise you will get an alignment exception.

在您的示例中,如果第一个单词存储在0x10010000中,那么下一个单词将存储在0x10010004中,当然前半部分/后半部分将存储在0x1001000和0x1001002中(顺序将取决于

In your example, if the first word is stored in 0x10010000 then the next word will be in 0x10010004 and of course the first half/second half would be in 0x1001000 and 0x1001002 (the ordering will depend on the endianness of the architecture).

这篇关于为什么在MIPS中内存地址增加4?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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