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

  1. ;
  2. ; *** Listing 11-23 ***
  3. ;
  4. ; Compares two word-sized arrays of equal length to see
  5. ; whether they differ, and if so, where, using non-string
  6. ; instructions.
  7. ;
  8.     jmp    Skip
  9. ;
  10. WordArray1    dw    100 dup (1), 0, 99 dup (2)
  11. ARRAY_LENGTH_IN_WORDS    equ    (($-WordArray1)/2)
  12. WordArray2    dw    100 dup (1), 100 dup (2)
  13. ;
  14. ; Returns pointers to the first locations at which two
  15. ; word-sized arrays of equal length differ, or zero if
  16. ; they're identical.
  17. ;
  18. ; Input:
  19. ;    CX = length of the arrays (they must be of equal
  20. ;        length)
  21. ;    DS:SI = the first array to compare
  22. ;    ES:DI = the second array to compare
  23. ;
  24. ; Output:
  25. ;    DS:SI = pointer to the first differing location in
  26. ;        the first array if there is a difference,
  27. ;        or SI=0 if the arrays are identical
  28. ;    ES:DI = pointer to the first differing location in
  29. ;        the second array if there is a difference,
  30. ;        or DI=0 if the arrays are identical
  31. ;
  32. ; Registers altered: AX, SI, DI
  33. ;
  34. ; Note: Does not handle arrays that are longer than 32K
  35. ;    words or cross segment boundaries.
  36. ;
  37. FindFirstDifference:
  38.     jcxz    FindFirstDifferenceSame
  39.                 ;if there's nothing to
  40.                 ; check, we'll consider the
  41.                 ; arrays to be the same
  42. FindFirstDifferenceLoop:
  43.     mov    ax,[si]
  44.     cmp    es:[di],ax    ;compare the next two words
  45.     jnz    FindFirstDifferenceFound ;the arrays differ
  46.     inc    si
  47.     inc    si        ;point to the next words to
  48.     inc    di        ; compare
  49.     inc    di
  50.     loop    FindFirstDifferenceLoop    ;the arrays are the
  51.                     ; same so far
  52. FindFirstDifferenceSame:
  53.     sub    si,si        ;indicate that the strings
  54.     mov    di,si        ; are identical
  55. FindFirstDifferenceFound:
  56.     ret
  57. ;
  58. Skip:
  59.     call    ZTimerOn
  60.     mov    si,offset WordArray1    ;point to the two
  61.     mov    di,ds            ; arrays to be
  62.     mov    es,di            ; compared
  63.     mov    di,offset WordArray2    
  64.     mov    cx,ARRAY_LENGTH_IN_WORDS
  65.                     ;# of words to check
  66.     call    FindFirstDifference    ;see if they differ
  67.     call    ZTimerOff
  68.