MIPS - 让数组值 [英] MIPS - getting array values

查看:494
本文介绍了MIPS - 让数组值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好了,我有存储在内存中的数组,我想基本上是创建一个变量i和索引我得到的数组值。如何在MIPS做到这一点?提前致谢!这里是我的code。

 。数据
数组:.word 0:100。文本
李$ T0,5#此为我我再presentationLA $ T2,数组LW $ T1,我($ T2)#这个是我在哪里搞砸了。


解决方案

您应该添加基地和指数一起,并记得4字的大小规模。事情是这样的:

 李$ T0,5#这是我我再presentation
LA $ T2,数组
SLL $ T1,$ T0,4#2规模
阿杜$ T1,T1 $,$#T2加偏移和基地一起
LW $ T1,($ T1)#获取数据

您只能使用 I($ T2)的风格,如果 I 是适合16一个立即数位。

Ok, so I have an array stored in memory and I want to essentially create a variable "i" and get the array value at index i. How do I do this in MIPS? Thanks in advance! Here is my code.

.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.

解决方案

You should add the base and index together, and remember to scale by 4 for the word size. Something like this:

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

You can only use the i($t2) style if i is an immediate constant that fits into 16 bits.

这篇关于MIPS - 让数组值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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