【发布时间】:2011-01-23 00:53:48
【问题描述】:
我正在尝试在 MIPS 程序集中创建一个数组,然后将所有元素添加在一起。但是,当我尝试组装以下内容时,它会说
read_array 第 1 行位置 7 出错:“.word”指令不能出现在文本段中 组装:操作完成但出现错误。
这是我的程序集:
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:
谢谢!
【问题讨论】:
-
我知道这段代码中有一些逻辑错误,但我的问题得到了解答。谢谢!
-
这真的很奇怪,IDK,如果这个限制是为了保护初学者免于将数据与代码混合并在执行落入他们的数据时让他们的程序崩溃,或者什么。在大多数汇编程序中,您可以在任何地方使用
.byte/.word或db/dd在任何位置发出您想要的任何字节。 (例如,出于某种原因发出指令的非默认编码。)
标签: arrays assembly mips mars-simulator