Assembly Language Help (alang.hlp) (
Table of Contents;
Topic list)
Important Notice
The pages on this site contain documentation for very old MS-DOS software,
purely for historical purposes.
If you're looking for up-to-date documentation, particularly for programming,
you should not rely on the information found here, as it will be woefully
out of date.
CMPS Instruction
◄Detail► ◄Key► ◄Example► ◄Up► ◄Contents► ◄Index► ◄Back►
────────────────────────────────────────────────────────────────────────────
Title: Compare String Flags: O D I T S Z A P C
═════════════════
Syntax: CMPS dest,src ± ± ± ± ± ±
CMPSB
CMPSW
CMPSD (80386/486 Only)
See also: REPE, SCAS, JCXZ, CLD, CMP
Description:
Compares two strings. DS:SI must point to the source string and
ES:DI must point to the destination string (even if operands are
given). For each comparison, the destination element is subtracted
from the source element and the flags are updated to reflect the
result (although the result is not stored).
DI and SI are adjusted according to the size of the operands and
the status of the direction flag. They are increased if the
direction flag has been cleared with CLD, or decreased if the
direction flag has been set with STD.
If the CMPS form of the instruction is used, operands must be
provided to indicate the size of the data elements to be
processed. A segment override can be given for the source (but not
for the destination). If CMPSB (bytes), CMPSW (words), or CMPSD
(doublewords) is used, the instruction determines the size of the
data elements to be processed.
CMPS and its variations are normally used with repeat prefixes:
REPNE (or REPNZ) finds the first match between two strings; REPE
(or REPZ) finds the first mismatch.
Before the comparison, CX should contain the maximum number of
elements to compare. After a REPNE CMPS, the zero flag is
clear if no match was found. After REPE CMPS, the zero flag
is set if no mismatch was found. Otherwise, SI and DI will
point to the element after the first match or nonmatch.
When the instruction finishes, ES:DI and DS:SI point to the
element that follows (if the direction flag is clear) or
precedes (if the direction flag is set) the match or mismatch.
If CX decrements to 0, ES:DI and DS:SI point to the element
that follows or precedes the last comparison. The zero flag is
set or clear according to the result of the last comparison, not
according to the value of CX.
-♦-