Intel 253666-024US Computer Hardware User Manual


 
Vol. 2A 3-137
INSTRUCTION SET REFERENCE, A-M
CMPS/CMPSB/CMPSW/CMPSD/CMPSQ—Compare String Operands
Description
Compares the byte, word, doubleword, or quadword specified with the first source
operand with the byte, word, doubleword, or quadword specified with the second
source operand and sets the status flags in the EFLAGS register according to the
results.
Both source operands are located in memory. The address of the first source operand
is read from DS:SI, DS:ESI or RSI (depending on the address-size attribute of the
instruction is 16, 32, or 64, respectively). The address of the second source operand
is read from ES:DI, ES:EDI or RDI (again depending on the address-size attribute of
the instruction is 16, 32, or 64). The DS segment may be overridden with a segment
override prefix, but the ES segment cannot be overridden.
At the assembly-code level, two forms of this instruction are allowed: the “explicit-
operands” form and the “no-operands” form. The explicit-operands form (specified
with the CMPS mnemonic) allows the two source operands to be specified explicitly.
Here, the source operands should be symbols that indicate the size and location of
the source values. This explicit-operand form is provided to allow documentation.
However, note that the documentation provided by this form can be misleading. That
is, the source operand symbols must specify the correct type (size) of the operands
(bytes, words, or doublewords, quadwords), but they do not have to specify the
correct location. Locations of the source operands are always specified by the
DS:(E)SI (or RSI) and ES:(E)DI (or RDI) registers, which must be loaded correctly
before the compare string instruction is executed.
The no-operands form provides “short forms” of the byte, word, and doubleword
versions of the CMPS instructions. Here also the DS:(E)SI (or RSI) and ES:(E)DI (or
Opcode Instruction 64-Bit
Mode
Compat/
Leg Mode
Description
A7 CMPSW Valid Valid For legacy mode, compare word at
address DS:(E)SI with word at
address ES:(E)DI; For 64-bit mode
compare word at address (R|E)SI
with word at address (R|E)DI. The
status flags are set accordingly.
A7 CMPSD Valid Valid For legacy mode, compare dword
at address DS:(E)SI with dword at
address ES:(E)DI; For 64-bit mode
compare dword at address (R|E)SI
with dword at address (R|E)DI. The
status flags are set accordingly.
REX.W + A7 CMPSQ Valid N.E. Compares quadword at address
(R|E)SI with quadword at address
(R|E)DI and sets the status flags
accordingly.