5-8
DATA TYPES AND ADDRESSING MODES
5.3.3.1.SPECIFYING A SEGMENT SELECTOR
The segment selector can be specified either implicitly or explicitly. The most common method
of specifying a segment selector is to load it in a segment register and then allow the processor
to select the register implicitly, depending on the type of operation being performed. The
processor automatically chooses a segment according to the rules given in Table 5-1.
When storing data in 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 doubleword in memory contains the offset and the next word contains the segment
selector.
Table 5-1. Default Segment Selection Rules
Type of
Reference
Register
Used
Segment
Used
Default Selection Rule
Instructions
CSCode SegmentAll instruction fetches.
Stack
SSStack SegmentAll stack pushes and pops.
Any memory reference which uses the ESP or EBP
register as a base register.
Local Data
DSData SegmentAll data references, except when relative to stack or
string destination.
Destination
Strings
ESData Segment
pointed to with
the ES register
Destination of string instructions.