Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.4k views
in Technique[技术] by (71.8m points)

assembly - Error: Runtime exception ... store address not aligned on word boundary

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 "
"

    .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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share

2.1m questions

2.1m answers

62 comments

56.6k users

...