CMPSB Compare String Byte Flags: O D I T S Z A P C
Logic: CMP (DS:SI), (ES:DI) ; Sets flags only
This instruction compares two values by subtracting the byte pointed
to by ES:DI, from the byte pointed to by DS:SI, and sets the flags
according to the results of the comparison. The operands themselves
are not altered. After the comparison, SI and DI 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.
Operands Clocks Transfers Bytes Example
(repeat) 9 + 22/rep 2/rep 1 REPE CMPSB
The following example compares BUFFER1 against BUFFER2 for the first
cld ;Scan in the forward direction
mov cx, 100 ;Scanning 100 bytes (CX is used by REPE)
lea si, buffer1 ;Starting address of first buffer
lea di, buffer2 ;Starting address of second buffer
repe cmpsb ; ...and compare it.
jne mismatch ;The Zero Flag will be cleared if there
match: . ;If we get here, buffers match
dec si ;If we get here, we found a mismatch.
dec di ;Back up SI and DI so they point to the
Upon exit from the REPE CMPSB loop, the Zero Flag will be cleared if a
mismatch was found, and set otherwise. If a mismatch was found, DI and
SI will be pointing one byte past the byte that didn't match; the DEC
DI and DEC SI instructions backup these registers so they point to the