x86 Assembly Language Reference Manual

Compare String Data (scas)

scas{bwl}
Operation

compare ES:[(E)DI] with [AL|AX|EAX]

Description

Compares the memory byte or word addressed in the destination register relative to the ES segment with the contents of the AL, AX, or EAX register. The result is discarded; only the flags are set.

Before executing the scas instruction, load the index values into the DI destination-index register. The destination operand must be addressable from the ES register; it cannot span segments.

After the data is transferred, the destination-index register is 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 search of CX or ECX bytes, words or longs, precede a scas instruction with a repz or repnz prefix.

Example

Compare the memory byte addressed in the destination register, relative to the ES segment, with the contents of the AL register.

scasb

Compare the memory word addressed in the destination register, relative to the ES segment, with the contents of the AX register

scasw

Compare the memory byte double-word addressed in the destination register, relative to the ES segment, with the contents of the EAX register

scasl