Error: Runtime exception … store address not aligned on word boundary

可紊 提交于 2021-02-02 09:54:29

问题


I am trying to print binary digits of any integer input and store them in the array starting at the last index. Then I am trying to print it from the array.

    .data

prompt: .asciiz "Enter an int: "
errorLarge: .asciiz "Error Value to large CANNOT be held in 16 bit"
errorSmall: .asciiz "Error Value is to small CANNOT be held in 16 bits"

# 64bytes =512 bits created (1 int =4 bytes):: (16 int =64 bytes)
array: .space 64

newLine: .asciiz "\n"

    .globl main
    .text

main:
    li $v0,4
    la $a0,prompt
    syscall

    li $v0,5
    syscall
    move $t0,$v0

    li $t1,32767
    li $t2,-32767

    bgt $t0,$t1,InputToGreat
    blt $t0,$t2,InputToSmall

    li $t2,2
    li $t5,64     # last memory location in array+1

    li $t7,0

    j initializer

InputToGreat:

    li $v0,4
    la $a0,errorLarge
    syscall

    j main

InputToSmall:

    li $v0,4
    la $a0,errorSmall
    syscall

    j main

finalizer:

    subi $t5,$t5,4
    sw  $t4,array($t5)

    li $t4,0

    bne $t5,$zero, finalizer

OutPut:

    lw $t6,array($t7)

    li $v0,1
    move $a0,$t6
    syscall

    addi $t7,$t7,4
    bne  $t7,252,OutPut

    li $v0,10
    syscall

initializer:

    div    $t0,$t2  # (inside house) 1) 12/2  2) 6/2   3) 3/2
    mflo   $t0  #quotient       6        3        1
    mfhi   $t4  #rem                0        0        1

    beq    $t4,1,finalizer

InputToArray:

    subi $t5,$t5,4
    sw  $t4,array($t5) #first time array+60 last location in array

    li $v0,1
    move $a0,$t4
    syscall

    j initializer

I am getting an error on line 99 sw $t4,array($t5) #first time array+60 last location in array which says

line 99: Runtime exception at 0x004000d8: store address not aligned on word boundary 0x100100ab


回答1:


Because you store into array with sw, array must be 4 byte aligned. This a restriction of the mips architecture. Likewise for lw.

So, change:

array: .space 64

Into:

    .align 4
array: .space 64

Also, note that $t5 should be divisible by 4 (which it is when your test program runs)



来源:https://stackoverflow.com/questions/45174399/error-runtime-exception-store-address-not-aligned-on-word-boundary

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!