C Programming - String Length!!

glibc implementation of strlen for i386 platform.

Cool!

size_t
strlen (const char *str)
{
int cnt;

asm("cld\n" /* Search forward. */
/* Some old versions of gas need `repne' instead of `repnz'. */
"repnz\n" /* Look for a zero byte. */
"scasb" /* %0, %1, %3 */ :
"=c" (cnt) : "D" (str), "0" (-1), "a" (0));

return -2 - cnt;
}


Note: This was extracted from glibc-2.3.6 (sysdeps/i386/strlen.c)

Labels:


About this entry