Share via


MIPS Prolog (Windows CE 5.0)

Send Feedback

The MIPS prolog has several immediately contiguous parts, regardless of whether MIPS 16-bit mode, MIPS 32-bit mode, or MIPS 64-bit mode is in force.

The following steps show the required elements of a MIPS prolog.

The code examples shown apply to MIPSII. For MIPS IV, replace the sw instruction with sd, and replace the lw instruction with ld.

  1. Define the prolog and set up the entry.

    .ent <routine_name>
    <routine_name>:
    
  2. Reserve space for the stack frame.

    Addiu sp, -<frame size>
    

    An extended addiu instruction of four bytes is generated for frame sizes greater than 1024. You can accommodate frame sizes up to 32768 bytes using the addiu instruction. If the frame size exceeds 32768, update the stack pointer with a constant from the literal pool using the following sequence of instructions.

    hw  $3, <frame size> constant offset(pc)
    move  $2, $29
    subu  $2, $2, $3
    move  $29, $2
    

    The size of the stack frame must be a multiple of eight. This includes space for local variables and temporaries, saved registers, and a procedure call argument area for non-leaf routines.

    Any routine that uses registers $16-$23, or $30, or any floating-point register that the called function saves, must save these registers.

    The procedure call argument area is set up so that it contains the maximum number of bytes required for the arguments of any procedure called in a non-leaf routine. This number of required bytes includes those arguments that the function can pass in registers, unless the N32 calling convention is in use.

  3. Set up a virtual frame pointer. The virtual frame pointer is the sp($29) added to the frame size.

    .frame framereg (usually $29), framesize, returnreg (usually $31)
    
  4. Set a bit in the bitmask for each general-purpose register saved. Set bits in little endian order. The frame offset is the offset, a negative number, from the virtual frame pointer where the register save area begins.

    .mask mask, <frame offset>
    
  5. Store any registers that need to be saved.

    For example, if the **Return Address (RA)**needs to be saved:

    sw ra, <frame size> + <frame offset>(sp)
    

    If subsequent lower number registers need to be saved, the offset depends on the MIPS mode. If the next register is a MIPS16 register,

    sw  $<mips16 register>, <frame size> + <frame offset> - n(sp)
    

    Otherwise

    move  $2, <mipsii register>
    sw  $2, <frame size> + <frame offset> - n(sp)
    

    Where N is four and is incremented by four for each subsequent lower number register to be saved.

    If <frame size> + <frame offset> greater than 1020, an extended sw instruction is generated. If the <frame size> + <frame offset> is greater than 32767, then the following 3 instruction sequence is required before executing the register save loop:

    lw  $2, <frame size> + <frame offset>constant offset(pc)
    move  $2, $29
    addu  $3, $2, $3
    

    The sw instructions depend on the mode of the MIPS register. If the next register is a MIPS16 register:

    sw  $<mips16 register>, -n($3)
    

    Otherwise

    move  $2,$<mipsii register>
    sw  $2, -n($3)
    
  6. Mark the end of the prolog.

    .prologue 0
    

See Also

MIPS Prolog and Epilog

Send Feedback on this topic to the authors

Feedback FAQs

© 2006 Microsoft Corporation. All rights reserved.