arrays - 在 MIPS 中创建(和访问)数组

标签 arrays assembly mips mars-simulator

我正在尝试在 MIPS Assembly 中创建一个数组,然后将所有元素添加在一起。但是,当我尝试组装以下内容时,它显示

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

进入.data部分。检查这个quick tutorial .

关于arrays - 在 MIPS 中创建(和访问)数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2368553/

相关文章:

arrays - 为什么在 Matlab 中通过 sub2ind 进行索引与通过 A(i, j) 进行索引不同?

mips - 'jalr $a0, $a0' 的正确行为是什么?

C 到 MIPS 汇编

assembly - 如何在 aarch64 程序集列表中轻松导航

c - 我应该如何编写 C 代码以使生成的程序集使用额外的 dsll32 和 dsra32 指令?

javascript - 使用 jQuery 按值删除 JSON 数组中的元素

python - 多维 Numpy 数组排序

java - 特定整数集的哈希函数

assembly - 试图理解汇编指令 : cltd on x86

assembly - "mov (%rax),%eax"和 "mov %rax,%eax"有什么区别?