SH-3 Prolog and Epilog Examples
The following examples show how to use prologs and epilogs in specific situations.
Allocate a stack frame to save R14, R8, and PR
The following example allocates a stack frame to save R14, R8, and PR and to allow alloca() calls. In addition, the example allocates a four-word argument build area. It needs no stack space for local variables or temporaries.
NESTED_ENTRY Function mov.l R14, @-R15 // Save old frame pointer. mov.l R8, @-R15 // Save a permanent register. sts.l PR, @-R15 // Save return address. mov R15, R14 // Set up new frame pointer. add #12, R14 add #-16, R15 // Allocate argument save area. PROLOG_END // Routine body add #-12, R14 // Find base of RSA. mov R14, R15 lds.l @R15+, PR // Restore return address. mov.l @R15+, R8 // Restore R8. rts // Return mov.l @R15+, R14 // Restore R14. ENTRY_END Function
Allocate a stack frame for a leaf routine
The following example allocates a stack frame for a leaf routine that requires 40 bytes for local variables and temporaries. It uses permanent registers R8, R9, and R10. This routine has no alloca() locals, so no frame pointer is required.
NESTED_ENTRY Function mov.l R8, @-R15 mov.l R9, @-R15 mov.l R10, @-R15 add #-40, R15 PROLOG_END // Routine body add #40, R15 mov.l @R15+, R10 mov.l @R15+, R9 rts mov.l @R15+, R8 ENTRY_END Function
Allocate a stack frame with 64KB of memory
The following example allocates a stack frame that requires 64 KB of memory. It saves the argument register R4 to the incoming argument save area, and saves the argument register R5 to allocated register R8. No separate frame pointer is required. This example declares an exception handler.
EXCEPTION_HANDLER RoutineHandler NESTED_ENTRY Function mov.l R4, @R15 // Save argument to incoming argument save area. mov.l R8, @-R15 sts.l PR, @-R15 mov.l @(0x0000001C,pc),r1 // Load constant -65528. add r1,r15 // Allocate stack frame. mov.l R5, R8 // Save argument to register. PROLOG_END // Routine body mov.l @(0x0000000C,pc),r1 // Load constant 65528. add r1,r15 // Remove stack frame. lds.l @R15+, PR // Recover return address. rts mov.l @R15+, R8 // Restore R8. ENTRY_END Function
See Also
SH-3 Calling Sequence Specification | SH-3 Prolog and Epilog | SH-3 Prolog | SH-3 Epilog
Last updated on Thursday, April 08, 2004
© 1992-2003 Microsoft Corporation. All rights reserved.