IA-32 Assembly Language Reference Manual

Compare String Operands (cmps)

cmps{bwl}
Operation

compare DS:[(E)SI] with ES:[(E)DI]

Description

Compares the byte, word, or long in DS:[(E)SI] with the byte, word, or long in ES:[(E)DI}. Before executing the cmps instruction, load the index values into the SI source- and DI destination-index registers.

cmps subtracts the operand indexed by the destination-index from the operand indexed by the source-index register.

After the data is compared, both the source- and destination-index registers are automatically incremented or decremented as determined by the value of the direction flag (DF). The index registers are incremented if DF = 0 (DF cleared by a cld instruction); they are decremented if DF = 1 (DF set by a std instruction). The increment/decrement count is 1 for a byte move, 2 for a word, and 4 for a long.

For a block compare of CX or ECX bytes, words or longs, precede a cmps instruction with a repz or repnz prefix.

Example

Compare the 8-bit byte in the DS:[(E)SI] register to the ES:[(E)DI] register.

cmpsb

Compare the 16-bit word in the DS:[(E)SI] register to the ES:[(E)DI] register.

cmpsw

Compare the 32-bit word in the DS:[(E)SI] register to the ES:[(E)DI] register.

cmpsl