简体   繁体   English

Gcc内联汇编“'asm'操作数有什么不可能约束”是什么意思?

[英]Gcc inline assembly what does “'asm' operand has impossible constraints” mean?

I have this below code within function: 我在函数中有以下代码:

void makeSystemCall(uint32_t num, uint32_t param1, uint32_t param2, uint32_t param3){
    asm volatile (
        "mov %0, %%eax\n\t"//Move num to eax
        "mov %1, %%ebx\n\t"//Move param1 to ebx
        "mov %2, %%ecx\n\t"//Move param2 to ecx
        "mov %3, %%edx\n\t"//Move param3 to edx
        "int $0x80"//Call interrupt. Data in eax, ebx, ecx and edx
        : //No output params
        : "r" (num), "r" (param1), "r" (param2), "r" (param3)//Input params
        : "%eax", "%ebx", "%ecx", "%edx" //This handles register state pushing and popping?
    );
}

Now I have no idea why this doesn't work. 现在我不知道为什么这不起作用。 Gcc says: "error: 'asm' operand has impossible constraints" I have been following gcc inline assembly tutorials and I though that this would be correct way to take parameters from c code to inline assembly block. Gcc说:“错误:'asm'操作数有不可能的约束”我一直在关注gcc内联汇编教程,我认为这是将参数从c代码转换为内联汇编块的正确方法。

Also I use gcc cross compiler built for 32 bit x86. 我也使用为32位x86构建的gcc交叉编译器。

Using the "r" constraint forces the compiler to load the parameter into a scratch register before using that scratch register for one of your mov instructions. 使用“r”约束会强制编译器将参数加载到暂存寄存器中,然后再将该临时寄存器用于其中一条mov指令。 There simply aren't 4 scratch registers available. 根本没有4个临时寄存器。

Use the "g" constraint instead. 请改用“g”约束。 This is more effiecient anyway, since the compiler will be able to access the argument directly in your mov instructions using a frame pointer offsetted memory access onto the destination register instead of doing that into a scratch register then moving the scratch register into the ultimate destination. 无论如何,这更有效,因为编译器将能够使用帧指针偏移内存访问到目标寄存器而直接在mov指令中访问参数,而不是将其作为暂存寄存器,然后将暂存寄存器移动到最终目标。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM