代码是:
# first Spim program
.data #Global Data here
N: .word 5 #loop count
X: .word 2,4,6,8,10 #array of integers
SUM: .word 0 #location of final sum
str : .asciiz "The sum of the array is ="
.text
.globl main #main defined globally
main:
lw $s0, N #Loop count N(initially must be zero) loaded in $s0
la $t0,X #Address of X into t0
$s1, $s1, $zero #logical and with zero results in zero
loop:
lw $t1, 0(#t0)
add $s1,$s1,$t1
addi $t0, $t0, $4
addi $s0, $s0, -1
bne $0, $s0, loop
sw $s1, SUM
li $v0, 10
syscall
.end
在PC = 0x0040003c处发生异常
算术溢出spim:(解析器)文件
/ home / divyanshu / Documents / QtSpim_Codes_and_stuff /第一个Qtspim program.txt
.word 2,4,6,8,10#整数数组
答案 0 :(得分:0)
您有很多错误。
数组中元素之间不应包含逗号
可能是过去的代码,但字符串上的引号不正确,应为“
$ s1,$ s1,$ zero(main的第3行)不是有效的指令-您要将s1设置为0。
循环开始:lw $ t1,0(#t0)无效,#应该为$
addi $ t0,$ t0,$ 4:表示t0 = t0 +您要加4的a4,因此请删除$视为数字。
为我工作:
.data #Global Data here
N: .word 5 #loop count
X: .word 2 4 6 8 10 #array of integers
SUM: .word 0 #location of final sum
str : .asciiz "The sum of the array is ="
.text
.globl main #main defined globally
main:
lw $s0, N #Loop count N(initially must be zero) loaded in $s0
la $t0,X #Address of X into t0
move $s1, $zero
loop:
lw $t1, 0($t0)
add $s1,$s1,$t1
addi $t0, $t0, 4
addi $s0, $s0, -1
bne $0, $s0, loop
sw $s1, SUM
li $v0, 10
syscall
如果练习中需要打印语句,则仍然需要添加打印语句。