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

  1.     page    66,132
  2. ;******************************* SCAN02.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_TINY2 - scan sequential buffers for string, matching either case
  15. ;  inputs:  es:bx   =   compare string start (string terminated with zero)
  16. ;           es:di   =   compare string current location
  17. ;           ds:si   =   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 ah=0 then a match was found ds:si points at match end.
  23. ;                 use -si- 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. ;
  33. ;                            code size   speed
  34. ;         SCAN_BLOCK_TINY1    46 bytes    2.36 (small is faster)
  35. ;         SCAN_BLOCK_TINY2    69 bytes   13.35 (matches ether case)
  36. ;         SCAN_BLOCK1         43 bytes    2.36
  37. ;         SCAN_BLOCK2        152 bytes    6.37 (matches either case)
  38. ;         SCAN_BLOCK_FAST    466 bytes    1.42 
  39. ;
  40. ;* * * * * * * * * * * * * *
  41. 
  42.     PUBLIC    SCAN_BLOCK_TINY2
  43. SCAN_BLOCK_TINY2    PROC    FAR
  44.     mov    dl,20h
  45.         push    bp
  46. sb_lp0: mov    ah,es:[di]    ;get first char. of compare string
  47. sb_lp1: jcxz    at_eof        ;jmp if buffer empty
  48.     call    compare        ;compare first char
  49.     jne    sb_lp1        ;loop if no match
  50.     mov    bp,si        ;save start of possible match
  51. sb_lp2: inc    di        ;move to next compare string char.
  52.     mov    ah,es:[di]    ;get next compare string char.
  53.     cmp    ah,0        ;end of compare string?
  54.     je    match        ;jmp if all characters match
  55.     jcxz    at_eof        ;jmp if at end of buffer
  56.     call    compare        ;compare next char.
  57.     je    sb_lp2        ;jmp if match
  58.     
  59.     add    cx,si        ;compute cx to restart search
  60.     sub    cx,bp
  61.     
  62.     mov    si,bp        ;get buffer ptr to restart search
  63.     mov    di,bx        ;get compare string start
  64.     jmp    sb_lp0        ;go restart search
  65. match:    mov    di,bx        ;set compare string ptr to start.
  66. at_eof: pop    bp
  67.     retf
  68. SCAN_BLOCK_TINY2    ENDP
  69. ;
  70. ; compare character in -ah- to next char. in buffer.
  71. ;  inputs:    ah = compare string char.
  72. ;          ds:si = buffer ptr
  73. ;             cx = amount of data left in buffer
  74. ;             dl = case flag
  75. ;
  76. compare:   lodsb            ;get next char. from buffer
  77.        dec       cx            ;update count of buffer char's
  78.        cmp       al, ah        ;match?
  79.        je       bye            ;jmp if match
  80.        mov       dh, al        ;try matching other
  81.        or       dh, dl        ;  case if char
  82.            sub     dh, 'a'        ;     is an alpha
  83.            cmp     dh, 'z' - 'a' + 1
  84.        jnc       not_alpha
  85.        xor      al,dl
  86. not_alpha: cmp    al, ah
  87. bye:       ret
  88. ;------------------------------------------------------------------------
  89.  
  90. LIBSEG    ENDS
  91. ;;    end
  92.