zqz_joshua 发表于 2005-1-22 18:51:26

一个关于 strstr()的理解问题

如下,我想该怎样去阅读类似__volatile__的代码,谢谢:

***************************

char * strstr(const char * cs,const char * ct)
{
int        d0, d1;
register char * __res;
__asm__ __volatile__(
        "movl %6,%%edi\n\t"
        "repne\n\t"
        "scasb\n\t"
        "notl %%ecx\n\t"
        "decl %%ecx\n\t"        /* NOTE! This also sets Z if searchstring='' */
        "movl %%ecx,%%edx\n"
        "1:\tmovl %6,%%edi\n\t"
        "movl %%esi,%%eax\n\t"
        "movl %%edx,%%ecx\n\t"
        "repe\n\t"
        "cmpsb\n\t"
        "je 2f\n\t"                /* also works for empty string, see above */
        "xchgl %%eax,%%esi\n\t"
        "incl %%esi\n\t"
        "cmpb $0,-1(%%eax)\n\t"
        "jne 1b\n\t"
        "xorl %%eax,%%eax\n\t"
        "2:"
        :"=a" (__res), "=&c" (d0), "=&S" (d1)
        :"0" (0), "1" (0xffffffff), "2" (cs), "g" (ct)
        :"dx", "di");
return __res;
}

WeiMingzhi 发表于 2005-1-23 09:38:27

sd_2001 发表于 2005-1-24 15:54:55

给翻译以下

=============
输入参数部分
=============
eax = 0
ecx = 0xffffffff
esi = cs
=============
主体
=============
movl ct, %edi
repne
scasb
notl %ecx
decl %ecx
movl %ecx,%edx

again:

movl ct,%edi
movl %esi,%eax
movl %edx,%ecx
repe
cmpsb

je exit

xchgl %eax,%esi
incl %esi
cmpb $0, -1(%eax)

jne again

xorl %eax,%eax

exit:

==============
输出参数
==============
__res = eax

zqz_joshua 发表于 2005-1-25 19:28:34

非常感谢!!!
哪有相关的电子入门/讲解资料可参考?
这个有人说是用Mips的compiler做的.


给翻译以下

=============
输入参数部分
=============
eax = 0
ecx = 0xffffffff
esi = cs                     <======这个是做什么???



=============
主体
=============
movl ct, %edi
repne
scasb
notl %ecx
decl %ecx
movl %ecx,%edx

again:

movl ct,%edi
movl %esi,%eax
movl %edx,%ecx
repe
cmpsb

je exit

xchgl %eax,%esi
incl %esi
cmpb $0, -1(%eax)

jne again

xorl %eax,%eax

exit:

==============
输出参数
==============
__res = eax
页: [1]
查看完整版本: 一个关于 strstr()的理解问题