Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/60.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xcode/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C 内联汇编代码错误_C_Inline Assembly - Fatal编程技术网

C 内联汇编代码错误

C 内联汇编代码错误,c,inline-assembly,C,Inline Assembly,有人知道会发生什么吗 编辑: 永远不要忘记操作数之间的逗号。。。也 cmp op1 op2 jle环路 仅当op2小于或等于op1时才会跳转到循环 以下是正在工作的代码: addup.c: Assembler messages: addup.c:10: Error: junk `%eax' after register addup.c:12: Error: junk `%edx' after register 明白了,你忘了在addl和cmpl:)的操作数之间指定逗号)花了太长时间才注意到,太

有人知道会发生什么吗

编辑:

永远不要忘记操作数之间的逗号。。。也

cmp op1 op2 jle环路

仅当op2小于或等于op1时才会跳转到循环

以下是正在工作的代码:

addup.c: Assembler messages:
addup.c:10: Error: junk `%eax' after register
addup.c:12: Error: junk `%edx' after register

明白了,你忘了在
addl
cmpl
:)的操作数之间指定逗号)花了太长时间才注意到,太困了可能在我看来,你正在编译的文件不是你认为正在编译的文件。但是
ret
在循环过程中不会被修改你是什么意思?@keshlamyes。它应该是addl%1%0,但仍会收到错误@mangusta@Jianchen为什么不将x添加到ret,然后将y添加到ret,
“添加%1%0\t\n”“添加%2%0\t\n”
addup.c: Assembler messages:
addup.c:10: Error: junk `%eax' after register
addup.c:12: Error: junk `%edx' after register
int asm_sum(int x, int y)
{
    int ret = 0;

    __asm__ __volatile__(   "loop:\t\n"
                            "   addl %1, %0\n\t"
                            "   inc %1\n\t"
                            "   cmp %2, %1\n\t"
                            "   jle loop"
                            :"=r"(ret)
                            :"r"(x), "r"(y)
                         );
    return ret;
}