QtSpim error: "attempt to execute non instruction" on working code

QtSpim error: "attempt to execute non instruction" on working code

Screenshot of my error

我有两台计算机,当 运行 其中一台的 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 上尝试了这段代码并且它工作正常。

如果我在 QtSpim 中启用了延迟分支,我会收到类似的消息。

在无法正常工作的机器上,单击设置中的简单机器按钮并尝试这些设置。

已解决!原来在 QtSpim 中有一些参数是我很久以前设置的,但(愚蠢地)忘记清除了。对于遇到此问题的任何人,请转到 Simulator > 运行 Parameters >(清除框并单击“确定”)。