我有两台计算机,在其中一台计算机上的QtSpim中运行相同的MIPS代码时,没有出现此错误。
我尝试在错误消息中的地址上找到指令,但是在页面上或任何位置都找不到该地址。
我还尝试了单步执行说明。错误消息出现在第一条指令上。
这里是代码,以防万一:
.data
N: .word 4
m: .word 2, 5, 3, 4
.word 1, 7, 2, 7
.word 6, 6, 4, 5
.word 2, 5, 3, 4
a: .space 16
.align 2
# main program + show function
.data
msg1:
.asciiz "Matrix\n"
msg2:
.asciiz "Array\n"
.align 2
.text
.globl main
main:
addi $sp, $sp, -4
sw $fp, ($sp)
la $fp, ($sp)
addi $sp, $sp, -4
sw $ra, ($sp)
la $a0, m
lw $a1, N
la $a2, a
jal colSum # colSum(m, N, a)
la $a0, msg1
li $v0, 4
syscall # printf("Matrix\n")
la $a0, m
lw $a1, N
jal showMatrix # showMatrix(m, N)
la $a0, msg2
li $v0, 4
syscall # printf("Array\n")
la $a0, a
lw $a1, N
jal showArray # showArray(b, N)
lw $ra, ($sp)
addi $sp, $sp, 4
lw $fp, ($sp)
addi $sp, $sp, 4
j $ra
# end main()
# void showMatrix(m, N)
# params: m=$a0, N=$a1
# locals: m=$s0, N=$s1, row=$s2, col=$s3
showMatrix:
addi $sp, $sp, -4
sw $fp, ($sp)
la $fp, ($sp)
addi $sp, $sp, -4
sw $ra, ($sp)
addi $sp, $sp, -4
sw $s0, ($sp)
addi $sp, $sp, -4
sw $s1, ($sp)
addi $sp, $sp, -4
sw $s2, ($sp)
addi $sp, $sp, -4
sw $s3, ($sp)
move $s0, $a0
move $s1, $a1
li $s2, 0
show_matrix_loop1:
bge $s2, $s1, end_show_matrix_loop1
li $s3, 0
show_matrix_loop2:
bge $s3, $s1, end_show_matrix_loop2
li $a0, ' ' # putchar(' ')
li $v0, 11
syscall
move $t0, $s2
mul $t0, $t0, $s1
add $t0, $t0, $s3
li $t1, 4
mul $t0, $t0, $t1
add $t0, $t0, $s0
lw $a0, ($t0)
li $v0, 1 # printf("%d",m[row][col])
syscall
addi $s3, $s3, 1 # col++
j show_matrix_loop2
end_show_matrix_loop2:
li $a0, '\n' # putchar('\n')
li $v0, 11
syscall
addi $s2, $s2, 1 # row++
j show_matrix_loop1
end_show_matrix_loop1:
lw $s3, ($sp)
addi $sp, $sp, 4
lw $s2, ($sp)
addi $sp, $sp, 4
lw $s1, ($sp)
addi $sp, $sp, 4
lw $s0, ($sp)
addi $sp, $sp, 4
lw $ra, ($sp)
addi $sp, $sp, 4
lw $fp, ($sp)
addi $sp, $sp, 4
j $ra
# void showArray(a, N)
# params: a=$a0, N=$a1
# locals: a=$s0, N=$s1, i=$s2
showArray:
addi $sp, $sp, -4
sw $fp, ($sp)
la $fp, ($sp)
addi $sp, $sp, -4
sw $ra, ($sp)
addi $sp, $sp, -4
sw $s0, ($sp)
addi $sp, $sp, -4
sw $s1, ($sp)
addi $sp, $sp, -4
sw $s2, ($sp)
move $s0, $a0
move $s1, $a1
li $s2, 0 # i = 0
show_array_for:
bge $s2, $s1, end_show_array_for
li $a0, ' ' # putchar(' ')
li $v0, 11
syscall
move $t0, $s2
mul $t0, $t0, 4
add $t0, $t0, $s0
lw $a0, ($t0)
li $v0, 1 # printf("%d",a[i])
syscall
incr_show_array_for:
addi $s2, $s2, 1 # i++
j show_array_for
end_show_array_for:
li $a0, '\n'
li $v0, 11
syscall
lw $s2, ($sp)
addi $sp, $sp, 4
lw $s1, ($sp)
addi $sp, $sp, 4
lw $s0, ($sp)
addi $sp, $sp, 4
lw $ra, ($sp)
addi $sp, $sp, 4
lw $fp, ($sp)
addi $sp, $sp, 4
j $ra
# COMP1521 17s2 Final Exam
# void colSum(m, N, a)
.text
.globl colSum
# params: m=$a0, N=$a1, a=$a2
colSum:
# prologue
addi $sp, $sp, -4
sw $fp, ($sp)
la $fp, ($sp)
addi $sp, $sp, -4
sw $ra, ($sp)
addi $sp, $sp, -4
sw $s0, ($sp)
addi $sp, $sp, -4
sw $s1, ($sp)
addi $sp, $sp, -4
sw $s2, ($sp)
addi $sp, $sp, -4
sw $s3, ($sp)
addi $sp, $sp, -4
sw $s4, ($sp)
addi $sp, $sp, -4
sw $s5, ($sp)
# suggestion for local variables (based on C code):
# m=#s0, N=$s1, a=$s2, row=$s3, col=$s4, sum=$s5
li $s4, 0 # col
li $s5, 0 # sum
for_col:
bge $s4, $a1, for_col_end # if col >= N, end the loop
li $s5, 0 # sum = 0 ;
li $s3, 0 # row
for_row:
bge $s3, $a1, for_row_end # if row >= N, end the loop
# DO : sum += m[row][col];
li $t0, 4 # size of int
mul $t1, $a1, $s3 # curr row x number of columns
add $t1, $t1, $s4 # =+ current column
mul $t0, $t1, $t0 # =* size of int ////// $t0 is now the offset
# la $t1, ($a0) # load address of matrix into $t1
add $t0, $t0, $a0 # get the exact address of our current position in the matrix
lw $t1, ($t0) # get the word value from the address
add $s5, $s5, $t1 # sum += m[row][col];
addi $s3, $s3, 1 # row ++;
j for_row;
for_row_end:
# DO: a[col] = sum;
li $t0, 4
mul $t0, $t0, $s4 # 4xcol this is out offset from array a
addu $t0, $t0, $a2 # current address of a[col]
sw $s5, ($t0) # a[col] = sum; /// store the word in $s3 (sum) into the address at $t0
addu $s4, $s4, 1 # col ++
j for_col;
for_col_end:
# epilogue
lw $s5, ($sp)
addi $sp, $sp, 4
lw $s4, ($sp)
addi $sp, $sp, 4
lw $s3, ($sp)
addi $sp, $sp, 4
lw $s2, ($sp)
addi $sp, $sp, 4
lw $s1, ($sp)
addi $sp, $sp, 4
lw $s0, ($sp)
addi $sp, $sp, 4
lw $ra, ($sp)
addi $sp, $sp, 4
lw $fp, ($sp)
addi $sp, $sp, 4
j $ra
我觉得这可能与计算机上的设置有关,因为我已经在同事的计算机上的QtSpim上尝试过此代码,并且可以正常工作。
答案 0 :(得分:1)
如果我在QtSpim中启用了延迟分支,我也会收到类似的消息。
在无法运行的计算机上,单击设置中的“简单计算机”按钮,然后尝试这些设置。
答案 1 :(得分:1)
解决了!原来,我在很久以前就设置了QtSpim中的参数,(愚蠢地)忘记了清除。对于遇到此问题的任何人,请转到 Simulator> Run Parameters>(清除框并单击OK)。