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

  1. ;
  2. ; *** Listing 11-27 ***
  3. ;
  4. ; Determines whether two zero-terminated strings differ
  5. ; ignoring case-only differences, and if so where, using
  6. ; LODS, with an XLAT-based table look-up to convert to
  7. ; uppercase.
  8. ;
  9.     jmp    Skip
  10. ;
  11. TestString1    label    byte
  12.     db    'THIS IS A TEST STRING THAT IS '
  13.     db    'Z'
  14.     db    'TERMINATED WITH A ZERO BYTE...',0
  15. TestString2    label    byte
  16.     db    'This is a test string that is '
  17.     db    'a'
  18.     db    'terminated with a zero byte...',0
  19. ;
  20. ; Table of conversions between characters and their
  21. ; uppercase equivalents. (Could be just 128 bytes long if
  22. ; only 7-bit ASCII characters are used.)
  23. ;
  24. ToUpperTable    label    word
  25. CHAR=0
  26.     rept    256
  27. if (CHAR lt 'a') or (CHAR gt 'z')
  28.     db    CHAR    ;not a lowercase character
  29. else
  30.     db    CHAR and not 20h
  31.             ;convert in the range 'a'-'z' to
  32.             ; uppercase
  33. endif
  34. CHAR=CHAR+1
  35.     endm
  36. ;
  37. ; Compares two zero-terminated strings, ignoring differences
  38. ; that are only uppercase/lowercase differences.
  39. ;
  40. ; Input:
  41. ;    DS:SI = first zero-terminated string
  42. ;    ES:DI = second zero-terminated string
  43. ;
  44. ; Output:
  45. ;    DS:SI = pointer to first case-insensitive differing
  46. ;        location in first string, or 0 if the byte
  47. ;        wasn't found
  48. ;    ES:DI = pointer to first case-insensitive differing
  49. ;        location in second string, or 0 if the byte
  50. ;        wasn't found
  51. ;
  52. ; Registers altered: AX, BX, DX, SI, DI
  53. ;
  54. ; Direction flag cleared
  55. ;
  56. ; Note: Does not handle strings that are longer than 64K
  57. ;    bytes or cross segment boundaries.
  58. ;
  59. CompareStringsNoCase:
  60.     cld
  61.     mov    bx,offset ToUpperTable
  62. CompareStringsLoop:
  63.     lodsw        ;get the next 2 bytes
  64.     mov    dx,es:[di] ; from each string
  65.     inc    di    ;point to the next word in the
  66.     inc    di    ; second string
  67.     xlat        ;convert the first byte in the
  68.             ; first string to uppercase
  69.     xchg    dl,al    ;set aside the first byte &
  70.     xlat        ; convert the first byte in the
  71.             ; second string to uppercase
  72.     cmp    al,dl    ;do the first bytes match?
  73.     jnz    CompareStringsDifferent1 ;the strings differ
  74.     and    al,al    ;is this the terminating zero?
  75.     jz    CompareStringsSame
  76.             ;yes, we're done, with a match
  77.     mov    al,ah
  78.     xlat        ;convert the second byte from the
  79.             ; first string to uppercase
  80.     xchg    dh,al    ;set aside the second byte &
  81.     xlat        ; convert the second byte from the
  82.             ; second string to uppercase
  83.     cmp    al,dh    ;do the second bytes match?
  84.     jnz    CompareStringsDifferent ;the strings differ
  85.     and    ah,ah    ;is this the terminating zero?
  86.     jnz    CompareStringsLoop
  87.             ;no, do the next 2 bytes
  88. CompareStringsSame:
  89.     sub    si,si    ;return 0 pointers indicating that
  90.     mov    di,si    ; the strings are identical
  91.     ret
  92. CompareStringsDifferent1:
  93.     dec    si    ;point back to the second byte of
  94.     dec    di    ; the word we just compared
  95. CompareStringsDifferent:
  96.     dec    si    ;point back to the first byte of the
  97.     dec    di    ; word we just compared
  98.     ret
  99. ;
  100. Skip:
  101.     call    ZTimerOn
  102.     mov    si,offset TestString1 ;point to one string
  103.     mov    di,seg TestString2
  104.     mov    es,di
  105.     mov    di,offset TestString2 ;point to other string
  106.     call    CompareStringsNoCase    ;and compare the
  107.                     ; strings without
  108.                     ; regard for case
  109.     call    ZTimerOff
  110.