CMPS COMPARE STRING CMPS

(BYTE OR WORD)

Operation:

Flags Affected:

(LSRC) - (RSRC)

AF, CF, OF, PF, SF, ZF

if (OF) = 0 then

 

(SI) +- (SI) + OELTA

 

(01) +- (01) + OELTA

 

else

 

(SI) +- (SI) - OELTA

 

(01) +- (01) - OELTA

 

Description:

eM PS destination-string, source-string

CMPS (Compare String) subtracts the destina- tion byte or word (addressed by DI) from the source byte or word (addressed by SI). CMPS affects the flags but does not alter either operand, updates SI and DI to point to the next string element and updates, AF, CF, OF, PF, SF and ZF to reflect the relationship of the destination element to the source element. For example, if a JG (Jump if Greater) instruction follows CMPS, the jump is taken if the des-

tination element is greater than the source element. If CMPS is prefixed with REPE or REPZ, the operation is interrupted as "com- pare while not end-of-string (CX not zero) and strings are equal (ZF = 1)." If CMPS is preceded by REPNE or REPNZ, the operation is interrupted as "compare while not end-of- string (CX not zero) and strings are not equal (ZF = 0)." Thus, CMPS can be used to find matching or differing string elements.

Encoding:

11010011wl

if w = 0 then LSRC = (SI), RSRC = (01), OELTA = 1

else LSRC = (SI) + 1:(SI), RSRC = (01) + 1:(01), OELTA = 2

CMPS Operands

Clocks·

Transfers

Bytes

CMPS Coding Examples

dest-string, source-string

22(30)

2

1

CMPSBUFF1, BUFF2

(repeat) dest-string, source-string

9+22(30)/rep

2/rep

1

REP COMPS 10, KEY

*b(w): where b denotes the number of clock cycles for byte operands and w denotes the number of clock cycles for word operands.

2-68

Page 103
Image 103
Intel 210200-002 manual Cmps Compare String Cmps Byte or Word, 11010011wl, EM PS destination-string, source-string, Rep