home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast2.iso / asmutil / stdlib.zip / STRSPANL.ASM < prev    next >
Assembly Source File  |  1990-07-18  |  1KB  |  83 lines

  1. stdlib        segment    para public 'slcode'
  2.         assume    cs:stdlib
  3. ;
  4. ;
  5. ; strspanl-    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. ;    return address- 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_strspanl
  22. ;
  23. sl_strspanl    proc    far
  24.         push    bp
  25.         mov    bp, sp
  26.         pushf
  27.         push    es
  28.         push    ds
  29.         push    ax
  30.         push    bx
  31.         push    dx
  32.         push    si
  33.         push    di
  34.         cld
  35. ;
  36. ; Put the pointers into a couple of better locations.
  37. ;
  38.         mov    ax, es
  39.         mov    ds, ax
  40.         mov    si, di
  41.         les    di, 2[bp]
  42. ;
  43.         mov    bx, di            ;Preserve ptr to char set.
  44.         mov    cx, 0ffffh
  45.         mov    al, 0
  46.     repne    scasb                ;Compute length of char set.
  47.         neg    cx
  48.         dec    cx
  49.         dec    cx
  50.         mov    2[bp], di        ;Save new return address
  51.         mov    dx, cx            ;Save for use later.
  52. ;
  53. ; Okay, now we can see how many characters from the set match the prefix
  54. ; characters in the string.
  55. ;
  56. StrLp:        lodsb                ;Get next char in string.
  57.         mov    cx, dx            ;Get length of char set.
  58.         mov    di, bx            ;Get ptr to char set
  59.     repne    scasb                ;See if in set
  60.         jz    StrLp            ;Repeat while in set.
  61. ;
  62.         pop    di
  63.         mov    cx, di
  64.         sub    cx, si
  65.         neg    cx
  66.         dec    cx
  67.         pop    si
  68.         pop    dx
  69.         pop    bx
  70.         pop    ax
  71.         pop    ds
  72.         pop    es
  73.         popf
  74.         pop    bp
  75.         ret
  76. sl_strspanl    endp
  77. ;
  78. ;
  79. ;
  80. ;
  81. stdlib        ends
  82.         end
  83.