1 <!DOCTYPE HTML PUBLIC
"-//IETF//DTD HTML 2.0//EN">
4 <TITLE>80386 Programmer's Reference Manual -- Opcode SCAS
</TITLE>
7 <B>up:
</B> <A HREF=
"c17.htm">
8 Chapter
17 --
80386 Instruction Set
</A><BR>
9 <B>prev:
</B><A HREF=
"SBB.htm"> SBB Integer Subtraction with Borrow
</A><BR>
10 <B>next:
</B><A HREF=
"SETcc.htm"> SETcc Byte Set on Condition
</A>
14 <H1>SCAS/SCASB/SCASW/SCASD -- Compare String Data
</H1>
17 Opcode Instruction Clocks Description
19 AE SCAS m8
7 Compare bytes AL-ES:[DI], update (E)DI
20 AF SCAS m16
7 Compare words AX-ES:[DI], update (E)DI
21 AF SCAS m32
7 Compare dwords EAX-ES:[DI], update (E)DI
22 AE SCASB
7 Compare bytes AL-ES:[DI], update (E)DI
23 AF SCASW
7 Compare words AX-ES:[DI], update (E)DI
24 AF SCASD
7 Compare dwords EAX-ES:[DI], update (E)DI
32 THEN use DI for dest-index;
33 ELSE (* AddressSize =
32 *) use EDI for dest-index;
35 IF byte type of instruction
37 AL - [dest-index]; (* Compare byte in AL and dest *)
38 IF DF =
0 THEN IndDec :=
1 ELSE IncDec := -
1; FI;
42 AX - [dest-index]; (* compare word in AL and dest *)
43 IF DF =
0 THEN IncDec :=
2 ELSE IncDec := -
2; FI;
44 ELSE (* OperandSize =
32 *)
45 EAX - [dest-index];(* compare dword in EAX & dest *)
46 IF DF =
0 THEN IncDec :=
4 ELSE IncDec := -
4; FI;
49 dest-index := dest-index + IncDec
54 SCAS subtracts the memory byte or word at the destination register from
55 the AL, AX or EAX register. The result is discarded; only the flags are set.
56 The operand must be addressable from the ES segment; no segment override is
59 If the address-size attribute for this instruction is
16 bits, DI is used
60 as the destination register; otherwise, the address-size attribute is
32
63 The address of the memory data being compared is determined solely by the
64 contents of the destination register, not by the operand to SCAS. The
65 operand validates ES segment addressability and determines the data type.
66 Load the correct index value into DI or EDI before executing SCAS.
68 After the comparison is made, the destination register is automatically
69 updated. If the direction flag is
0
70 (
<A HREF=
"CLD.htm">CLD
</A> was executed), the destination
71 register is incremented; if the direction flag is
1
72 (
<A HREF=
"STD.htm">STD
</A> was executed), it
73 is decremented. The increments or decrements are by
1 if bytes are compared,
74 by
2 if words are compared, or by
4 if doublewords are compared.
76 SCASB, SCASW, and SCASD are synonyms for the byte, word and
77 doubleword SCAS instructions that don't require operands. They are
78 simpler to code, but provide no type or segment checking.
80 SCAS can be preceded by the
81 <A HREF=
"REP.htm">REPE
</A> or
82 <A HREF=
"REP.htm">REPNE
</A> prefix for a block search
83 of CX or ECX bytes or words. Refer to the
84 <A HREF=
"REP.htm">REP
</A> instruction for further
87 <H2>Flags Affected
</H2>
89 OF, SF, ZF, AF, PF, and CF as described in
<A HREF=
"appc.htm">Appendix C
</A>
91 <H2>Protected Mode Exceptions
</H2>
93 #GP(
0) for an illegal memory operand effective address in the CS, DS,
94 ES, FS, or GS segments; #SS(
0) for an illegal address in the SS segment;
95 #PF(fault-code) for a page fault
97 <H2>Real Address Mode Exceptions
</H2>
99 Interrupt
13 if any part of the operand would lie outside of the effective
100 address space from
0 to
0FFFFH
102 <H2>Virtual
8086 Mode Exceptions
</H2>
104 Same exceptions as in Real Address Mode; #PF(fault-code) for a page
111 <B>up:
</B> <A HREF=
"c17.htm">
112 Chapter
17 --
80386 Instruction Set
</A><BR>
113 <B>prev:
</B><A HREF=
"SBB.htm"> SBB Integer Subtraction with Borrow
</A><BR>
114 <B>next:
</B><A HREF=
"SETcc.htm"> SETcc Byte Set on Condition
</A>