assemblyarmembedded

Why is PUSH instruction used in ARM mode rather than STM?


While debugging in Code Composer Studio (Texas Instruments) with the CPU in ARM mode, I observed a push instruction in the disassembly view.

According to ARM and Thumb Assembler Instructions:

PUSH Pushes multiple registers to the stack in Thumb state (for ARM state use STM)

As mentioned above, the push instruction is used in Thumb state, while STM is used in ARM state.

Q1: Why is push instruction used rather than STM in ARM mode?

I also noticed that the stack pointer's value had been set before program starts running.

Q2: Who decide the stack pointer's initial value before a program start executing?

Program:

int main(void)
{   // program stops here

    OS_ERR  err = OS_ERR_NONE;

    /*rest of code are omitted*/
}

Disassembly:

          main():
805dce18:   E92D4008            push       {r3, lr}
17          OS_ERR  err = OS_ERR_NONE;
805dce1c:   E3A0C000            mov        r12, #0
805dce20:   E58DC000            str        r12, [sp]

Registers:

Name    Value            Description

CPSR    0x6000019F       current program status registers
   T    0                If set ARM is in Thumb mode



  SP    0x88000F30       stack pointer

Solution

  • For Q2) The Stack Pointer initialization location is in your binary file. The first four bytes in your output binary denotes the location to which the stack pointer is to be initialized. You can modify this value as well as the size of the stack in your linker file.