您的位置:程序门 -> linux/unix社区 -> 内核及驱动程序研究区



c语言嵌入汇编出错,请大家帮忙看看原因呀


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


c语言嵌入汇编出错,请大家帮忙看看原因呀
发表于:2007-10-31 12:02:23 楼主
下面汇编代码出错,是什么原因?
我找了好久都不知道问题在哪里。

test.c:   in   function   `ccmp':
test.c:22:   parse   error   before   ':'   token


#include <stdio.h>
#include <string.h>

int   ccmp(const   char   *s,const   char   *t,int   count)
{
int   res;
_asm_(
              "cld"
              "1:decl   %3"
              "js   2f"
              "lodsb"
              "scasb"
              "jne   3f"
              "testb   %%al,%%al"
              "jne   1b"                                          
              "2:xorl   %%eax,%%eax"
              "jmp   4f"              
              "3:movl   $1,%%eax"
              "jl   4f"
              "negl   %%eax"                            
              "4:"                  
             
              :"=a"(res)                                                     //此处是第22行
              :"d"(t),"s"(s),"c"(count)
              :"eax","edi","esi","ecx"
          );
  return   res;            
}

int   main()
{
char   *s="despite";
char   *t="despair";
int   i,count;
count=strlen(t);
i=ccmp(s,t,count);

printf("-----return   from   asm:%d---------",i);
    return   0;
}
发表于:2007-10-31 14:18:241楼 得分:0
介个汇编看不明白。
发表于:2007-11-05 15:45:212楼 得分:0
#include   <stdio.h>
#include   <string.h>

int   ccmp(const   char   *s,   const   char   *t,   int   count)
{
        int   res;
        __asm__("   cld\n
                            1:decl   %3\n
                            js   2f\n
                            lodsb\n
                            scasb\n
                            jne   3f\n
                            testb   %%al,%%al\n
                            jne   1b\n
                            2:   xorl   %%eax,%%eax     \n
                            jmp   4f     \n
                            3:movl   $1,%%eax   \n
                            jl   4f   \n
                            negl   %%eax   \n
                            4:\n"
                            :   "=a"(res)
                            :   "d"(t),   "s"(s),   "c"(count)
                    );
    return       res;
}

int   main()
{
        char   *s=   "despite";
        char   *t=   "despair";
        int   i,count;

        count=strlen(t);
        i=ccmp(s,t,count);

        printf(   "-----return   from   asm:   %d   ---------",i);
        return       0;
}

再试试?
我觉得是
                            :   "eax   ",   "edi   ",   "esi   ",   "ecx   "  
这一行没写对。


快速检索

最新资讯
热门点击