assembly - MIPS - 获取数组值

标签 assembly mips

好的,所以我在内存中存储了一个数组,我想本质上创建一个变量“i”并获取索引 i 处的数组值。我如何在 MIPS 中执行此操作?提前致谢!这是我的代码。

.data
array: .word 0:100

.text
li $t0, 5 #this is my representation of "i"

la $t2, array

lw $t1, i($t2) #this is where i am messed up.

最佳答案

您应该将基数和索引相加,并记住将字长按 4 倍缩放。像这样的事情:

li $t0, 5          # this is my representation of "i"
la $t2, array
sll $t1, $t0, 2    # scale by 4
addu $t1, $t1, $t2 # add offset and base together
lw $t1, ($t1)      # fetch the data

如果 i 是适合 16 位的立即常量,则只能使用 i($t2) 样式。

关于assembly - MIPS - 获取数组值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28491018/

相关文章:

c - 在英特尔 64 位机器上启用/禁用缓存 : CD bit always set?

c++ - 带有/SAFESEH 的自定义 SEH 处理程序

c - 使用自定义 __start 的 GCC/LD 的异常输出

java - 以 mips 为单位传递参数

assembly - MIPS 汇编器提示 PIC 为 "Branch out of range"

mips - R型指令的移位量字段存储什么

assembly - 这个程序中的堆栈指针是如何通过 call 和 ret 改变的

c - 不需要的跳转中断 MPLAB X IDE v.3.30

linux - 在 Linux 上的 64 位进程中运行 32 位代码 - 内存访问

simulation - 使用 Verilog 在 FPGA 上模拟 MIPS 处理器