为什么我会收到运行时异常:获取地址未在字边界上对齐

Why am i getting Runtime exception: fetch address not aligned on word boundary

我的作业包含这段代码,我需要修复它,但我现在无法继续...代码应该移动一个数组 t

          .data
source:   .word   3, 1, 4, 1, 5, 9, 0
dest:     .word   0, 0, 0, 0, 0, 0, 0
countmsg: .asciiz " values copied. "

          .text

main:   la      $a0,source
    la      $a1,dest

loop:   lw      $v1, 0($a0)     # read next word from source
        addiu   $v0, $v0, 1     # increment count words copied
        sw      $v1, 0($a1)     # write to destination
        addiu   $a0, $a0, 1     # advance pointer to next source
        addiu   $a1, $a1, 1     # advance pointer to next dest
        bne     $v1, $zero, loop# loop if word copied not zero

loopend:
        move    $a0,$v0         # $a0 <- count
        jal     puti            # print it

        la      $a0,countmsg    # $a0 <- countmsg
        jal     puts            # print it

        li      $a0,0x0A        # $a0 <- '\n'
        jal     putc            # print it

finish:
        li      $v0, 10         # Exit the program
        syscall




### The following functions do syscalls in order to print data (integer, string, character)
#Note: argument $a0 to syscall has already been set by the CALLEE

puti:
        li      $v0, 1          # specify Print Integer service
        syscall                 # Print it
        jr      $ra             # Return

puts:
        li      $v0, 4          # specify Print String service
        syscall                 # Print it
        jr      $ra             # Return

putc:
        li      $v0, 11         # specify Print Character service
        syscall                 # Print it
        jr      $ra             # Return

它 returns 0x00400010 处的运行时异常:获取地址未在字边界 0x10010001 上对齐

我认为错误在第 11 行,但我无法解决。

你的前进指针是错误的。 如果数组的元素是单词,则必须使用 lw/sw 到 read/write 元素 from/to 数组并考虑到每个元素占用 4 个字节(因此,1 个字)。因此,要推进指针,您必须向指针添加 4(代码中的 $a0$a1)。

如果您尝试使用字节数组,那么您将使用 .byte 指令来定义您的数组,lb/sb 并将指针递增 1一次定位(就像您在代码中所做的那样)。

不应该是 addiu $a0, $a0, 4 因为你必须跳到下一个词