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

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