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>cmpsb compare string byte 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]
CMPSB            Compare String Byte                 Flags: O D I T S Z A P C
                                                            *       * * * * *
CMPSB

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

    This instruction compares two values by subtracting the byte pointed
    to by ES:DI, from the byte pointed to by DS:SI, and sets the flags
    according to the results of the comparison. The operands themselves
    are not altered. After the comparison, SI and DI are 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.

  --------------------------------------------------------------------------
   Operands                  Clocks   Transfers  Bytes   Example
      -                        22         2        1     CMPSB
   (repeat)                9 + 22/rep   2/rep      1     REPE CMPSB

  -------------------------------- Example ---------------------------------

    The following example compares BUFFER1 against BUFFER2 for the first
    mismatch.

          cld                     ;Scan in the forward direction
          mov     cx, 100         ;Scanning 100 bytes (CX is used by REPE)
          lea     si, buffer1     ;Starting address of first buffer
          lea     di, buffer2     ;Starting address of second buffer
          repe    cmpsb           ;   ...and compare it.
          jne     mismatch        ;The Zero Flag will be cleared if there
                                  ;   is a mismatch
  match:          .               ;If we get here, buffers match
                  .
  mismatch:
          dec     si              ;If we get here, we found a mismatch.
          dec     di              ;Back up SI and DI so they point to the
                  .               ;   first mismatch

    Upon exit from the REPE CMPSB loop, the Zero Flag will be cleared if a
    mismatch was found, and set otherwise. If a mismatch was found, DI and
    SI will be pointing one byte past the byte that didn't match; the DEC
    DI and DEC SI instructions backup these registers so they point to the
    mismatched characters.

See Also: CMP CMPS CMPSW SCAS REP CLD STD Flags

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