__asm__ (
"loop:\n\t"
"movl $1,%3\n\t"
"movl $0, %6\n"
"start:\n\t"
"movl (%1,%3,4),%4\n\t"
"movl -4(%1, %3, 4), %5\n\t"
"cmpl %4, %5\n\t"
"jle next\n\t"
"xchgl %4, %5\n\t"
"movl %4, (%1, %3, 4)\n\t"
"movl %5, -4(%1, %3, 4)\n\t"
"movl $1, %6\n"
"next:\n\t"
"incl %3\n\t"
"cmpl %3, %2\n\t"
"jge start\n\t"
"cmpl $0, %6\n\t"
"je end\n\t"
"jmp loop\n"
"end: \n\t"
:"=r"(input_array)
:"r"(input_array), "r"(size-1), "r"(1), "r"(0), "r"(0), "r"(0)
);
我得到:
error: can't find a register in class ‘GENERAL_REGS’ while reloading ‘asm’ error: ‘asm’ operand has impossible constraints
最佳答案
您必须记住,这些机器的寄存器数量有限。并且它实际上可能会用完 - 这就是您收到的错误告诉您的信息。
在 x86 上,只有 8 个通用寄存器。 esp
是为堆栈指针保留的。 ebp
可能用作基指针。这样就只剩下 6 个了。
但是,您的内联汇编代码片段似乎需要 7 个寄存器?你的数量还不够。
所以解决方案是您需要使用更少的寄存器。将一些参数放入内存或更改算法...
关于c - 错误: can't find a register in class ‘GENERAL_REGS’ while reloading ‘asm’ ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8275859/