Intel 253666-024US Computer Hardware User Manual


 
3-138 Vol. 2A CMPS/CMPSB/CMPSW/CMPSD/CMPSQ—Compare String Operands
INSTRUCTION SET REFERENCE, A-M
RDI) registers are assumed by the processor to specify the location of the source
operands. The size of the source operands is selected with the mnemonic: CMPSB
(byte comparison), CMPSW (word comparison), CMPSD (doubleword comparison),
or CMPSQ (quadword comparison using REX.W).
After the comparison, the (E/R)SI and (E/R)DI registers increment or decrement
automatically according to the setting of the DF flag in the EFLAGS register. (If the DF
flag is 0, the (E/R)SI and (E/R)DI register increment; if the DF flag is 1, the registers
decrement.) The registers increment or decrement by 1 for byte operations, by 2 for
word operations, 4 for doubleword operations. If operand size is 64, RSI and RDI
registers increment by 8 for quadword operations.
The CMPS, CMPSB, CMPSW, CMPSD, and CMPSQ instructions can be preceded by the
REP prefix for block comparisons. More often, however, these instructions will be
used in a LOOP construct that takes some action based on the setting of the status
flags before the next comparison is made. See
“REP/REPE/REPZ/REPNE/REPNZ—Repeat String Operation Prefix” in Chapter 4, in
the Intel® 64 and IA-32 Architectures Software Developer’s Manual, Volume 2B, for
a description of the REP prefix.
In 64-bit mode, the instruction’s default address size is 64 bits, 32 bit address size is
supported using the prefix 67H. Use of the REX.W prefix promotes doubleword oper-
ation to 64 bits (see CMPSQ
). See the summary chart at the beginning of this section
for encoding data and limits.
Operation
temp SRC1 - SRC2;
SetStatusFlags(temp);
IF (64-Bit Mode)
THEN
IF (Byte comparison)
THEN IF DF
= 0
THEN
(R|E)SI (R|E)SI + 1;
(R|E)DI (R|E)DI + 1;
ELSE
(R|E)SI (R|E)SI – 1;
(R|E)DI (R|E)DI – 1;
FI;
ELSE IF (Word comparison)
THEN IF DF
= 0
THEN
(R|E)SI (R|E)SI + 2;
(R|E)DI (R|E)DI + 2;
ELSE
(R|E)SI (R|E)SI – 2;