- 论坛徽章:
- 0
|
- #include <stdio.h>
- #include <string.h>
- int lenstr(char *p)
- {
- __asm__ __volatile__(
- "movb $0, %%al\n\t"
- "movl $0XFFFFFFFF, %%ecx\n\t"
- "cld\n\t"
- "repne scasb\n\t"
- "negl %%ecx\n\t"
- "subl $2, %%ecx\n\t"
- "movl %%ecx, %%edi\n\t"
- :"=&D"(p)
- :"0"(p)
- :"eax", "ecx"
- );
- return (int)p;
- }
- int main(int argc, char* argv[])
- {
- char * p = "i am a string!";
- printf("%s=%d\n", p, lenstr(p));
- printf("%s=%d\n", p, strlen(p));
- return 0;
- }
- 13:17:10 root /mnt/windows/code/user-prg/mixed-c-asm # gcc strlen.c
- 13:17:30 root /mnt/windows/code/user-prg/mixed-c-asm # ./a.out
- i am a string!=14
- i am a string!=14
- 13:17:32 root /mnt/windows/code/user-prg/mixed-c-asm # uname -a
- Linux linux-2148 2.6.16.21-0.8-default #1 Mon Jul 3 18:25:39 UTC 2006 i686 i686 i386 GNU/Linux
- 这样也算是没有定义变量吧
复制代码 |
|