background image

3-22 Vol. 1

BASIC EXECUTION ENVIRONMENT

When storing data in memory or loading data from memory, the DS segment default can be overridden to allow 
other segments to be accessed. Within an assembler, the segment override is generally handled with a colon “:” 
operator. For example, the following MOV instruction moves a value from register EAX into the segment pointed to 
by the ES register. The offset into the segment is contained in the EBX register:

MOV ES:[EBX], EAX;

At the machine level, a segment override is specified with a segment-override prefix, which is a byte placed at the 
beginning of an instruction. The following default segment selections cannot be overridden:

Instruction fetches must be made from the code segment.

Destination strings in string instructions must be stored in the data segment pointed to by the ES register.

Push and pop operations must always reference the SS segment.

Some instructions require a segment selector to be specified explicitly. In these cases, the 16-bit segment selector 
can be located in a memory location or in a 16-bit register. For example, the following MOV instruction moves a 
segment selector located in register BX into segment register DS:

MOV DS, BX

Segment selectors can also be specified explicitly as part of a 48-bit far pointer in memory. Here, the first double-
word in memory contains the offset and the next word contains the segment selector.

3.7.4.1  

Segmentation in 64-Bit Mode

In IA-32e mode, the effects of segmentation depend on whether the processor is running in compatibility mode or 
64-bit mode. In compatibility mode, segmentation functions just as it does in legacy IA-32 mode, using the 16-bit 
or 32-bit protected mode semantics described above.
In 64-bit mode, segmentation is generally (but not completely) disabled, creating a flat 64-bit linear-address 
space. The processor treats the segment base of CS, DS, ES, SS as zero, creating a linear address that is equal to 
the effective address. The exceptions are the FS and GS segments, whose segment registers (which hold the 
segment base) can be used as additional base registers in some linear address calculations.

3.7.5 

Specifying an Offset

The offset part of a memory address can be specified directly as a static value (called a displacement) or through 
an address computation made up of one or more of the following components:

Displacement — An 8-, 16-, or 32-bit value.

Base — The value in a general-purpose register.

Index — The value in a general-purpose register.

Scale factor — A value of 2, 4, or 8 that is multiplied by the index value.

Table 3-5.  Default Segment Selection Rules

Reference Type

Register Used Segment Used

Default Selection Rule

Instructions

CS

Code Segment

All instruction fetches.

Stack

SS

Stack Segment

All stack pushes and pops.

Any memory reference which uses the ESP or EBP register as a base 

register.

Local Data

DS

Data Segment

All data references, except when relative to stack or string destination.

Destination Strings ES

Data Segment 

pointed to with the 

ES register

Destination of string instructions.