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

  1.     page    66,132
  2. ;******************************* SCAN04.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_BLOCK2 - scan sequential buffers for string, match 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. other_case    db    0    ;other case of first search char.
  43.  
  44.     PUBLIC    SCAN_BLOCK2
  45. SCAN_BLOCK2    PROC    FAR
  46.         apush    bp,dx
  47.         mov    dl,20h
  48.         mov    ah,es:[di]    ;get first cmp string char
  49.         cmp    ah,'A'
  50.         jb    sb_3        ;jmp if not alpha
  51.     cmp    ah,'Z'
  52.     jb    sb_1        ;jmp if is lower
  53.     cmp    ah,'a'
  54.     jb    sb_3        ;jmp if not alpha
  55.     cmp    ah,'z'
  56.     ja    sb_3        ;jmp if not alpha
  57.     xor    ah,dl        ;make lower case
  58.     jmp    sb_3
  59.     
  60. sb_1:    or    ah,dl        ;make lower case
  61. sb_3:    mov    cs:other_case,ah        
  62. sb_lp0: mov    ah,es:[di]
  63.         mov     dh,cs:other_case
  64. ;
  65. ; ah,dh = upper and lower case compare characters
  66. fast_lp:lodsb
  67.     dec    cx
  68.     cmp    al,dh
  69.     je    sb_6
  70.     cmp    al,ah
  71.     je    sb_6
  72.     jcxz    at_eof
  73.  
  74.     lodsb
  75.     dec    cx
  76.     cmp    al,dh
  77.     je    sb_6
  78.     cmp    al,ah
  79.     je    sb_6
  80.     jcxz    at_eof
  81.  
  82.     lodsb
  83.     dec    cx
  84.     cmp    al,dh
  85.     je    sb_6
  86.     cmp    al,ah
  87.     je    sb_6
  88.     jcxz    at_eof
  89.  
  90.     lodsb
  91.     dec    cx
  92.     cmp    al,dh
  93.     je    sb_6
  94.     cmp    al,ah
  95.     je    sb_6
  96.     jcxz    at_eof
  97.         jmp    fast_lp
  98.     
  99. sb_6:    mov    bp,si
  100. sb_lp2: inc    di
  101.     mov    ah,es:[di]
  102.     cmp    ah,0
  103.     je    match
  104.     jcxz    at_eof
  105.  
  106.            lodsb
  107.            dec     cx
  108.        cmp       al, ah
  109.        je       @@bye
  110.        mov       dh, al
  111.        or       dh, dl
  112.            sub     dh, 'a'
  113.            cmp     dh, 'z' - 'a' + 1
  114.        jnc       @@not_alpha
  115.        xor       al,dl
  116. @@not_alpha:
  117.     cmp    al, ah
  118. @@bye:
  119.     je    sb_lp2
  120.     
  121.     add    cx,si
  122.     sub    cx,bp
  123.     
  124.     mov    si,bp
  125.     mov    di,bx
  126.     jmp    sb_lp0
  127. match:    mov    di,bx
  128. at_eof: apop    dx,bp
  129.     retf
  130. SCAN_BLOCK2    ENDP
  131. ;------------------------------------------------------------------------
  132.  
  133. LIBSEG    ENDS
  134.     end
  135.