I'm using Keil to write Assembly for ARM 7.
I have the following runtime error:
Non-aligned Access: ARM Instruction at 000000F8H, Memory Access at 7F7F7F7FH
Data Abort: ARM Instruction at 000000F8H, Memory Access at 7F7F7F7FH
This doesn't really help me, because I don't know what 'non-aligned access' is, (other than the obvious, but I don't really understand what it means) and I am trying to access (store) to 0x7F7F7F7F
, what's the issue?
Searching I only found a couple of similar issues, both using C, and resolved by some means very specific to their code and which didn't relate to this issue.
I'm doing:
LDR R0, =0x7F7F7F7F
LDR R1, LABEL
STR R1, [R0]
I then do a similar thing with a different label, and offsets of R0
, but it fails here first.
The issue is that the address you use for a 32-bit (4-byte) memory operation must be aligned to a 4-byte boundary. This means the address must be a multiple of 4, or if you prefer, the bottom two bits of the address must be zero.
In this case, the closest 4-byte aligned addresses would be
0x7F7F7F7C
or0x7F7F7F80
.Similarly,
LDRH
/STRH
require 2-byte alignment, whereasLDRB
/STRB
can operate anywhere (1-byte alignment == unaligned).In general the compiler/assembler takes care of making sure your variables are aligned correctly for the size they are - you should only run into this if you're generating addresses yourself (as per the question).