0

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.

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
  • Those numbers, 5000, and 50001 are not in the same ballpark. – Erik Eidt Apr 12 '23 at 01:55
  • There's no reason to think that the stack occurs immediately following the code; in many environments it is far past the code, with a gap of inaccessible memory in bettween. – Erik Eidt Apr 12 '23 at 01:57
  • See the following https://stackoverflow.com/questions/74650564/is-frame-pointer-necessary-for-riscv-assembly/74650674#74650674 – Erik Eidt Apr 12 '23 at 01:59
  • And also https://stackoverflow.com/questions/75942196/what-it-means-that-ebp-register-points-to-the-old-ebp/75943063#75943063 – Erik Eidt Apr 12 '23 at 01:59
  • 1
    What does this have to do with [python]? Are you looking at Python internals or backtraces? I removed the tag; if there's a reason it's relevant, add it back along with text in the question body that's Python-related. – Peter Cordes Apr 12 '23 at 01:59
  • 1
    A function, being written by a compiler or by an assembler programmer, knows if it needs a certain amount of space for its activation/invocation. It may still need more, but the frame is the sort of minimum amount it knows it needs. The frame is allocated on a runtime stack, which allows for recursion, meaning each invocation of the same function has its own stack storage, as you would expect for local variables in recursion. – Erik Eidt Apr 12 '23 at 02:17

1 Answers1

0

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.

rcgldr
  • 27,407
  • 3
  • 36
  • 61