Partager via


THUMB Epilog

The THUMB epilog is a contiguous sequence of instructions that restores the saved permanent registers, resets the stack pointer to its value on function entry, and returns to the function's calling function. When unwinding out of a function, the Virtual Unwinder must determine if the currently executing instruction is in the prolog or epilog. If the current point of control lies in either of these areas, special measures must be taken to unwind out of the function.

In addition, the Virtual Unwinder requires that an epilog have certain specific parts. All parts are immediately contiguous, with no intervening instructions.

The following list shows important information about an epilog.

Note   In the following discussion, {R0-R3} denotes {R0, [R1, [R2, [R3]]]}, and {R4-R7} denotes {[[[R4], R5], R6], R7}.

  • If a frame pointer has been setup by the prolog, the epilog restores the stack pointer from the frame pointer. It uses a single mov instruction to copy R7 to R13. This copy restores R13 to the value it had just after the prolog linked the stack.
    Unlinking the stack restores R13.

  • If {R4-R7} are to be restored, and if high registers are not to be restored, then the epilog must contain an instruction to pop {R4-R7}. This instruction updates the stack pointer. If the Unwinder restores high registers, then it also restores R4-R7.

  • The epilog contains a sequence of zero or two instructions that pop the link register from the stack into R3. If the routine is a leaf or if the routine restores high registers, the epilog omits this sequence.

    If the epilog restores high registers, it uses a branch and link to call a restore-register routine that restores R4 through R7 and the link register. It also restores the stack pointer to the value it held just after the prolog saved {R0-R3}, or to the value the stack pointer held on entry of the function if {R0-R3} were saved.

  • In a non-interworking routine that does not need to save any registers other than {R4-R7, LR}, the epilog will end with pop {R4-R7, PC} or pop {PC} if {R4-R7} do not need saved. If a non-interworking routine needs to save other registers, the epilog will end with a copy of R3 to the PC.

    In an interworking routine, the epilog will end with a branch and exchange (BX) to R3.

See Also

ARM Prolog and Epilog | ARM Prolog | ARM Epilog | THUMB Prolog | ARM Prolog and Epilog Coding Examples

 Last updated on Thursday, April 08, 2004

© 1992-2003 Microsoft Corporation. All rights reserved.