Partager via


SH-4 Prolog and Epilog Examples (Windows Embedded CE 6.0)

1/5/2010

The following code examples show how to use prolog and epilog to perform certain tasks.

  • Allocate a stack frame to save R14, R8, and PR
    This example allocates a stack frame to save R14, R8, and PR, and to allow alloca() calls. It also allocates a 4-word argument build area. Local variables and temporaries do not need stack space.

    // Prolog
    
    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
    
    
    // Epilog
    
    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
    This 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.

    //  Prolog
    
    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
    

See Also

Reference

SH-4 Assembler Macros

Other Resources

Renesas SH-4 Prolog and Epilog