What is non-aligned access? (ARM/Keil)

前端 未结 5 1854
抹茶落季
抹茶落季 2020-12-16 05:49

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 7         


        
5条回答
  •  萌比男神i
    2020-12-16 06:39

    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 or 0x7F7F7F80.

    Similarly, LDRH/STRH require 2-byte alignment, whereas LDRB/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).

提交回复
热议问题