ARM Prolog and Epilog Coding Examples

The following code samples show ARM and THUMB prolog and epilog code.

  • ARM Prolog with frame in R11.

    MOV    r12, r13        ; Save stack on entry if needed.
    STMDB  r13!, {r0-r3}    ; As needed
    STMDB  r13!, {r4-r12, r14}  ; As needed
    SUB    r11, r12, #16    ; Sets frame past args
    <stack link if needed>
    
  • ARM Prolog with no frame.

    MOV    r12, r13
    STMDB  r13!, {r0-r3}        ; As needed
    STMDB  r13! {[r4-r12,]|[r13,]r14}  ; As needed
    <stack link if needed>
    <note: r12 is not used if the stack (r13) is the first register saved>
    
  • ARM Epilog with frame in R11.

    <no stack unlink>
    LDMDB  r11, {r4-r11, r13, r15}
    
  • ARM Epilog with no frame.

    <stack unlink if needed>
    LDMIA  r13, {r4-R11, r13, r15}
    
  • ARM Epilog with interworking return.

    <stack unlink if needed>
    LDMIA   r13, {r4-r11, r13, LR}
    BX      LR
    
  • THUMB Prolog with no frame.

    PUSH    {r0-r3}    ; As needed
    PUSH    {r4-r7, LR}  ; As needed
    SUB    SP, SP, #4  ; Stack link (as needed)
    
  • THUMB Epilog with no frame.

    ADD    SP, SP, #4    ; Stack link (as needed)
    POP    {r4-r7}      
    POP    {r3}        ; POP link register into r3
    ADD    SP, SP, #16    ; POP r0-r3 as needed
    MOV    PC, r3
    
  • THUMB Prolog with frame in R7.

    PUSH    {r0-r3}      ; As needed
    PUSH    {r4-r7, LR}    ; As needed
    SUB    SP, SP, #4    ; Stack link (as needed)
    MOV    r7, SP      ; Set frame
    
  • THUMB Epilog with frame in R7.

    MOV    r13, r7
    ADD    SP, SP, #4    ; Stack unlink (as needed)
    POP    {r4-r7}      
    POP    {r3}        ; POP link register into r3
    ADD    SP, SP, #16    ; POP r0-r3 as needed
    MOV    PC, r3
    
  • THUMB Prolog with interworking return.

    PUSH    {r4-r7, LR}
    
  • THUMB Prolog saving high registers.

    PUSH    {r0-r3}      ; Save r0-r3 as needed
    PUSH    {LR}
    BL    __savegpr_9    ; Routine for saving {r4-r11}
    SUB    SP, SP, #4    ; Stack link (as needed)
    
  • THUMB Epilog restoring high registers.

    ADD    SP, SP, #4    ; Stack link (as needed)
    BL    __restgpr_9
    ADD    SP, SP, #16    ; POP r0-r3 as needed
    BX    LR
    
  • THUMB Prolog with a large stack frame.

    PUSH    {r7}  
    LDR    r7, [PC, #20]
    NEG    r7, r7
    ADD    SP, r7
    
  • THUMB Epilog with a large stack frame.

    LDR    r7, [PC, #4]
    ADD    SP, r7
    POP    {r7}
    MOV    PC, LR
    
  • Save register routine.

    __savegpr_9
      BX      PC
      NOP
      STMDB    SP!, {r4-r7, r9-r11}
      BX      LR
    
  • Restore register routine.

    __restgpr_9
      MOV      r3, LR
      BX      PC
      LDMIA    SP!, {r4-r7, r9-r11, LR}
      BX      r3
    

See Also

ARM Prolog and Epilog | ARM Prolog | ARM Epilog | THUMB Prolog | THUMB Epilog

 Last updated on Thursday, April 08, 2004

© 1992-2003 Microsoft Corporation. All rights reserved.