在MIPS中从寄存器向基址添加偏移量 [英] Adding offset to base from register in MIPS

查看:446
本文介绍了在MIPS中从寄存器向基址添加偏移量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我在t3中有一个数字,可以使用lw $ s3,$ t3($ t0)来获取存储在base + offset所引用的内存中的值,其中base在t0中,偏移量在t3中s3?

解决方案

我相信plaknas提供的解决方案只有一半正确,因为在创建" MIPS中的偏移量时必须考虑字长. /p>

假设字长为4个字节,这是正确的答案:

sll $t3, $t3, 2
add $t0, $t0, $t3
lw $s3, 0($t0)

If I have a number in t3, can I use lw $s3, $t3($t0) to get the value stored at the memory referenced by base+offset where the base is in t0 and the offset is in t3 into s3?

解决方案

I believe that the solution plaknas gives is only half-correct, as you have to take the word size into account when "creating" the offset in MIPS.

Here is the correct answer, assuming a word size of 4 bytes:

sll $t3, $t3, 2
add $t0, $t0, $t3
lw $s3, 0($t0)

这篇关于在MIPS中从寄存器向基址添加偏移量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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