c - 错误: can't find a register in class ‘GENERAL_REGS’ while reloading ‘asm’

标签 c inline-assembly

__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/

相关文章:

c - 我如何在 C 函数中递增一维数组的元素

字符变量[] = {0};和 char var[1];在 C 中等价?

c - 为什么下面的代码中使用 CAN_TypeDef 类型的指针?

c - Linux,使用Socket和读写功能,数据可以分片吗?

c - 快速问题,为什么 scanf_s 在运行时抛出异常?我很困扰

c - 在 gcc 的内联 asm 中使用 printf 函数

c++ - 内联 asm 分配给 'FS:0' : handler not registered as safe handler

c++ - C++中的比较和交换

c - parasoft c++ 测试 - 编译内联汇编代码

gcc - Cortex-M3 的 CMSIS 库中的数据内存屏障 (DMB)