# STACK

## LIFO (Last In First Out)

Imagine that you have a stack of books on your desk. The books are stacked on top of each other in a certain order, with the bottom book being the first one you put on the stack and the top book being the last one you added.&#x20;

This is like a LIFO system, because **the last book you added** (the top one) **is the first one you can take off** the stack. So if you want to grab a book from the middle of the stack, you have to take off the top few books first and then you can reach the one you want.

the "top" of the stack is at the lowest memory address, and the "bottom" is at the highest memory address

```markdown
Segment | Address                          | Contents
--------|----------------------------------|------------------------------------------
Stack   |               ^                  | Local variables, function params
        |               |                  |
        | 0xaaaaaaaa (just an example)     |
        | ...                              |
        | +------------------------------+ | Each frame is specific to a procedure. 
        | |                              | | Each frame contains the local variables 
        | |           Frame 2            | | of the procedure, the return address, and
        | |                              | | a backup of the input parameters, or a 
        | +------------------------------+ | copy of certain registers.
        | +------------------------------+ | 
        | |                              | | The frame 1 normally corresponds to the
        | |           Frame 1            | | 'main' function.
        | |                              | |
        | +------------------------------+ |
        | 0xffffffff                       |
--------|----------------------------------|-----------------------------------------
```

##


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://www.ctfrecipes.com/pwn/general-knowledge/operation-of-the-stack.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
