5
$\begingroup$

I am currently learning assembly programming on wombat 4, I am looking at Frame pointers. I understand exactly what a frame pointer is: it is a register and are used to access parameters on a stack. But i'm confused on how they affect the program counter and why they are preferred over normal registers.

Could some one explain, please.

$\endgroup$
  • 1
    $\begingroup$ As not everybody knows Wombats as something to program with, please include a link to the systems documentation. $\endgroup$ – uli May 5 '12 at 8:56
  • $\begingroup$ hahaha! I should have worded that better i should have said programming in CPUSIM en.wikipedia.org/wiki/CPU_Sim $\endgroup$ – Xabi May 5 '12 at 9:04
  • $\begingroup$ In the docs I haven’t found an example of the frame pointer use. Can you please give a detailed example where the program counter is affected by the usage of a frame pointer, other than picking the function’s return adress from the stack? $\endgroup$ – uli May 5 '12 at 9:12
8
$\begingroup$

As the stack pointer may change while a function is executed, access to the stack is less confusing with a static frame pointer, that is set upon the entry to the function, so relative addressing becomes simpler.

On reason for using the stack to store parameters is that there is usually more memory available than registers. What would you do with a function g(a,b,c,d,e,f) where you have enough registers free to store a–e, but non for f? You would put f on the stack. As the size of the stack is only limited by the available memory using the stack still works for functions with even more parameters.

Modern compilers typically have a flag that controls whether the use of registers for parameter passing is allowed or not.

$\endgroup$
  • $\begingroup$ One addition/clarification: if our stack grows upwards, the stack pointer points always to the top, the is the place where new temporary values can be stored. The frame pointer points always to the first entry of the current frame, which allows to access local variables with a constant offset (that is known to the compiler). $\endgroup$ – Raphael May 10 '12 at 13:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.