STACK

The stack is a data structure that operates as a last-in-first-out (LIFO) structure

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.

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

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                       |
--------|----------------------------------|-----------------------------------------

Last updated