Course contentsShow
← Computer Science
Lesson 1385 of 2,87231. Memory ManagementFree lesson

Segmentation in x86 Architecture

Examining real-world segmentation implementation in x86 processors including segment registers and descriptor tables.

Segmentation in x86 Architecture

What you'll learn: How real x86 processors implement segmentation using segment registers and descriptor tables.

How x86 Does Segmentation in Practice

While we've explored segmentation conceptually, x86 processors provide specific hardware to make it work. The CPU uses segment registers (CS, DS, SS, ES, FS, GS) that don't hold base addresses directly—they hold selectors that point into descriptor tables.

Think of it like a library: instead of storing entire books (segment details) in your pocket (registers), you carry library card numbers (selectors) that reference the actual books in the library catalog (descriptor tables).

The x86 Segmentation Components

Segment Registers

  • CS (Code Segment): points to executable code
  • DS (Data Segment): points to data
  • SS (Stack Segment): points to the stack
  • ES, FS, GS: extra segments for additional data

Descriptor Tables

The Global Descriptor Table (GDT) and Local Descriptor Table (LDT) store segment descriptors containing:

  • Base address (where the segment starts in physical memory)
  • Limit (segment size)
  • Access rights (read/write/execute permissions)
  • Privilege level (ring 0-3 for protection)

Address Translation Process

  1. Program uses a logical address: segment:offset
  2. Segment register holds a selector index
  3. CPU looks up the descriptor in GDT/LDT
  4. Retrieves base address and limit from descriptor
  5. Checks: offset < limit (protection)
  6. Computes physical address: base + offset

Modern x86-64 largely flattens segmentation (all segments cover full address space), relying more on paging, but the mechanism remains for backward compatibility.

Key Takeaway: x86 segmentation uses segment registers as indices into descriptor tables (GDT/LDT) that store the actual segment base, limit, and protection information—a hardware implementation that enables efficient address translation and memory protection.