在MIPS中加载和存储字节 [英] Loading and storing bytes in MIPS

查看:531
本文介绍了在MIPS中加载和存储字节的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

明天我正在学习考试,我对加载/存储字节数主题感到困惑.我有这个例子:

I'm studying for an exam tomorrow and I'm quit confused on the loading/storing bytes topic. I have this example:

我根本不明白他是怎么用红色获得答案的.有人可以帮我解释一下吗?

I don't understand how he got the answers in red at all. Could someone help explain this to me?

推荐答案

add    $s3, $zero, $zero

这将执行加法运算$s3 = 0 + 0,有效地将寄存器$s3设置为零.

This performs the addition $s3 = 0 + 0, effectively setting the register $s3 to a value of zero.

lb     $t0, 1($s3)

l 从存储器中的位置到寄存器$t0 b .存储器地址由1($s3)给出,即地址$s3+1.这将是内存中的0 + 1 = 1stbyte.由于我们具有大端架构,因此我们从大端优先"读取4字节块的字节.

This loads a byte from a location in memory into the register $t0. The memory address is given by 1($s3), which means the address $s3+1. This would be the 0+1=1st byte in memory. Since we have a big-endian architecture, we read bytes the 4-byte chunks "big end first".

byte:  0   1   2   3
      00  90  12  A0

第0个字节是00,第1个字节是90.因此我们将字节90加载到$t0中.

The 0th byte is 00, and the 1st byte is 90. So we load the byte 90 into $t0.

sb     $t0, 6($s3)

s 将寄存器$t0中的 b 转换为6($s3)给定的内存地址.同样,这表示地址$s3+6.

This stores a byte from the register $t0 into a memory address given by 6($s3). Again this means the address $s3+6.

byte:  4   5   6   7
      FF  FF  FF  FF

成为

byte:  4   5   6   7
      FF  FF  90  FF


现在,如果架构是低端的怎么办?这意味着字节在内存中的排列顺序是小写优先",因此第二条指令和第三条指令的效果会发生变化.


Now, what if the architecture was little-endian? This would mean bytes are arranged "little end first" in memory, so the effect of the 2nd and 3rd instructions change.

lb     $t0, 1($s3)

这会将存储器地址1中的字节加载到寄存器$t0中.但是现在地址是从小到小",因此我们将12读入寄存器.

This loads the byte in memory address 1 into register $t0. But now the addresses are "little end first", so we read 12 into the register instead.

byte:  3   2   1   0
      00  90  12  A0

下一步...

sb     $t0, 6($s3)

这会将字节12中的字节存储在内存地址6中,该字节又是12.再次使用小字节序结构:

This stores the byte in register $t0, which is 12 into a memory address 6. Again with little-endian architecture:

byte:  7   6   5   4
      FF  FF  FF  FF

成为

byte:  7   6   5   4
      FF  12  FF  FF

这篇关于在MIPS中加载和存储字节的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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