MIPS Frame Pointer Usage

Sep 05, 2006 2 Replies

I am an instructor at a large university, teaching a variety of computer architecture-related courses, including the standard Patterson-Hennessey MIPS text. For several semesters, I have been dancing around the question of exactly how, and by whom, the frame pointer ($fp, GPR 30) is managed. I understand its function, but I am at a loss to explain to inquisitive students exactly how its value gets set. Does the JAL instruction set it to $SP-4 automatically? Is it the responsibility of the author of a procedure to establish its value on entry?



If anyone can point me to an authoritative source on this question I would be very grateful.



Thanks



Justin Harlow



FP is usually not used at all by MIPS software. If it was used, the compiler would set it in the procedure prolog, after saving its previous value on the stack. It would then be restored before return. Nothing happens implicitly in the processor.

If you want to show FP logic to your students, x86 is a much better example, plus you can show the real compiler-generated code including FP handling.

The frame pointer is typically not used, if used it is generally set by the compiler at function entry. You can force the compiler to use the fp by using "alloca" (allocate memory on the stack) call in a function, in this case the compiler will use $fp to address the local variables allocated on the stack.

Sandeep

Join the Discussion

Have something to add? Share your thoughts — no account required.

Didn't find your answer?

Ask the community — no account required