user21560229
user21560229

Reputation: 19

What is the frame pointer in the stack? What exactly is the frame? (stack in assembly)

So, heres how I interpet the stack, let me know what is wrong/right. This is for any sort of assembly.

So it goes:

Directives

Bytecode with instructions

A 'stack' of added bytes added to the end of the instructions (these are set to 0 if I recall correctly, doesnt matter)

With this stack, we have a stack pointer that will look at the exact point of the most recenetly pushed byte. Then we'll have a stack base that is the very bottom of the stack (this value never changes). So if the length of the instructions and directives is 5000 bytes, the stack base will be the 50001st byte. If the stack is an extra 2500 bytes, then the stack limit will be byte 7500.

Let me know if thats correct. Now for the question:

What exactly is the frame or frame pointer? I know a frame is a frame of the stack (so a specific portion of the stack), but that is really confusing to me. How is a frame set? why do we need one? Is the frame pointer the exact byte position of where that frame is? If so, how do we know how long it is?

I looked up a few articles on frames and frame pointers and got many confusing answers. Wondering if we could take about it in plain english, haha.

Upvotes: 0

Views: 1089

Answers (1)

rcgldr
rcgldr

Reputation: 28808

What exactly is the frame or frame pointer?

This is a convention commonly used by different tool sets. At function entry EBP|RBP is pushed onto the stack and then set to ESP|RSP, resulting in [ESP|RSP] containing the value of the calling function's EBP|RBP. In the case of nested functions, this creates a backwards chain of pointers to each function's stack, which is called a frame, and EBP|RBP would be considered to be the current frame pointer.

Note that some toolsets include an option to disable this usage of EBP|RBP, freeing it up to be used as a general purpose register, rather than as a frame pointer.

Upvotes: 0

Related Questions