home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c065 / 2.ddi / CLIB2.ZIP / STRLEN.CAS < prev    next >
Encoding:
Text File  |  1990-06-07  |  1.8 KB  |  61 lines

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