Share via


MIPSII Prolog Example

The following example shows how to construct a prolog for a MIPSII ISA.

  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>
    

    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 or written another way, the framereg added to the framepointer.

    .frame framereg (usually $29), framesize, returnreg (usually $31)
    
  4. The mask pseudo instruction marks the beginning of the register save area. Set a bit on in the bitmask for each general-purpose register saved. These bits are set 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.

    sw $31, framesize + frameoffset($29)      ; save return address
    sw reg, framesize + frameoffset-N($(29))   ; save integer register
    sdc1 reg, framesize + frameoffset -N($(29)) ; save float register
    

    Issue one of the previously mentioned for each register saved where N is four and incremented by four for each subsequent lower number register saved.

  6. Mark the end of the prolog.

    .prologue 0
    

    The minimum proper prolog for a leaf routine includes the .ent, entry label, .frame and .prologue. For a non-leaf routine, the minimum proper prolog includes all of the previously mentioned items with and saving of the return address register, ra($31).

See Also

MIPS Prolog | MIPS16 Prolog Example

 Last updated on Thursday, April 08, 2004

© 1992-2003 Microsoft Corporation. All rights reserved.