home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast2.iso / asmutil / stdlib.zip / STRCSPN2.ASM < prev    next >
Assembly Source File  |  1991-03-04  |  1KB  |  78 lines

  1. stdlib        segment    para public 'slcode'
  2.         assume    cs:stdlib
  3. ;
  4. ;
  5. ; strcspan-    Returns the number of characters at the beginning of a string
  6. ;        which are NOT from a specified set.
  7. ;
  8. ; inputs:
  9. ;
  10. ;    ES:SI-  Points at string to test.
  11. ;    DS:DI-    Points at set of characters (zero terminated string).
  12. ;
  13. ; outputs:
  14. ;
  15. ;    CX-    Number of characters not in the set which are the prefix of
  16. ;        the test string.
  17. ;
  18. ;
  19. ;
  20. ;
  21.         public    sl_strcspan2
  22. ;
  23. sl_strcspan2    proc    far
  24.         pushf
  25.         push    es
  26.         push    ds
  27.         push    ax
  28.         push    bx
  29.         push    dx
  30.         push    si
  31.         push    di
  32.         cld
  33. ;
  34. ; Put the pointers into a couple of better locations.
  35. ;
  36.         mov    ax, es
  37.         mov    cx, ds
  38.         mov    es, cx
  39.                 mov    ds, ax
  40. ;
  41.         mov    bx, di            ;Preserve ptr to char set.
  42.         mov    cx, 0ffffh
  43.         mov    al, 0
  44.     repne    scasb                ;Compute length of char set.
  45.         neg    cx
  46.         dec    cx
  47.         dec    cx
  48.         mov    dx, cx            ;Save for use later.
  49. ;
  50. ; Okay, now we can see how many characters from the set match the prefix
  51. ; characters in the string.
  52. ;
  53. StrLp:        lodsb                ;Get next char in string.
  54.         mov    cx, dx            ;Get length of char set.
  55.         mov    di, bx            ;Get ptr to char set
  56.     repne    scasb                ;See if in set
  57.         jnz    StrLp            ;Repeat while not in set.
  58. ;
  59.         pop    di
  60.         pop    cx
  61.         sub    si, cx
  62.         xchg    cx, si
  63.         dec    cx
  64.         pop    dx
  65.         pop    bx
  66.         pop    ax
  67.         popf
  68.         pop    ds
  69.         pop    es
  70.         ret
  71. sl_strcspan2    endp
  72. ;
  73. ;
  74. ;
  75. ;
  76. stdlib        ends
  77.         end
  78.