Intel 64 and IA-32 Architectures Software Developers Manual Volume 2B, Instruction Set Reference, N-Z
4-286 Vol. 2B
INSTRUCTION SET REFERENCE, N-Z
SCAS/SCASB/SCASW/SCASD—Scan String
Description
In non-64-bit modes and in default 64-bit mode: this instruction compares a byte,
word, doubleword or quadword specified using a memory operand with the value in
AL, AX, or EAX. It then sets status flags in EFLAGS recording the results. The memory
operand address is read from ES:(E)DI register (depending on the address-size
attribute of the instruction and the current operational mode). Note that ES cannot
be overridden with a segment override prefix.
At the assembly-code level, two forms of this instruction are allowed. The explicit-
operand form and the no-operands form. The explicit-operand form (specified using
the SCAS mnemonic) allows a memory operand to be specified explicitly. The
memory operand must be a symbol that indicates the size and location of the
operand value. The register operand is then automatically selected to match the size
of the memory operand (AL register for byte comparisons, AX for word comparisons,
EAX for doubleword comparisons). The explicit-operand form is provided to allow
documentation. Note that the documentation provided by this form can be
misleading. That is, the memory operand symbol must specify the correct type (size)
of the operand (byte, word, or doubleword) but it does not have to specify the correct
location. The location is always specified by ES:(E)DI.
Opcode Instruction
64-Bit
Mode
Compat/
Leg Mode Description
AE SCAS m8 Valid Valid Compare AL with byte at ES:(E)DI or
RDI, then set status flags
1
.
NOTES:
1. In 64-bit mode, only 64-bit (RDI) and 32-bit (EDI) address sizes are supported. In non-64-bit mode,
only 32-bit (EDI) and 16-bit (DI) address sizes are supported.
AF SCAS m16 Valid Valid Compare AX with word at ES:(E)DI or
RDI, then set status flags.
a
AF SCAS m32 Valid Valid Compare EAX with doubleword at
ES(E)DI or RDI then set status flags.
a
REX.W + AF SCAS m64 Valid N.E. Compare RAX with quadword at RDI or
EDI then set status flags.
AE SCASB Valid Valid Compare AL with byte at ES:(E)DI or
RDI then set status flags.
a
AF SCASW Valid Valid Compare AX with word at ES:(E)DI or
RDI then set status flags.
a
AF SCASD Valid Valid Compare EAX with doubleword at
ES:(E)DI or RDI then set status flags.
a
REX.W + AF SCASQ Valid N.E. Compare RAX with quadword at RDI or
EDI then set status flags.