PREV UP next StackThreads/MP: version 0.77 User's Guide

3.6.4: Stack Pointers and Frame Pointers

        void * asm_get_fp()
@        void * asm_get_sp()
@        void * asm_get_gp()

asm_get_fp() returns the frame pointer, asm_get_sp() the stack pointer. On machines that have a global register, asm_get_gp() returns the value of the global register. On machines that do not have a global register, asm_get_gp() is not available. Every procedure returns the value visible to the calling procedure. For example, when a procedure f calls asm_get_fp(), it returns the value of the frame pointer register when f is running.

When a procedure calls asm_get_fp() and asm_get_sp(), you may be surprised at their values; in StackThreads/MP execution, the frame pointer register always points to the running frame, whereas the stack pointer register always points to the stack top of the worker. These two values do not significantly differ in sequential execution, because both point to the frame allocated at the stack top. In StackThreads/MP, however, a running frame may not be on the stack top and may be far away from the stack top. It may even be another worker's stack.

Also, when a procedure calls asm_get_sp() several times, it may return different values each time. This is also because other frames may be above the running frame. The value of asm_get_fp(), on the other hand, returns the same value, as long as they are called from the same procedure. The returned value thus serves as the identifier of the procedure call.