
Instruction Set
4-36
CMPS
CMPS B Compare S tring Bytes
CMPS W Compare S tring Words
Compare S tring Components
CMPS
What It Does
CMPS compares a component in one string to a component in another string.
S yntax
Desc ription
CMPS compares the byte or word pointed to by the SI register with the byte or word pointed
to by the DI register. You must preload the registers before executing CMPS.
CMPS subtracts the DI indexed operand from the SI indexed operand. No result is stored;
only the flags reflect the change. The operand size determines whether bytes or words are
compared. The first operand (SI) uses the DS register unless a segment override byte is
present. The second operand (DI) must be addressable from the ES register; no segment
override is possible. After the comparison, both the source-index register and the
destination-index register are automatically advanced. If DF is 0, the registers increment
according to the operand size (byte=1; word=2); if DF is 1, the registers decrement.
CMPSB and CMPSW are synonymous with the byte and word CMPS instructions,
respectively.
Form
Opcode
Description
Clocks
Am186 Am188
CMPS m8m8
A6
Compare byte ES:[DI] to byte segment:[SI]
22
22
CMPS m16m16
A7
Compare word ES:[DI] to word segment:[SI]
22
26
CMPSB
A6
Compare byte ES:[DI] to byte DS:[SI]
22
22
CMPSW
A7
Compare word ES:[DI] to word DS:[SI]
22
26
CMPS sourcedestination
CMPSB
CMPSW
To override the default source
segment (DS) and to have the
assembler type-check your operands,
use this form. In this form, source is
segment:[SI]. The assembler uses he
segment in DS unless you specify a
different segment register as part of
the source string component. The
assembler uses the definitions of the
string components to determine their
sizes.
Regardless of the form of CMPS
you use, destination is always
ES:[DI]. Before using any orm of
CMPS, make sure that: ES
contains the segment of the
destination string, DI contains
the offset of the destination
string, and SI contains the offset
of the source string.
To compare a byte within a string
located in the destination segment
specified n ES to a byte within a string
located in the source segment
specified in DS, use this form.
To compare a word within a string
located in the destination segment
specified n ES o a word within a string
located in the source segment
specified in DS, use this form.