473,425 Members | 1,671 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,425 software developers and data experts.

stack pointer and frame pointer

Hi all,

What is the difference between stack pointer and frame pointer ?

Any suggestions are welcome ,,,

Oct 18 '06 #1
4 14783
In article <11**********************@f16g2000cwb.googlegroups .com>,
code break <pk*****@gmail.comwrote:
>What is the difference between stack pointer and frame pointer ?
The C language standard does not know anything about stacks
or frames. Stacks and frames are artifacts of particular implementations
and could differ between implementations.

[Off topic]

A stack pointer usually changes during the execution of any one
function, to hold temporary values or to hold variables whose
lifetime is only the scope of a block. For example,

int foo(void) {
int bar;
int totalbaz;
totalbaz = 0;
for (bar = 0; bar<10; bar++) {
int baz;
baz = 7*bar*bar*bar - 3*bar*bar + 2*bar + 5;
totalbaz += baz;
}
return totalbaz;
}

In this routine, baz only needs to exist within the for() loop,
so storage space for baz does not need to be allocated until the
for() loop starts executing, and the storage space could be released
at the end of the for() loop. baz would be a good candidate for being
allocated on a stack (in an implementation that used stacks.)
(Yes, it would be even better in a register, but the example can
be extended into something too large or complex to hold in registers.)
A frame pointer, on the other hand, usually points to the beginning
of the storage space allocated for any one function, and does not
change during the execution of that function. In the above example,
there could be a frame pointer pointing to a block of storage,
and at that block of storage there might be the address to return
to followed by the storage for totalbaz followed by the storage for bar --
so inside the for() loop, the compiler might refer to bar as being
a certain distance relative to the frame pointer. A frame pointer
usually points to the beginning of the fixed information about an
invocation of a function, The stack pointer -might- start from
the end of the fixed information for the frame, or the stack -might-
be somewhere else completely in memory... that's an implementation
decision. And some implementations don't use frame pointers at all.
--
Is there any thing whereof it may be said, See, this is new? It hath
been already of old time, which was before us. -- Ecclesiastes
Oct 18 '06 #2
code break wrote:
Hi all,

What is the difference between stack pointer and frame pointer ?

Any suggestions are welcome ,,,
A stack pointer is an index into a given stack frame.
A frame pointer represents a boundary of a stack frame.
This is architecture stuff, not C stuff.
Oct 18 '06 #3
"code break" <pk*****@gmail.comwrites:
What is the difference between stack pointer and frame pointer ?

Any suggestions are welcome ,,,
This is not a C question.

I suggest consulting a good book on computer architecture, or doing a
Google search, or posting to comp.arch (probably in that order).

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Oct 18 '06 #4
In article <G_sZg.1444$rS.1238@fed1read05>,
jmcgill <jm*****@email.arizona.eduwrote:
>code break wrote:
>What is the difference between stack pointer and frame pointer ?
>A stack pointer is an index into a given stack frame.
Sometimes. But it would be perfectly valid for an implementation
to allocate the maximum possible local variable space all in
a functions frame, and to have a stack that lives somewhere else
completely that is used for things such as passing parameters into
routines. The return address could be passed in a register,
and the function prolog could store it in the frame (or just keep
it in the register if the function was a leaf function); thus stacks
need not have any control information, and can be completely divorced
from frames (as long as functions are well-behaved about popping
values off of the stack.)
>A frame pointer represents a boundary of a stack frame.
Sometimes. As explored above, stacks and frames go together like
peanut butter and jam -- you might be accustomed to always putting
them together, but that's not the only way.
>This is architecture stuff, not C stuff.
"architecture" in the "software architecture" sense. The hardware
architecture limits or guides or optimizes intra-routine communications,
but stacks and frames are more usually artificats of the
ABI (Application Binary Interface) than of the hardware.
--
"It is important to remember that when it comes to law, computers
never make copies, only human beings make copies. Computers are given
commands, not permission. Only people can be given permission."
-- Brad Templeton
Oct 18 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: iceColdFire | last post by:
HI, I have a function as void f(int p) { return p++; } now I have created a function pointer as
19
by: Lucas Machado | last post by:
i'm doing some Linux Kernel hacking for a course i'm currently taking. there is a pointer to a struct (struct example_struct *ex_ptr) in a .c that i want to access in a system call. i defined a...
4
by: anonymous | last post by:
Thanks your reply. The article I read is from www.hakin9.org/en/attachments/stackoverflow_en.pdf. And you're right. I don't know it very clearly. And that's why I want to understand it; for it's...
2
by: bekz | last post by:
Hi All, I have written exploits for binaries with fixed stack frame pointer. But now a days most of the compliers generates instrutions with random stack frame pointer. And with injecting...
13
by: arnuld | last post by:
i see the use of pointers, from K&R2 but what is the use of: 1. "pointer to pointer": char c; char** ppc; 2. pointer to function:
2
by: rasmidas | last post by:
Hi, I am getting the following error while I am running my application. EXITING AddToEventLog() EXITING WriteNoDocProdEvent() EXITING SubstituteSummitMessages() EXITING dmgDocumentCreate ()...
3
by: Jack | last post by:
For the small code below: #include <iostream> using namespace std; int main() { char a1 = "string 1"; char a2 = "string 2"; char a3 = "string 3";
14
by: Brian | last post by:
Hello - I have been told that for extra efficiency we should always compile code with frame pointer ommited (-fomit-frame-pointer), also -pipe. What is the reason for this? Why does it make a...
17
by: Andrea Taverna (Tavs) | last post by:
Subject: Initialization of a const matrix implemented as pointer-to-pointer Hello everyone. I've got the following matrix definition in a source file static const char **a; I need it to...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.