This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Alignment in ARM?

I could not clearly understand the alignment issues present in ARM. Sometimes I get BUS ERROR while running an assembly file but don't know how to resolve it. Some of the doubts:

1. Is it better to store registers pairwise or individually on the stack?

2. Should alignment be 16-byte or 8-byte?

3. How to be sure that alignment is always correct?

Can someone please throw some light on this topic?

  • Alignment constraints for the stack are given in

    http://infocenter.arm.com/help/topic/com.arm.doc.ihi0042f/IHI0042F_aapcs.pdf   (32 bit)

    http://infocenter.arm.com/help/topic/com.arm.doc.ihi0055c/IHI0055C_beta_aapcs64.pdf   (64 bit)

    The appropriate ARM Architectural manual for whatever you're using will say what the alignment support is under a section called 'Alignment support' and 'Unaligned data access restrictions' but briefly

    For 32 bit the stack should be 8 byte aligned when calling anything and for 64 bit it should be 16 byte aligned all the time.

    Unaligned access is never allowed to device memory or when doing exclusive access.or load acquire/store release

    Alignment is based on element size for multiple elements. The system can set a option so any access which is unaligned for the element length causes an interrupt.

    In the 32 bit instruction set there are some extra restrictions for LDM/STM, LDRD/STRD and some other instructions. The Cortex-M0  and some earlier cores don't support unaligned access, and even earlier ones do something weird and wonderful.