home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PROGRAMS / UTILS / DOS_HELP / ADVMSDOS.ZIP / STRNDX.ASM < prev    next >
Encoding:
Assembly Source File  |  1986-06-19  |  1.3 KB  |  47 lines

  1.  
  2. ;
  3. ; General purpose string search/matching routine for 8086
  4. ; Copyright (C) 1986 Ray Duncan, June 1986
  5. ;
  6. ; Call with:      DS:SI = pattern address
  7. ;              BX    = pattern length 
  8. ;        ES:DI = address of string to be searched
  9. ;        DX    = length of string to be searched
  10. ;
  11. ; Returns:      CY    = True if no match 
  12. ;               or
  13. ;        CY    = False if match, and 
  14. ;               ES:DI = pointer to matched string 
  15. ;
  16. strndx    proc    near
  17.  
  18.     mov    bp,si            ; save pattern offset
  19.     dec    bx            ; decr. pattern length by one
  20.     cld
  21.  
  22. s1:    mov    si,bp            ; AL := first char of pattern
  23.     lodsb
  24.     mov    cx,dx            ; remaining searched string length
  25.     repnz scasb            ; look for match on first char.
  26.     jnz    s3            ; searched string exhausted, exit
  27.     mov    dx,cx            ; save new string length
  28.     mov    cx,bx            ; get pattern length - 1
  29.     repz cmpsb            ; compare remainder of strings
  30.     jz    s2            ; everything matched
  31.     add    di,cx            ; no match, restore string addr
  32.     sub    di,bx            ; advanced by one char.
  33.     cmp    dx,bx            ; searched string exhausted?
  34.     ja    s1            ; some string left, try again
  35.     jmp    s3            ; no match, jump to return 
  36.  
  37. s2:    sub    di,bx            ; match was found,
  38.     dec    di            ; let ES:DI = addr of matched string
  39.     clc                ; and return CY=False
  40.     ret
  41.  
  42. s3:    stc                ; no match, return CY=True
  43.     ret
  44.  
  45. strndx    endp
  46. ;
  47.