"Access to unaligned memory location, bad address=ffffff"

1k views Asked by At

I'm trying to read integers from an input.txt file, below is my read loop where I'm attempting to read and store the integers into an array. I keep getting "Access to unaligned memory location, bad address=ffffff" on any line after the line with "LDR R2, [R2,R5,LSL #2]...im using ARM SIM. Does anyone know what I'm doing wrong?

    start:
    MOV R5, #0      @int i 
    MOV R1, #0
    swi SWI_Open
    LDR R1,=InFileH
    STR R0,[R1]
    MOV R3, #0

readloop:
    LDR R0, =InFileH
    LDR R0, [R0]
    swi SWI_RdInt
    CMP R0, #0
    BEQ readdone
    @the int is now in R0
    MOV R1, R0
    LDR R3,=a
    STR R2,[R3,R5,LSR#2]
    MOV R2, R1
    ADD R5, R5, #1      @i++
    bal readloop

readdone:
    MOV R0, #0
    swi SWI_Close
    swi SWI_Exit

.data
.align 4
InFileH:    .skip 4
InFile:     .asciz  "numbers.txt"
OutFile:    .asciz "numsort.txt"
OutFileH:   .skip 4
NewLine:    .asciz "\n"

a:  .skip 400
1

There are 1 answers

0
Abhishek D K On

i had faced similar issue while programming arm assembly
this was because it was expecting offset in multiples of 4

STR R2, [R1, #2]

the above instruction throws the similar error. so it was resolved by using

STR R2, [R1, #4]

for better understanding clickhere