TEMPLATE

RAM SEGMENTS

  • Stack: Local variables and function call management; grows downwards.

    • To easily visualize how the call stack grows in memory, imagine an icicle forming on a rooftop. The rooftop represents high memory addresses (e.g., 0xFFFFFF), while the tip of the icicle represents low memory addresses. As water drips and freezes, the icicle grows downward, extending farther from the roof. The stack behaves the same way: each new function call pushes (adds) a new stack frame downward (lower) in memory, toward lower addresses, just like an icicle lengthening toward its tip.

  • Heap: Dynamically allocated memory (e.g., via malloc); grows upwards.

  • .bss (block started by symbol - READ/WRITE): Stores uninitialized global/static variables (they get zero-initialized by OS).

  • .data (initialized data - READ/WRITE - NOT EXECUTABLE): Stores initialized global and static variables.

  • .text (code section - READ-ONLY - EXECUTABLE): Contains program instructions; usually at the lowest addresses.

X86: GCC METHOD

X64: NASM METHOD

X64: W/ FUNCTIONS

The ordering of section directives in my assembly source may differ from the conventional .data, .bss, .text layout typically used by others. This is intentional, as the arrangement serves purely as a visualization aid. Placing .bss, .data, and .text in a custom order helps me mentally associate each memory section with my own conceptual model of how a program is represented in memory. Although the assembler and linker ultimately determine the true physical layout, organizing the sections in a way that aligns with my personal understanding allows me to more clearly internalize how each region is defined, how they differ in purpose, and how they relate to one another within a process’s memory space. This approach enhances my comprehension while leaving the actual binary structure unchanged.

Last updated