X86 memory segmentation

segmentsegmented memorymemory segmentsegment selectorsegmentation8086 segmentshardware instructionmemory segmentationparagraphsegment boundary
x86 memory segmentation refers to the implementation of memory segmentation in the Intel x86 computer instruction set architecture.wikipedia
84 Related Articles

X86

x86 architectureIntel x8680x86
x86 memory segmentation refers to the implementation of memory segmentation in the Intel x86 computer instruction set architecture.
The 8086 was introduced in 1978 as a fully 16-bit extension of Intel's 8-bit 8080 microprocessor, with memory segmentation as a solution for addressing more memory than can be covered by a plain 16-bit address.

Virtual 8086 mode

Virtual Mode Extensionsv86 modevirtual x86 mode
In real mode or V86 mode, the size of a segment can range from 1 byte up to 65,536 bytes (using 16-bit offsets).
VM86 mode uses a segmentation scheme identical to that of real mode (for compatibility reasons) which creates 20-bit linear addresses in the same manner as 20-bit physical addresses are created in real mode, but are subject to protected mode's memory paging mechanism.

Intel 8086

808680C86Intel-8086
Segmentation was introduced on the Intel 8086 in 1978 as a way to allow programs to address more than 64 KB (65,536 bytes) of memory.
There are also three 16-bit segment registers (see figure) that allow the 8086 CPU to access one megabyte of memory in an unusual way.

Memory segmentation

segmentationmemory segmentsegment
x86 memory segmentation refers to the implementation of memory segmentation in the Intel x86 computer instruction set architecture.
Intel x86 memory segmentation does not fit either model and is discussed separately below, and also in greater detail in a separate article.

X86-64

x64AMD64Intel 64
The x86-64 architecture, introduced in 2003, has largely dropped support for segmentation in 64-bit mode.

High memory area

HMAHMA, or High Memory Area
This roughly 64-kilobyte region of memory was known as the High Memory Area (HMA), and later versions of MS-DOS could use it to increase the available "conventional" memory (i.e. within the first MB).
In real mode, the segmentation architecture of the Intel 80286 and subsequent processors identifies memory locations with a 16-bit segment and a 16-bit offset, which is resolved into a physical address via (segment) x 16 + (offset).

Global Descriptor Table

Local Descriptor TableGDTLDT
When attempting address translation of a given logical address, the processor reads the 64-bit segment descriptor structure from either the Global Descriptor Table when TI=0 or the Local Descriptor Table when TI=1.
These memory areas are called segments in Intel terminology.

Memory address

addressaddressesmemory location
The effective 20-bit address space of real mode limits the addressable memory to 2 20 bytes, or 1,048,576 bytes (1 MB).
Early x86 computers use the segmented memory model addresses based on a combination of two numbers: a memory segment, and an offset within that segment.

X86 assembly language

x86 assemblyIntel syntaxassembly language
Logical addresses can be explicitly specified in x86 assembly language, e.g.
In protected mode, the segment selector can be broken down into three parts: a 13-bit index, a Table Indicator bit that determines whether the entry is in the GDT or LDT and a 2-bit Requested Privilege Level; see x86 memory segmentation.

Flat memory model

linear addressingLinear address spaceLinear
Segmentation cannot be turned off on x86-32 processors (this is true for 64-bit mode as well, but beyond the scope of discussion), so many 32-bit operating systems simulate a flat memory model by setting all segments' bases to 0 in order to make segmentation neutral to programs.

Instruction set architecture

instruction setinstructionsinstruction
x86 memory segmentation refers to the implementation of memory segmentation in the Intel x86 computer instruction set architecture.

Byte

bytesBTB
In real mode or V86 mode, the size of a segment can range from 1 byte up to 65,536 bytes (using 16-bit offsets). Segmentation was introduced on the Intel 8086 in 1978 as a way to allow programs to address more than 64 KB (65,536 bytes) of memory.

Intel 80286

80286286Intel 286
The Intel 80286 introduced a second version of segmentation in 1982 that added support for virtual memory and memory protection.

Virtual memory

virtual storagememoryswap
The Intel 80286 introduced a second version of segmentation in 1982 that added support for virtual memory and memory protection.

Memory protection

protected memorymemory protectedMemory protection key
The Intel 80286 introduced a second version of segmentation in 1982 that added support for virtual memory and memory protection.

Real mode

real-moderealmode1 MB addressable space
In real mode or V86 mode, the size of a segment can range from 1 byte up to 65,536 bytes (using 16-bit offsets). At this point the original model was renamed real mode, and the new version was named protected mode.

Protected mode

protected-mode16-bit protected mode286 protected mode
At this point the original model was renamed real mode, and the new version was named protected mode.

Code segment

code.textcode segment(.text)
In real mode, the registers CS, DS, SS, and ES point to the currently used program code segment (CS), the current data segment (DS), the current stack segment (SS), and one extra segment determined by the programmer (ES).

Data segment

rodata.data.rodata
In real mode, the registers CS, DS, SS, and ES point to the currently used program code segment (CS), the current data segment (DS), the current stack segment (SS), and one extra segment determined by the programmer (ES).

Intel 80386

80386i386386
The Intel 80386, introduced in 1985, adds two additional segment registers, FS and GS, with no specific uses defined by the hardware.

Physical address

addressbinary addressPhysical
The segment address is always added to a 16-bit offset in the instruction to yield a linear address, which is the same as physical address in this mode.

Hexadecimal

hex0x16
For instance, the segmented address 06EFh:1234h (here the suffix "h" means hexadecimal) has a segment selector of 06EFh, representing a segment address of 06EF0h, to which the offset is added, yielding the linear address 06EF0h + 1234h = 08124h.

Kilobyte

KBkilobytesK
While real mode segments are always 64 KB long, the practical effect is only that no segment can be longer than 64 KB, rather than that every segment must be 64 KB long.

Address space

addressaddressableaddressed
The effective 20-bit address space of real mode limits the addressable memory to 2 20 bytes, or 1,048,576 bytes (1 MB).

Megabyte

MBmegabytesMbyte
This roughly 64-kilobyte region of memory was known as the High Memory Area (HMA), and later versions of MS-DOS could use it to increase the available "conventional" memory (i.e. within the first MB). The effective 20-bit address space of real mode limits the addressable memory to 2 20 bytes, or 1,048,576 bytes (1 MB).