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

What is the meaning of a 64 bit aligned stack pointer address?

According to ARM Architecture Procedure Call Standard (AAPCS) on the ARMv6-M, and ARMv7-M architecture in  it says:

"Although the processor hardware allows SP to be at any word aligned address at function boundaries, standard programming practice requires C program code to ensure that the SP is at a 64-bit (doubleword) aligned address."

What does it mean that the Stack pointer has to be at a 64 bit aligned address?

Parents
  • Hi Yasuhiko,

    In Cortex-M0 and Cortex-M0+ processors, CCR.STKALIGN is fixed to 1. So it always enforce 8 byte stack alignment for exception stack frames.

    When setting up the initial SP values, the values should be 8 bytes aligned.

    When having function calls, the SP value at function call boundaries should be 8 byte aligned. It is okay to have 4 byte alignment in the middle of a function, as long as the SP value is adjust back to 8 bytes aligned before the function is ended or a function call is made.

    If a function is coded in assembly language, and inside this function it calls another assembly function which you knew that it does not require 8 byte stack alignment, you can have 4 byte stack alignment at function call in such case. But if you are calling a C function, then 8 byte stack alignment is required, as the C compiler might make assumption of SP value in pointer handling.

    Hope this helps.

    regards,

    Joseph

Reply
  • Hi Yasuhiko,

    In Cortex-M0 and Cortex-M0+ processors, CCR.STKALIGN is fixed to 1. So it always enforce 8 byte stack alignment for exception stack frames.

    When setting up the initial SP values, the values should be 8 bytes aligned.

    When having function calls, the SP value at function call boundaries should be 8 byte aligned. It is okay to have 4 byte alignment in the middle of a function, as long as the SP value is adjust back to 8 bytes aligned before the function is ended or a function call is made.

    If a function is coded in assembly language, and inside this function it calls another assembly function which you knew that it does not require 8 byte stack alignment, you can have 4 byte stack alignment at function call in such case. But if you are calling a C function, then 8 byte stack alignment is required, as the C compiler might make assumption of SP value in pointer handling.

    Hope this helps.

    regards,

    Joseph

Children