home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast.iso / pcmag / vol7n17.zip / PP717.ZIP / STRINGS3.ASM < prev    next >
Assembly Source File  |  1988-08-30  |  5KB  |  163 lines

  1. ;----------------------------------------------------------------------
  2. ; STRINGS3.ASM --- MASM String Package #3
  3. ; Copyright (c) 1988 Ziff Communications Co.
  4. ; PC Magazine * Ray Duncan * 12-13-88
  5. ;----------------------------------------------------------------------
  6. _TEXT   segment word public 'CODE'
  7.         extrn   strcmp:near     ; from STRINGS1
  8.         extrn   strndx:near     ; from STRINGS1
  9.         extrn   strupr:near     ; from STRINGS2
  10.         assume  cs:_TEXT
  11. ;----------------------------------------------------------------------
  12. ; STRCMPI:      Case-insensitive string comparison 
  13. ;
  14. ; Call with:    DS:SI = address of string1
  15. ;               BX    = length of string1
  16. ;               ES:DI = address of string2
  17. ;               DX    = length of string2
  18. ;
  19. ; Returns:      Z     = True  if strings are equal
  20. ;               or
  21. ;               Z     = False if strings are not equal, and
  22. ;               S     = True  if string1 < string2
  23. ;               S     = False if string1 > string2
  24. ;
  25. ; Uses:         nothing
  26. ;----------------------------------------------------------------------
  27.         public  strcmpi
  28. strcmpi proc    near
  29.  
  30.         push    bx              ; save registers
  31.         push    cx
  32.         push    dx
  33.         push    si              
  34.         push    di
  35.         push    ds
  36.         push    es
  37.  
  38.         call    strupr2         ; translate both strings to upper case
  39.         call    strcmp          ; compare upper-cased strings
  40.  
  41.         pop     es              ; restore registers
  42.         pop     ds      
  43.         pop     di
  44.         pop     si
  45.         pop     dx
  46.         pop     cx
  47.         pop     bx
  48.         ret                     ; return S and Z flags 
  49.  
  50. strcmpi endp
  51. ;----------------------------------------------------------------------
  52. ; STRNDXI:      Case-insensitive string search 
  53. ;
  54. ; Call with:    DS:SI = pattern address
  55. ;               BX    = pattern length 
  56. ;               ES:DI = address of string to be searched
  57. ;               DX    = length of string to be searched
  58. ;
  59. ; Returns:      CY    = True if no match 
  60. ;               ES:DI = unchanged
  61. ;               or
  62. ;               CY    = False if match, and 
  63. ;               ES:DI = pointer to match for pattern
  64. ;                       string within searched string
  65. ;
  66. ; Uses:         nothing
  67. ;----------------------------------------------------------------------
  68.         public  strndxi
  69. strndxi proc    near
  70.  
  71.         push    ax              ; save registers
  72.         push    bx
  73.         push    cx
  74.         push    dx
  75.         push    si
  76.         push    di
  77.         push    bp
  78.         push    ds
  79.         push    es
  80.  
  81.         call    strupr2         ; translate both strings to upper case
  82.         push    di              ; save offset of dup string to be searched
  83.         call    strndx          ; search upper-cased string
  84.         jc      sndx3           ; jump, no match found
  85.  
  86.         pop     bx              ; match found, calculate neg.
  87.         sub     bx,di           ; offset in duplicate string
  88.  
  89.         pop     es              ; restore registers and
  90.         pop     ds              ; let ES:DI = offset of
  91.         pop     bp              ; match in original string
  92.         pop     di
  93.         sub     di,bx
  94.         pop     si
  95.         pop     dx
  96.         pop     cx
  97.         pop     bx
  98.         pop     ax
  99.         clc                     ; return Carry = False
  100.         ret
  101.  
  102. sndx3:  pop     di              ; no match found, discard address of duplicate
  103.         pop     es              ; restore registers
  104.         pop     ds
  105.         pop     bp
  106.         pop     di
  107.         pop     si
  108.         pop     dx
  109.         pop     cx
  110.         pop     bx
  111.         pop     ax
  112.         ret                     ; return Carry = True
  113.  
  114. strndxi endp
  115. ;----------------------------------------------------------------------
  116. ; STRUPR2:      Duplicate two strings and translate 
  117. ;               the duplicates to upper-case
  118. ;
  119. ; Call with:    DS:SI = string1 address
  120. ;               BX    = string1 length 
  121. ;               ES:DI = string2 address
  122. ;               DX    = string2 length
  123. ;
  124. ; Returns:      DS:SI = address of upper-cased string1 
  125. ;                       in temporary storage
  126. ;               BX    = string1 length
  127. ;               ES:DI = address of upper-cased string2
  128. ;                       in temporary storage
  129. ;               DX    = string2 length
  130. ;
  131. ; Uses:         nothing
  132. ;----------------------------------------------------------------------
  133. strupr2 proc    near
  134.  
  135.         push    ds              ; save address and length
  136.         push    si              ; of string1
  137.         push    bx
  138.         push    es              ; get address and length        
  139.         push    di              ; of string2 for strdup
  140.         push    dx
  141.         pop     bx
  142.         pop     si
  143.         pop     ds
  144.  
  145.         call    strupr          ; dup string2 and translate to upper-case
  146.         push    ds              ; save address and length
  147.         push    si              ; of string2 copy
  148.         push    bx
  149.         pop     dx
  150.         pop     di
  151.         pop     es
  152.         pop     bx              ; restore address and 
  153.         pop     si              ; length of string1
  154.         pop     ds
  155.  
  156.         call    strupr          ; dup string1 and translate to upper-case
  157.         ret                     ; return to caller
  158.  
  159. strupr2 endp
  160.  
  161. _TEXT   ends
  162.         end
  163.