home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast2.iso / asmutil / stdlib.zip / STRSPAN.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. ; strspan-    Returns the number of characters (from a set) which
  6. ;        precede a string.
  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 in set which are the prefix of
  16. ;        the test string.
  17. ;
  18. ;
  19. ;
  20. ;
  21.         public    sl_strspan
  22. ;
  23. sl_strspan    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.         xchg    di, si
  35.         mov    ax, es
  36.         mov    es, dx
  37.         mov    ds, ax
  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.         jz    StrLp            ;Repeat while in set.
  56. ;
  57.         pop    cx
  58.         mov    di, cx
  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_strspan    endp
  71. ;
  72. ;
  73. ;
  74. ;
  75. stdlib        ends
  76.         end
  77.