Memory Segment - Segment Register

> Computer System > Computer - Memory (Physical memory) > Memory - Segment

1 - About

The segment registers (CS, DS, SS, ES, FS, and GS) hold 16-bit segment selectors

To access a particular segment in memory, the segment selector for that segment must be present in the appropriate segment register.

Advertising

3 - Initialization by memory model

How segment registers are used depends on the type of memory management model that the operating system or executive is using.

3.1 - Flat

When using the flat (unsegmented) memory model, segment registers are loaded with segment selectors that point to overlapping segments, each of which begins at address 0 of the linear address space.

These overlapping segments then comprise the linear address space for the program.

Typically, two overlapping segments are defined:.

Overlapping Segment Value Data Type
The CS segment register code segment for code
All the other segment registers
(DS, SS, ES, FS, and GS)
data segment and
stack segment
for data and stacks

3.2 - Segmented

When using the segmented memory model, each segment register is ordinarily loaded with a different segment selector so that each segment register points to a different segment within the linear address space.

At any time, a program can thus access up to six segments that are mapped to the same linear address space.

To access a segment not pointed to by one of the segment registers, a program must first load the segment selector for the segment to be accessed into a segment register.

Each of the segment registers is associated with one of three types of storage:

Types of storage Segment Register
Program Data Type - Code DS register point to four code segments
Program Data Type - Data DS, ES, FS, and GS registers point to four data segments
Program Data Type - Stack SS register point to four stack segments
Advertising

4 - 64 bit

In 64-bit mode: CS, DS, ES, SS are treated as if each segment base is 0, regardless of the value of the associated segment descriptor base. This creates a flat address space for code, data, and stack. FS and GS are exceptions.

Both segment registers may be used as additional base registers in linear address calculations (in the addressing of local data and certain operating system data structures).

5 - Documentation / Reference