Lesson 6 / 10
Module 3Lesson 1⏱ 55 min study

Lesson 6: x86/x64 Architecture, Memory Layout & Stack Mechanics

Deconstruct the Intel x86 CPU architecture, general and special-purpose registers, the process memory hierarchy, and the call/return stack lifecycle.

✦ Key Architectural Takeaways
  • •A 32-bit x86 architecture addresses 4 GB of virtual memory (0x00000000 to 0xFFFFFFFF), split between user space and kernel space.
  • •The Stack grows downwards from high memory addresses to low memory addresses, while the Heap grows upwards towards high memory.
  • •The Extended Instruction Pointer (EIP) dictates CPU execution flow: whatever 32-bit memory address resides in EIP will be fetched and executed next.
  • •The Extended Stack Pointer (ESP) always points to the top of the stack, while the Base Pointer (EBP) anchors the current function's local stack frame.
  • •Intel x86 CPUs use Little-Endian byte ordering: the least significant byte is stored at the lowest memory address.

1. Process Virtual Memory Architecture

When an executable binary (e.g., a Windows Portable Executable .exe or Linux ELF) is loaded into memory, the operating system creates an isolated virtual address space.

In 32-bit x86 systems, this virtual address space spans 2^{32} bytes (4 GB), ranging from 0x00000000 to 0xFFFFFFFF:

ARCHITECTURE DIAGRAMSYSTEM SCHEMATIC
High Memory Addresses (0xFFFFFFFF)
+-------------------------------------------------------------+
| Kernel Space (Operating System Drivers & Core Subsystems)   |
+-------------------------------------------------------------+
| User Space Stack (Grows DOWNWARD towards low memory \/)     |
| [ Local Variables | Saved EBP | Saved EIP Return Address ] |
+-------------------------------------------------------------+
|                          |                                  |
|                          v                                  |
|                   Unallocated Memory                        |
|                          ^                                  |
|                          |                                  |
+-------------------------------------------------------------+
| Heap (Grows UPWARD /\ - Dynamic allocations: malloc / new) |
+-------------------------------------------------------------+
| .bss Segment (Uninitialized Global / Static Variables)      |
+-------------------------------------------------------------+
| .data Segment (Initialized Global / Static Variables)       |
+-------------------------------------------------------------+
| .text Segment (Compiled Machine Code Assembly Instructions) |
+-------------------------------------------------------------+
Low Memory Addresses (0x00000000)
§

2. Intel x86 CPU Register Hierarchy

Registers are microscopic, ultra-high-speed memory cells positioned directly on the CPU die:

x86 Register Architecture Matrix:

Register NameFunctional PurposeRole in Exploit Engineering
EAXAccumulator RegisterHolds function return values and arithmetic results
EBXBase RegisterPointer to data in the DS segment; general storage
ECXCounter RegisterLoop iteration counter and string operation counter
EDXData RegisterI/O pointer and arithmetic overflow operations
ESPExtended Stack PointerCritical: Points directly to the current top of the stack
EBPExtended Base PointerCritical: Anchors the base frame for local function variables
EIPExtended Instruction PointerHoly Grail: Points to the next instruction to execute!
§

3. Little-Endian Byte Ordering

Intel x86 microprocessors store multi-byte data words in memory using Little-Endian format: the least significant byte (LSB) is stored at the lowest memory address:

ARCHITECTURE DIAGRAMSYSTEM SCHEMATIC
Memory Address:  0x0012FF40   0x0012FF41   0x0012FF42   0x0012FF43
Memory Bytes:       [ 78 ]       [ 56 ]       [ 34 ]       [ 12 ]

Interpreted 32-bit Value: 0x12345678

When constructing exploit payloads targeting a specific memory address (e.g., targeting a JMP ESP instruction located at 0x625011AF), the payload in Python must reverse the byte order: b"\xaf\x11\x50\x62"!