MIPS异常4和5错误

时间:2011-02-19 20:32:08

标签: exception assembly mips

我正在尝试使用堆栈创建函数AVA,其中x1 [i] = y1 [i] + z1 [i],除了我收到这些错误:

  Exception 5  [Address error in store]  occurred and ignored
  Exception 5  [Address error in store]  occurred and ignored
  Exception 5  [Address error in store]  occurred and ignored
  Exception 5  [Address error in store]  occurred and ignored
  Exception 5  [Address error in store]  occurred and ignored
  Exception 4  [Address error in inst/data fetch]  occurred and ignored
0
  Exception 4  [Address error in inst/data fetch]  occurred and ignored
0
  Exception 4  [Address error in inst/data fetch]  occurred and ignored
0
  Exception 4  [Address error in inst/data fetch]  occurred and ignored
0
  Exception 4  [Address error in inst/data fetch]  occurred and ignored
0 

继承我的代码:

    .data
newline: .asciiz  "\n"
x1: .space 20
y1: .word 1, 2, 3, 4, 5
z1: .word -5, -4, -3, -2, -1
x2: .space 40
y2: .word -1, 3, -5, 7, -9, 2, -4, 6, -8, 10
z2: .word 1,2,3,4,5,6,7,8,9,10
#######################################################

  .globl main
  .text

main:
#$a0-a3 for passing to functions
#$v0-v1 for storing return values from functions

  addiu $sp, $sp, -16    #allocate stack space
  la $t0, x1          #AVA(x1,y1,z1,5)
  sw $t0, 0($sp)
  la $t0, y1
  sw $t0, 4($sp)
  la $t0, z1
  sw $t0, 8($sp)
  li $t0, 5
  sw $t0, 12($sp)
  jal AVA 
  addiu  $sp, $sp, 16    #deallocate stack space
#############################  
  la $t0, x1      #t0 = x
  li $t2, 0          #iterator
  li $t3, 5      #array size
For:
  bge     $t2, $t3, endFor       # loop while element <= arraysize
  lw      $t1, 0($t0)             # get word from x array

   li      $v0, 1                  # 'print' command code
   move    $a0, $t1                # needs value in $a0
   syscall                         # print it


  # print newline
  li  $v0, 4
  la  $a0, newline
  syscall


   addi    $t0, $t0, 4             # move to next entry in array x
   addi    $t2, $t2, 1             # increment iterator number

  b For                  # go to Loop
endFor:
#############################

li $v0, 10  #exit
syscall

AVA:
  li $t0, 0          #iterator
  lw $t1, 0($sp)        #x[i]
  lw $t2, 4($sp)        #y[i]
  lw $t3, 8($sp)        #z[i]
  lw $t4, 12($sp)       #n

loop:
  bge $t0, $t4, return   # loop while iterator < n
  lw  $t5, 0($t2)
  lw  $t6, 0($t3)
  add $t5, $t5, $t6      #y[i] + z[i]
  sw $t5, 0($t1)        #x[i] = y[i] + z[i]

  addi $t0, $t0, 1      #increment iterator
  addi $t1, $t1, 4      #increment x
  addi $t2, $t2, 4      #increment y
  addi $t3, $t3, 4      #increment z
  b loop

return:
  sw $t1, 0($sp)
  jr $ra
#######################################################  

和我的完整日志: http://pastie.org/1583460

1 个答案:

答案 0 :(得分:1)

您在阵列之前缺少.align指令。 newline常量长度为两个字节,因此x1y1z1从未对齐的地址开始。尝试在定义.align 2之前添加x1(对齐2 ^ 2个字节的多个字节)。