SCASW
Usage: SCASW Modifies flags: AF CF OF PF SF ZF
Compares word value at EDI from the accumulator and sets the flags similar to a subtraction. EDI is incremented/decremented by 2 and the state of the Direction Flag. Use with REP prefixes.
Scan String
SCASB ; AE [8086]
SCASW ; o16 AF [8086]
SCASD ; o32 AF [386]
SCASB compares the byte in AL with the byte at EDI, and sets the flags accordingly. It then increments or decrements (depending on the direction flag: increments if the flag is clear, decrements if it is set) EDI.
SCASW and SCASD work in the same way, but they compare a word to AX or a doubleword to EAX instead of a byte to AL, and increment or decrement the addressing registers by 2 or 4 instead of 1.
The REPE and REPNE prefixes (equivalently, REPZ and REPNZ) may be used to repeat the instruction up to ECX times until the first unequal or equal byte is found.
Example:
mov edi SourcePointer
mov ecx MAX_POSSIBLE_LENGTH
mov ax 'AA'
repne scasw | je Found
; Not found = repeat
Found: