创建(和访问)的MIPS数组 [英] Creating (and accessing) an array in MIPS

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

问题描述

我试图创造MIPS大会数组,然后所有的元素加在一起。然而,当我尝试组装以下,它说

I'm trying to create an array in MIPS Assembly, and then add all the elements together. However, when I try to assemble the following, it says

在read_array行错误1位7:.word指令不能出现在文本段
  组装:操作完成但有错误

Error in read_array line 1 position 7: ".word" directive cannot appear in text segment Assemble: operation completed with errors.

下面是我的组装:

list: .word 3, 2, 1, 0, 1, 2
li $t0, 0x00000000  #initialize a loop counter to $t0
li $t4, 0x00000005  #last index of array
li $t3, 0x00000000  #this will hold our final sum
la $t1, list  #the address of list[0] is in $t1

loop: addi $t0, $t0, 0x00000001 #index++
  add $t5, $t0, $t0 #array index X2
  add $t5, $t0, $t0 #array index X2 again
  add $t6, $t5, $t1 #4x array index in $t6

  lw $t2, 0($t6)   #load list[index] into $t2
  add $t3, $t3, $t2 #$t3 = $t3 + $t2
  beq $t0, $t4, end
  j loop

end:

谢谢!

推荐答案

您必须把这个行:

list: .word 3, 2, 1, 0, 1, 2

。数据部分。勾选此快速教程

这篇关于创建(和访问)的MIPS数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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