home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c082_144 / 1.ddi / CLIBSRC1.ZIP / STRLEN.CAS < prev    next >
Encoding:
Text File  |  1992-06-10  |  1.4 KB  |  65 lines

  1. /*-----------------------------------------------------------------------*
  2.  * filename - strlen.cas
  3.  *
  4.  * function(s)
  5.  *        strlen - calculates the length of a string
  6.  *-----------------------------------------------------------------------*/
  7.  
  8. /*
  9.  *      C/C++ Run Time Library - Version 5.0
  10.  *
  11.  *      Copyright (c) 1987, 1992 by Borland International
  12.  *      All Rights Reserved.
  13.  *
  14.  */
  15.  
  16.  
  17. #pragma inline
  18. #include <asmrules.h>
  19. #include <string.h>
  20.  
  21. /*-----------------------------------------------------------------------*
  22.  
  23. Name            strlen - calculates the length of a string
  24.  
  25. Usage           size_t strlen(const char *str);
  26.  
  27. Prototype in    string.h
  28.  
  29. Description     returns the length of a null terminated string
  30.  
  31. *------------------------------------------------------------------------*/
  32. #undef strlen                  /* not an intrinsic */
  33.  
  34. #if defined(__FARFUNCS__)
  35. #include <_farfunc.h>
  36. #endif
  37.  
  38. size_t _CType _FARFUNC strlen(const char *str)
  39. {
  40.   #if !(LDATA)
  41.   asm     mov     ax,ds
  42.   asm     mov     es,ax
  43.   asm     mov     di,str
  44.   asm     xor     ax,ax
  45.   #else
  46.   asm     les     di,str
  47.   asm     xor     ax,ax
  48.   asm     cmp     ax,W1(str)
  49.   asm     jne     start
  50.   asm     cmp     ax,di
  51.   asm     je      out
  52.   #endif
  53.  
  54.   start:
  55.   asm     cld
  56.   asm     mov     cx, -1
  57.   asm     repne   scasb
  58.   asm     xchg    ax,cx
  59.   asm     not     ax
  60.   asm     dec     ax
  61.  
  62.   out:
  63.   return(_AX);
  64. }
  65.