3-8
BASIC EXECUTION ENVIRONMENT
in memory, the segment selector for that segment must be present in the appropriate segment
register.
When writing application code, programmers generally create segment selectors with assembler
directives and symbols. The assembler and other tools then create the actual segment selector
values associated with these directives and symbols. If writing system code, programmers may
need to create segment selectors directly. (A detailed description of the segment-selector data
structure is given in Chapter 3, Protected-Mode Memory Management, of the Intel Architecture
Software Developers Manual, Volume 3.)
How segment registers are used depends on the type of memory management model that the
operating system or executive is using. When using the flat (unsegmented) memory model, the
segment registers are loaded with segment selectors that point to overlapping segments, each of
which begins at address 0 of the linear address space (as shown in Figure 3-5). These overlap-
ping segments then comprise the linear address space for the program. (Typically, two overlap-
ping segments are defined: one for code and another for data and stacks. The CS segment
register points to the code segment and all the other segment registers point to the data and stack
segment.)
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 (as shown in Figure 3-6). At any time, a program can thus access up to six
segments in the 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.
Figure 3-5. Use of Segment Registers for Flat Memory Model
Segment Registers
CS
SS
DS
ES
FS
GS
Linear Address
Space for Program
The segment selector in
each segment register
points to an overlapping
Overlapping
Segments
of up to
4G Bytes
segment in the linear
address space.
Beginning at
Address 0