User Guide

General-Purpose Programming 73
24592—Rev. 3.15—November 2009 AMD64 Technology
Segment Override Prefix. The DS segment is the default segment for most memory operands. Many
instructions allow this default data segment to be overridden using one of the six segment-override
prefixes shown in Table 3-7 on page 72. Data-segment overrides will be ignored when accessing data
in the following cases:
When a stack reference is made that pushes data onto or pops data off of the stack. In those cases,
the SS segment is always used.
When the destination of a string is memory it is always referenced using the ES segment.
Instruction fetches from the CS segment cannot be overridden. However, the CS segment-override
prefix can be used to access instructions as data objects and to access data stored in the code segment.
For further details on these prefixes, see “Segment-Override Prefixes” in Volume 3.
Lock Prefix. The LOCK prefix causes certain read-modify-write instructions that access memory to
occur atomically. The mechanism for doing so is implementation-dependent (for example, the
mechanism may involve locking of data-cache lines that contain copies of the referenced memory
operands, and/or bus signaling or packet-messaging on the bus). The prefix is intended to give the
processor exclusive use of shared memory operands in a multiprocessor system.
The prefix can only be used with forms of the following instructions that write a memory operand:
ADC, ADD, AND, BTC, BTR, BTS, CMPXCHG, CMPXCHG8B, DEC, INC, NEG, NOT, OR, SBB,
SUB, XADD, XCHG, and XOR. An invalid-opcode exception occurs if LOCK is used with any other
instruction.
For further details on these prefixes, see “Lock Prefix” in Volume 3.
Repeat Prefixes. There are two repeat prefixes byte codes, F3h and F2h. Byte code F3h is the more
general and is usually treated as two distinct instructions by assemblers. Byte code F2h is only used
with CMPSx and SCASx instructions:
REP (F3h)—This more generalized repeat prefix repeats its associated string instruction the
number of times specified in the counter register (rCX). Repetition stops when the value in rCX
reaches 0. This prefix is used with the INS, LODS, MOVS, OUTS, and STOS instructions.
REPE or REPZ (F3h)—This version of REP prefix repeats its associated string instruction the
number of times specified in the counter register (rCX). Repetition stops when the value in rCX
reaches 0 or when the zero flag (ZF) is cleared to 0. The prefix can only be used with the CMPSx
and SCASx instructions.
REPNE or REPNZ (F2h)—The REPNE or REPNZ prefix repeats its associated string instruction
the number of times specified in the counter register (rCX). Repetition stops when the value in rCX
reaches 0 or when the zero flag (ZF) is set to 1. The prefix can only be used with the CMPSx and
SCASx instructions.
The size of the rCX counter is determined by the effective address size. For further details about these
prefixes, including optimization of their use, see “Repeat Prefixes” in Volume 3.