home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast2.iso / asmutil / zendisk2.zip / LST11-21.ASM < prev    next >
Assembly Source File  |  1990-02-15  |  2KB  |  72 lines

  1. ;
  2. ; *** Listing 11-21 ***
  3. ;
  4. ; Compares two word-sized arrays of equal length to see
  5. ; whether they differ, and if so where, using REPZ CMPSW.
  6. ;
  7.     jmp    Skip
  8. ;
  9. WordArray1    dw    100 dup (1), 0, 99 dup (2)
  10. ARRAY_LENGTH_IN_WORDS    equ    (($-WordArray1)/2)
  11. WordArray2    dw    100 dup (1), 100 dup (2)
  12. ;
  13. ; Returns pointers to the first locations at which two
  14. ; word-sized arrays of equal length differ, or zero if
  15. ; they're identical.
  16. ;
  17. ; Input:
  18. ;    CX = length of the arrays (they must be of equal
  19. ;        length)
  20. ;    DS:SI = the first array to compare
  21. ;    ES:DI = the second array to compare
  22. ;
  23. ; Output:
  24. ;    DS:SI = pointer to the first differing location in
  25. ;        the first array if there is a difference,
  26. ;        or SI=0 if the arrays are identical
  27. ;    ES:DI = pointer to the first differing location in
  28. ;        the second array if there is a difference,
  29. ;        or DI=0 if the arrays are identical
  30. ;
  31. ; Registers altered: SI, DI
  32. ;
  33. ; Direction flag cleared
  34. ;
  35. ; Note: Does not handle arrays that are longer than 32K
  36. ;    words or cross segment boundaries.
  37. ;
  38. FindFirstDifference:
  39.     cld
  40.     jcxz    FindFirstDifferenceSame
  41.                 ;if there's nothing to
  42.                 ; check, we'll consider the
  43.                 ; arrays to be the same.
  44.                 ; (If we let REPZ CMPSW
  45.                 ; execute with CX=0, we
  46.                 ; may get a false match
  47.                 ; because CMPSW repeated
  48.                 ; zero times doesn't alter
  49.                 ; the flags)
  50.     repz    cmpsw        ;compare the arrays
  51.     jz    FindFirstDifferenceSame    ;they're identical
  52.     dec    si        ;the arrays differ, so
  53.     dec    si        ; point back to first
  54.     dec    di        ; difference in both arrays
  55.     dec    di
  56.     ret
  57. FindFirstDifferenceSame:
  58.     sub    si,si        ;indicate that the strings
  59.     mov    di,si        ; are identical
  60.     ret
  61. ;
  62. Skip:
  63.     call    ZTimerOn
  64.     mov    si,offset WordArray1    ;point to the two
  65.     mov    di,ds            ; arrays to be
  66.     mov    es,di            ; compared
  67.     mov    di,offset WordArray2    
  68.     mov    cx,ARRAY_LENGTH_IN_WORDS
  69.                     ;# of words to check
  70.     call    FindFirstDifference    ;see if they differ
  71.     call    ZTimerOff
  72.