home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast2.iso / asmutil / stdlib.zip / STRCSPAN.ASM < prev    next >
Assembly Source File  |  1990-07-18  |  1KB  |  77 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:DI-  Points at string to test.
  11. ;    DX:SI-    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_strcspan
  22. ;
  23. sl_strcspan    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.         mov    ax, es
  35.         mov    es, dx
  36.         mov    ds, ax
  37.         xchg    si, di
  38. ;
  39.         mov    bx, di            ;Preserve ptr to char set.
  40.         mov    cx, 0ffffh
  41.         mov    al, 0
  42.     repne    scasb                ;Compute length of char set.
  43.         neg    cx
  44.         dec    cx
  45.         dec    cx
  46.         mov    dx, cx            ;Save for use later.
  47. ;
  48. ; Okay, now we can see how many characters from the set match the prefix
  49. ; characters in the string.
  50. ;
  51. StrLp:        lodsb                ;Get next char in string.
  52.         mov    cx, dx            ;Get length of char set.
  53.         mov    di, bx            ;Get ptr to char set
  54.     repne    scasb                ;See if in set
  55.         jnz    StrLp            ;Repeat while not in set.
  56. ;
  57.         pop    di
  58.         mov    cx, di
  59.         sub    cx, si
  60.         neg    cx
  61.         dec    cx    
  62.         pop    si
  63.         pop    dx
  64.         pop    bx
  65.         pop    ax
  66.         pop    ds
  67.         pop    es
  68.         popf
  69.         ret
  70. sl_strcspan    endp
  71. ;
  72. ;
  73. ;
  74. ;
  75. stdlib        ends
  76.         end
  77.