免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1645 | 回复: 1

[实践] ubuntu下进行汇编语言在C中的嵌入汇编出现了问题 [复制链接]

论坛徽章:
0
发表于 2013-02-23 10:35 |显示全部楼层
程序如下:
#include<stdio.h>
int strCmp(char *cs,char *ct,int count)
{
    int _res;
    _asm_("cld\n"  
            "1:\n"
            "decl %3\n"  
            "js 2f\n"  
            "lodsb\n"  
            "scasb\n"
            "jne 3f\n"  
            "testb %%al,%%al\n"  
            "jne 1b\n"
            "2:\n"
            "xorl %%eax,%%eax\n"  
            "jmp 4f\n"
            "3:\n"
            "movl $1,%%eax\n"  
            "jl 4f\n"
            "negl %%eax\n"  
            "4:"
            :"=a" (_res) :"D"(cs),"S"(ct),"c"(count) :"si","di","cx");
    return _res;
}
main()
{
    char*p="1234";
    char*q="4321";
    char*r="1234";
    printf("input:%s,%s.we get output:%d\n",p,q,strCmp(p,q,4));
    printf("input:%s,%s.we get output:%d\n",q,p,strCmp(q,p,4));
    printf("input:%s,%s.we get output:%d\n",p,r,strCmp(p,r,4));
    return 0;
}



错误如下:
zh.c: 在函数‘strCmp’中:
zh.c:22:13: 错误: expected ‘)’ before ‘:’ token
请高手指教!

论坛徽章:
0
发表于 2013-02-23 15:33 |显示全部楼层
我前两天编译C程序的时候,遇到过
调用 goto时,后面一定要有执行语句.

所以,你的跳转点4后面是否加上一句执行code,应该就OK
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP