CMPS Compare Strings Flags: O D I T S Z A P C * - - - * * * * * CMPS source_string,destination_string
Logic CMP [DS:eSI],[ES:eDI] if DF = 0 eSI ← eSI + n ; n = 1 for byte, 2 for word, eDI ← eDI + n ; 4 for dword (386+) else eSI ← eSI - n eDI ← eDI - n endif
This instruction compares two values by subtracting the destination string element pointed to by ES:eDI, from the source string element pointed to by DS:eSI, and sets the flags according to the results of the comparison. The operands themselves are not altered. After the comparison, eSI and eDI are incremented (if the direction flag is cleared) or decremented (if the direction flag is set), in preparation for comparing the next element of the string. If the address-size attribute of CMPS is 16, the SI and DI registers will be used as source and destination indices, otherwise ESI and EDI.
The source segment can be changed with a segment override, the destination segment cannot.
Note: This instruction is always translated by the assembler into CMPSB, Compare String Byte, CMPSW, Compare String Word, or CMPSD, Compare String Dword, depending upon whether source refers to a string of bytes, words or doublewords. In either case, you must explicitly load the eSI and eDI registers with the offset of the source and destination strings.
CMPSB, CMPSW, and CMPSD are synonyms for the byte, word, and doubleword CMPS instructions that do not require any operands. They are simpler to use but provide no type or segment checking.
If the REPE or REPNE prefix modifies this instruction, the CPU compares the value of the destination string element to the value of the source string element. It then steps eSI and eDI in the direction indicated by DF by the indicated size, until either the REPE/REPNE condition is false or eCX counts to zero.