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

  1.     page    66,132
  2. ;******************************* SCAN03.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.  
  12.     extrn    strlen1:far
  13. .list
  14. comment 
  15. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -( SEARCH  )
  16. ;SCAN_BLOCK1 - scan sequential buffers for string, match case
  17. ;  inputs:  ds:bx   =   compare string start (string terminated with zero)
  18. ;           ds:si   =   compare string current location
  19. ;           es:di   =   buffer current location
  20. ;              cx   =   buffer size (remaining byte count)
  21. ;           direction flag = CLD state
  22. ;
  23. ;  output:  registers di,si,cx are updated
  24. ;           if flags set for "je" then es:di points past match
  25. ;                 if bx not equal to si then partial match is in progress
  26. ;                 at end of buffer.  CX should also be zero at this point.
  27. ;                 use -si- ,-di- and -cx- as returned to continue searching
  28. ;                 in current buffer.  
  29. ;
  30. ;           if flags set for "jne" then no match was found
  31. ;
  32. ;  Note:  If a partial match fails and the partial match was split
  33. ;         accross two buffers, then extra processing may be needed
  34. ;         by the caller to restart the compare in the first buffer.
  35. ;         Partial matches are detected by checking if -si- points
  36. ;         at start of compare string when end of buffer was reached.
  37. ;         If not at start, then partial match is in progress.
  38. ;
  39. ;         This routine is 43 bytes long and fast if searching for
  40. ;         long strings which are very similiar.
  41. ;
  42. ;                            code size   speed
  43. ;         SCAN_BLOCK_TINY1    46 bytes    2.36 (small is faster)
  44. ;         SCAN_BLOCK_TINY2    69 bytes   13.35 (matches ether case)
  45. ;         SCAN_BLOCK1         43 bytes    2.36
  46. ;         SCAN_BLOCK2        152 bytes    6.37 (matches either case)
  47. ;         SCAN_BLOCK_FAST    466 bytes    1.42 
  48. ;
  49. ;* * * * * * * * * * * * * *
  50. 
  51.  
  52.     PUBLIC    SCAN_BLOCK1
  53. SCAN_BLOCK1    PROC    FAR
  54.     apush    dx,bp
  55.     cmp    si,bx
  56.     jne    st_continue        ;jmp if partial match in progress
  57. restart_scan:
  58.     mov    si,bx
  59.     lodsb                ;get next compare char
  60.     repne    scasb            ;scan for char
  61.     jne    st_exit            ;jmp if no match found
  62. ;
  63. ; the first character matches, check next char
  64. ;
  65. st_continue:
  66.     mov    dx,cx            ;save cx,di incase of
  67.     mov    bp,di            ;   miscompare
  68.  
  69. cmp_lp:    cmp    byte ptr ds:[si],0
  70.     je    st_match1
  71.     jcxz    st_match2        ;jmp if at end of buffer
  72.     cmpsb
  73.     jne    no_match
  74.     dec    cx
  75.     jmp    cmp_lp
  76. no_match:    
  77.     mov    cx,dx            ;restore cx,di
  78.     mov    di,bp
  79.     jmp    restart_scan
  80. ;
  81. ; we have found a match, set exit registers
  82. ;
  83. st_match1:
  84.     mov    si,bx
  85. ;
  86. ; we are at end of buffer, and have a partial match
  87. ;
  88. st_match2:
  89.         
  90. st_exit:
  91.     apop    bp,dx
  92.     retf
  93. SCAN_BLOCK1    ENDP
  94. ;------------------------------------------------------------------------
  95.  
  96. LIBSEG    ENDS
  97. ;;    end
  98.