[<<Previous Entry]
[^^Up^^]
[Next Entry>>]
[Menu]
[About The Guide]
SCASB Scan String Byte Flags: O D I T S Z A P C
* * * * * *
SCASB
Logic: CMP AL, (ES:DI) ; Sets flags only
if DF = 0
DI . DI + 1
else
DI . DI - 1
This instruction compares two bytes by subtracting the destination
byte, pointed to by ES:DI, from AL. SCASB sets the flags according to
the results of the comparison. The operands themselves are not
altered. After the comparison, DI is incremented (if the direction
flag is cleared) or decremented (if the direction flag is set), in
preparation for comparing the next byte.
--------------------------------------------------------------------------
Operands Clocks Transfers Bytes Example
- 15 1 1 SCASB
(repeat) 9 + 15/rep 1/rep 1 REPNE SCASB
--------------------------------------------------------------------------
Notes: SCAS is useful for searching a block for a given
byte or word value. Use CMPS, Compare String, if you
wish to compare two strings (or blocks) in memory,
element by element.
-------------------------------- Example ---------------------------------
The following example searches the 100-byte block starting at LOST_A
for the character 'A' (65 decimal).
MOV AX, DS
MOV ES, AX ;SCAS uses ES:DI, so copy DS to ES
CLD ;Scan in the forward direction
MOV AL, 'A' ;Searching for the lost 'A'
MOV CX,100 ;Scanning 100 bytes (CX is used by REPNE)
LEA DI, LOST_A ;Starting address to DI
REPNE SCASB ; ...and scan it.
JE FOUND ;The Zero Flag will be set if we found
; a match.
NOTFOUND: . ;If we get here, no match was found
.
.
FOUND: DEC DI ;Back up DI so it points to the first
. ; matching 'A'
.
Upon exit from the REPNE SCASB loop, the Zero Flag will be set if a
match was found, and cleared otherwise. If a match was found, DI will
be pointing one byte past the match location; the DEC DI at FOUND
takes care of this problem.
See Also:
SCAS
SCASW
CMPS
REP
CLD
STD
Flags
This page created by ng2html v1.05, the Norton guide to HTML conversion utility.
Written by Dave Pearson