3-88
INSTRUCTION SET REFERENCE
CMPS/CMPSB/CMPSW/CMPSDCompare String Operands
(Continued)
After the comparison, the (E)SI and (E)DI registers are incremented or decremented automati-
cally according to the setting of the DF flag in the EFLAGS register. (If the DF flag is 0, the
(E)SI and (E)DI register are incremented; if the DF flag is 1, the (E)SI and (E)DI registers are
decremented.) The registers are incremented or decremented by one for byte operations, by two
for word operations, or by four for doubleword operations.
The CMPS, CMPSB, CMPSW, and CMPSD instructions can be preceded by the REP prefix for
block comparisons of ECX bytes, words, or doublewords. More often, however, these instruc-
tions 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. Refer to REP/REPE/REPZ/REPNE
/REPNZRepeat String Operation Prefix in this chapter for a description of the REP prefix.
Operation
temp
<
SRC1
?
SRC2;
SetStatusFlags(temp);
IF (byte comparison)
THEN IF DF = 0
THEN
(E)SI
<
(E)SI + 1;
(E)DI
<
(E)DI + 1;
ELSE
(E)SI
<
(E)SI 1;
(E)DI
<
(E)DI 1;
FI;
ELSE IF (word comparison)
THEN IF DF = 0
(E)SI
<
(E)SI + 2;
(E)DI
<
(E)DI + 2;
ELSE
(E)SI
<
(E)SI 2;
(E)DI
<
(E)DI 2;
FI;
ELSE (* doubleword comparison*)
THEN IF DF = 0
(E)SI
<
(E)SI + 4;
(E)DI
<
(E)DI + 4;
ELSE
(E)SI
<
(E)SI 4;
(E)DI
<
(E)DI 4;
FI;
FI;