Table of Contents

IronForgeCyber

Courses

Resources

Blog

Log In



IronForgeCyber

AboutPrivacyTerms

© 2026 IronForgeCyber. All rights reserved.

  1. courses
  2. asm-101
  3. memory
6 min read

Memory

Registers hold the handful of values a program is working on right now; everything else lives in memory. A running process sees one long, flat array of bytes, each with its own numeric address. Assembly reaches into that array constantly — loading values to work on, storing results back — so you need a mental map of how it is laid out and how multi-byte values sit inside it.

The Address Space

The operating system hands each process a range of addresses divided into regions, each with a purpose. Drawn in GDB's orientation — lowest address at the top, highest at the bottom:

0x400000 low .text your code (instructions) .data / .bss global variables heap malloc — grows toward higher addresses free space stack locals, return addresses — grows toward lower addresses 0x7fff… high

The stack and heap grow toward each other across the free space between them: the heap climbs into higher addresses as you malloc, and the stack descends into lower addresses as you call functions and allocate locals. This is the map the rest of the courses refer back to — the Binary Exploitation track lives almost entirely in the stack region.

Why does the code start at 0x400000?
That is the default load base the GNU linker gives a non-PIE x86-64 executable — an arbitrary-but-fixed convention written into its linker script (32-bit x86 used 0x08048000). The first page at 0x400000 holds the ELF header and program headers, so your .text is aligned up to the next page and the first instruction lands at 0x401000 — which is exactly why every break _start in this course stops there. Everything below 0x400000 is deliberately left unmapped, so dereferencing a NULL (or small) pointer faults instead of silently reading real memory.

These addresses are fixed only because we link with ld directly, producing a non-PIE binary. Most distribution binaries are PIE (position-independent) and the loader drops them at a randomized base on every run (ASLR) — a defense the Binary Exploitation course spends real effort defeating.

Endianness

When a multi-byte value is stored in memory, which byte comes first? x86 is little-endian: the least-significant byte is stored at the lowest address. Store the 32-bit value 0x12345678 and look at the individual bytes versus the whole word:

gdb
gef➤ break _startBreakpoint 1 at 0x401000gef➤ runBreakpoint 1, 0x0000000000401000 in _start ()gef➤ si0x0000000000401008 in _start ()gef➤ p/x $rax$1 = 0x402000gef➤ x/4xb $rax0x402000:       0x78    0x56    0x34    0x12gef➤ x/1xw $rax0x402000:       0x12345678gef➤ si0x000000000040100f in _start ()gef➤ p/x $rbx$2 = 0x12345678

x/4xb reads four bytes starting at the address and shows 0x78 0x56 0x34 0x12 — the value backwards, least-significant byte first. x/1xw reads the same four bytes as a word and shows 0x12345678, the right way round. The bytes really are reversed in memory; the CPU reassembles them when it reads the value. This trips everyone up the first time they stare at a hex dump of an address.

Addressing Modes

Instructions reach memory through an effective address built from up to four parts, written inside brackets:

nasm
[base + index*scale + displacement]
  • base — a register holding a starting address (e.g. rbx)
  • index — a register holding an element number (e.g. rcx)
  • scale — 1, 2, 4, or 8, the size of each element
  • displacement — a constant offset

Any part is optional, which gives you everything from a plain pointer to full array indexing:

nasm
1mov rax, [rbx]                 ; value at the address in rbx
2mov rax, [rbx + 8]             ; 8 bytes past it
3mov rax

Loading and Storing

Two instructions do the bulk of the work, and the difference between them matters:

  • mov moves data. mov rbx, [val] dereferences — it reads the bytes at that address and copies the value into rbx.
  • lea (load effective address) computes the address itself, without touching memory. lea rax, [val] puts the address of val into rax, not its contents.

You can see both in the session above: lea rax, [val] left the address in rax, while mov ebx, [val] pulled the value 0x12345678 into rbx. lea is the assembly equivalent of C's &, and it is also handy for quick arithmetic — lea rax, [rbx + rcx*4] computes rbx + rcx*4 in one instruction without ever reading memory.

A Closer Look: Sections

The regions above are the coarse view — what the kernel maps when it loads the program. Zoom in and each region is built from named sections that the linker laid down. readelf -S lists them all; here are the ones you will meet most often, grouped by the permissions they end up with:

SectionWhat it holdsPerms
.textmachine code — your instructionsr-x
.pltstubs that jump into shared-library functionsr-x
.init / .finicode that runs before main and after it returnsr-x
.rodataread-only constants: string literals, const globals, jump tablesr--
.datainitialized writable globals — C's int total = 42;rw-
.bsszero-initialized globals — C's int counter; — takes no file space, just a reserved sizerw-
.got / .got.pltruntime-resolved addresses of library functions and datarw-
.dynamicthe table the loader reads to wire up shared librariesrw-
.symtab / .strtab / .debug_*symbol names and debug info — not loaded into memory at runtime—

Two things are worth internalizing. First, sections with matching permissions are merged into one loadable segment — every r-x section becomes the single executable region in the map above, every rw- section becomes the writable one. That is why the coarse picture has a handful of regions while readelf -S shows dozens of sections. Second, .bss costs nothing on disk: an uninitialized global is stored as "reserve N zeroed bytes," so a program with a megabyte-sized zero array does not carry a megabyte of zeros around in its file.

The bare nasm programs in this course only ever produce .text and .data — .plt, .got, and the rest appear once you link against a library like libc. How those two sections cooperate to call a function whose address is not known until runtime is the subject of The GOT and PLT.

,
[
rbx
+
rcx
*
8
]
; the rcx-th 8-byte element of an array at rbx