Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- iAPx86 - <b>scas scan string flags: o d i t s z a p c</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
SCAS            Scan String                          Flags: O D I T S Z A P C
                                                            * - - - * * * * *
SCAS destination_string

        Logic   CMP accumulator,[ES:eDI]
                if DF = 0
                   eDI . eDI + n        ; n = 1 for byte, 2 for word,
                else                    ;     4 for dword (386+)
                   eDI . eDI - n
                endif

    This instruction compares the contents of the AL, AX, or EAX
    register with the memory byte, word, or doubleword pointed to by
    ES and the destination-index register (DI or EDI). After the
    comparison, eDI is automatically incremented (if the direction
    flag is cleared) or decremented (if the direction flag is set), in
    preparation for comparing the next element of the string.

    If the address-size attribute of SCAS is 16 bits, DI is used for
    the destination-index register; otherwise the the address-size
    attribute is 32 bits, and the EDI register will be used.

    The destination segment must be addressable from the ES register;
    it cannot be changed with a segment override.


    Note:       This instruction is always translated by the
                assembler into SCASB, Scan String Byte, SCASW, Scan
                String Word, or SCASD, Scan String Dword, depending
                upon whether destination refers to a string of bytes,
                words or doublewords. In either case, you must
                explicitly load the eDI register with the offset of
                the destination string.

                SCASB, SCASW, and SCASD are synonyms for the byte,
                word, and doubleword SCAS instructions that do not
                require an operand. They are simpler to use but
                provide no type or segment checking.


    SCAS is usually preceded with a REP prefix for a block scan of CX
    or ECX bytes bytes, words, or doublewords.


        Example:
                dataseg
                aname db "Frederik x"
                a_len = ($ - aname)
                codeseg
                mov     di,ds
                mov     es,di
                assume  es:dgroup
                mov     di,offset aname
                mov     cx,a_len
                mov     al,"x"
                cld                     ; Auto-increment di
                repne   scasb           ; Look for "x"
                jne     not_found       ; Can't use JCXZ
                dec     di              ; Point di to "x"
                mov     [byte di],"X"
                ;...
             not_found:


    Opcode      Format
    AE          SCAS m8                 ; = SCASB
    AF          SCAS m16                ; = SCASW
    AF          SCAS m32                ; = SCASD


    Length and timing
    Variations  Bytes   8088    186     286     386     486     Pentium
    scasb        1      19      15       7       7       6       4   NP
    scasw        1      19      15       7       7       6       4   NP
    scasd        1       -       -       -       7       6       4   NP
    repX scasb   2      9+15n   5+15n   5+8n    5+8n    7+5n*   8+4n NP
    repX scasw   2      9+19n   5+15n   5+8n    5+8n    7+5n*   8+4n NP
    repX scasd   2       -       -       -      5+8n    7+5n*   8+4n NP

    repX = repe or repz or repne or repnz

                     * = 5 if n=0
                     (n = count of bytes, words or dwords)

See Also: REP CMPS CLD STD Jcc JCXZ Flags

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson