home *** CD-ROM | disk | FTP | other *** search
/ C!T ROM 5 / ctrom5b.zip / ctrom5b / PROGRAM / ASM / ALIB30B / SCAN16.ASM < prev    next >
Assembly Source File  |  1994-10-31  |  3KB  |  136 lines

  1.     page    66,132
  2. ;******************************** SCAN16.ASM *********************************
  3.  
  4. LIBSEG           segment byte public "LIB"
  5.         assume cs:LIBSEG , ds:nothing
  6.  
  7. ;----------------------------------------------------------------------------
  8. .xlist
  9.     include  mac.inc
  10.     include  common.inc
  11. .list
  12. comment 
  13. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -( SEARCH  )
  14. BUFFER_SEARCH - search string1 for the first occurance of string2
  15. ;
  16. ; inputs:    ES:[DI] pointing to string1
  17. ;            DS:[SI] pointing to string2
  18. ;            
  19. ; output:    if no carry - DI = offset of target in source string.
  20. ;            if carry -  no match
  21. ;
  22. ; note:  case is ignored.  Strings must end with null character (zero).
  23. ;* * * * * * * * * * * * * *
  24. 
  25.     PUBLIC    BUFFER_SEARCH
  26. BUFFER_SEARCH    PROC    FAR
  27.     APUSH   AX,BX,CX,DX,SI
  28. ;
  29. ; scan for length of string  -> cx
  30. ;
  31.     push    di
  32.     xor    al,al
  33.     mov    cx,-1
  34.     repnz    scasb
  35.     not    cx
  36.     dec    cx
  37.     pop    di
  38.     jmp    first_char_scan
  39. BUFFER_SEARCH    ENDP
  40. comment 
  41. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -( SEARCH  )
  42. BUFFER_SEACHC - search a buffer for the first occurance of a string
  43. ;                     
  44. ; inputs:    ES:[DI] pointing to buffer
  45. ;            DS:[SI] pointing to match-string.
  46. ;                cx = length of buffer
  47. ;
  48. ; output:    if no carry - DI = offset of target in source string.
  49. ;            if carry    - no match
  50. ;
  51. ; note:  case is ignored.  Match string in DS:SI must end with zero.
  52. ;* * * * * * * * * * * * * *
  53. 
  54.     public    buffer_searchc
  55. BUFFER_SEARCHC    PROC    FAR    
  56.     APUSH   ax,BX,CX,DX,SI
  57. ;
  58. ; in the following loop, the long-string ptr moves only (es:di)
  59. ;    
  60. first_char_scan:
  61.     mov    ah,byte ptr [si]    ;get short-string char
  62.     mov    al,byte ptr es:[di]    ;get long_string char.
  63. ;
  64. ; convert -al- long_string to lower case
  65. ;
  66.     cmp    al,'A'
  67.     jb    bs_1            ;jmp if not alpha
  68.     cmp    al,'Z'
  69.     ja    bs_1            ;jmp if not alpha
  70.     or    al,20h            ;convert to lower
  71.     cmp    ah,al            ;compare strings
  72.     je    match1            ;jmp if match
  73. ;
  74. ; convert -al- long_string to upper case and try again
  75. ;
  76.     and    al,0dfh            ;convert to upper case
  77. bs_1:    cmp    ah,al
  78.     je    match1            ;jmp if match    
  79. ;
  80. ; this long-string char does not match, move to next long string char
  81. ;
  82. first_char_scan_cont:
  83.     inc    di
  84.     loop    first_char_scan
  85.     jmp    str_not_found
  86. ;
  87. ; the first char matches. ds:si=short string ptr   es:di=long string ptr
  88. ;
  89. match1:
  90.     push    si
  91.     push    di
  92. match_lp:    
  93.     inc    si
  94.     mov    ah,byte ptr ds:[si]    ;get next short string char
  95.     inc    di            ;move to next long string char
  96.     mov    al,byte ptr es:[di]    ;get long_string char.
  97.     cmp    ah,0
  98.     je    str_found        ;jmp if we have a match
  99.     cmp    al,0
  100.     je    str_not_found2        ;jmp if char not found
  101. ;
  102. ; convert -al- long_string to lower case
  103. ;
  104.     cmp    al,'A'
  105.     jb    bs_2            ;jmp if not alpha
  106.     cmp    al,'Z'
  107.     ja    bs_2            ;jmp if not alpha
  108.     or    al,20h            ;convert to lower
  109.     cmp    ah,al            ;compare strings
  110.     je    match_lp        ;jmp if match
  111. ;
  112. ; convert -al- long_string to upper case and try again
  113. ;
  114.     and    al,0dfh            ;convert to upper case
  115. bs_2:    cmp    ah,al
  116.     je    match_lp        ;jmp if match
  117. str_not_found2:
  118.     pop    di
  119.     pop    si
  120.     jmp    first_char_scan_cont
  121.     
  122. str_not_found:    
  123.     stc
  124.     jmp    bs__exit    
  125. str_found:
  126.     pop    di            ;put offset of match in -ax-
  127.     pop    si
  128.     clc
  129. bs__exit:        
  130.     APOP    SI,DX,CX,BX,AX
  131.         RETF
  132. BUFFER_SEARCHC ENDP
  133.  
  134. LIBSEG    ENDS
  135.     end
  136.