home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PROGRAMS / UTILS / DOS_HELP / XP.ZIP / FINDSTR.ASM < prev    next >
Encoding:
Assembly Source File  |  1990-01-27  |  2.0 KB  |  64 lines

  1. ; Function to perform comparison between a far and
  2. ; near string. A brute force method is used for searching.
  3. ; Use to find the "PATH=" string in the master environment.
  4. ; Returns pointer to start of string if match is found.
  5. ; Returns null pointer if not.
  6. ;       char far *findstr(char far *str1, char *str2);
  7. ; For Turbo C 2.0, small/tiny model.
  8. ; Written and tested with Turbo Assembler 1.0
  9. ; By Goh King Hwa, 20 Dec 1989.
  10. ; Bug Fix: 27 Jan 1990
  11.  
  12. _TEXT   segment byte public 'CODE'
  13.         assume  cs:_TEXT
  14. _findstr    proc    near
  15.     push    bp
  16.     mov    bp,sp
  17.         push    ds
  18.         push    si
  19.         push    di
  20.  
  21.         mov     ax,ds
  22.         mov     es,ax           ;move DS to ES
  23.         cld                     ;auto-increment mode
  24.  
  25. findEnd:                        ;find end of near string
  26.         mov     cx,-1           ;set for maximum count
  27.         mov     di,[bp+8]
  28.         xor     al,al           ;zero AL
  29.         repnz   scasb           ;repeat until EOS
  30.         mov     bx,di           ;end of near string save in BX
  31.  
  32.         mov     di,[bp+8]       ;ES:DI points to near string
  33.         lds     si,[bp+4]       ;DS:SI points to far string
  34.  
  35.         cmp     byte ptr [si],0
  36.         je      notfound        ;null far string, exit
  37.         cmp     byte ptr es:[di],0
  38.         je      notfound        ;null near string, exit
  39.  
  40. search:
  41.         mov     dx,si           ;save marker
  42.         mov     cx,-1           ;set for maximum count
  43.         repz    cmpsb           ;until the first non-matching character
  44.         cmp     bx,di           ;check against end of string
  45.         jne     notfound        ;if BX == DI, string matches
  46. found:
  47.         mov     ax,dx           ;restore old DI
  48.         mov     dx,ds           ;remember segment address
  49.         jmp     short exit
  50. notfound:
  51.         xor     ax,ax           ;return zero
  52.         xor     dx,dx           ;if string not found
  53. exit:
  54.         pop     di
  55.         pop     si
  56.         pop     ds
  57.     pop    bp
  58.     ret    
  59. _findstr    endp
  60. _TEXT    ends
  61.  
  62.         public  _findstr
  63.     end
  64.