Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- TASM 2.x / MASM 6.x Assembly Language - <b>scasw scan string word 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]
SCASW            Scan String Word                    Flags: O D I T S Z A P C
                                                            *       * * * * *
SCASW

          Logic:    CMP AX, (ES:DI)         ; Sets flags only
                    if DF = 0
                        DI . DI + 2
                    else
                        DI . DI - 2

    This instruction compares two words by subtracting the destination
    word, pointed to by ES:DI, from AX. SCASW 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 word.

  --------------------------------------------------------------------------
   Operands                  Clocks   Transfers  Bytes   Example
      -                        19         1        1     SCASW
   (repeat)                9 + 19/rep   1/rep      1     REPNE SCASW
  --------------------------------------------------------------------------

       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,50           ;Scanning 50 words (CX is used by REPNE)
          LEA     DI, LOST_A      ;Starting address to DI
  REPNE   SCASW                   ;   ...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
          DEC     DI              ;   matching 'A'
                  .
                  .

    Upon exit from the REPNE SCASW loop, the Zero Flag will be set if a
    match was found, and cleared otherwise. If a match was found, DI will
    be pointing two bytes (one word) past the match location; the DEC DI
    pair at FOUND takes care of this problem.

See Also: SCAS SCASB CMPS REP CLD STD Flags

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