‘asm’ operand has impossible constraints

来源:互联网 发布:js滑动到底部加载更多 编辑:程序博客网 时间:2024/06/04 08:31

1 环境说明

    Ubuntu14.04.2(64bit)+  gcc-4.8.2

2 问题描述

    当在c中内联汇编时,出现如题错误。

3 可能原因1

    将同一变量同时用于输出寄存器列表可返回值,会导致此错误,只要将其中之一去除就好。

int StrnCmp(const char *cs, const char *ct, int count){   register int __res;     asm(""         :"=a"(__res)    // 输出寄存器列表         :"D"(cs), "S"(ct), "c"(count)         :"si", "di", "cx");    return __res;       // 返回}


4 可能原因2
    将一个指定了寄存器的变量用于输出寄存器列表,会导致此错误,只要将其中之一去除就好。

void StrnCmp(const char *cs, const char *ct, int count){    register int __res asm("ax");// 指定__res使用寄存器eax    asm(""        :"=a"(__res)    // 返回寄存器列表         :"D"(cs), "S"(ct), "c"(count)        :"si", "di", "cx");}


0 0
原创粉丝点击