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?
);
}
现在我不知道为什么这不起作用. Gcc表示:错误:'asm'操作数具有不可能的约束"我一直在关注gcc内联汇编教程,尽管这是将参数从c代码导入内联汇编块的正确方法.
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.
我还使用为32位x86构建的gcc交叉编译器.
Also I use gcc cross compiler built for 32 bit x86.
推荐答案
使用"r"约束会强制编译器在将该临时寄存器用于您的mov
指令之一之前,将参数加载到临时寄存器中.根本没有4个暂存寄存器可用.
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. There simply aren't 4 scratch registers available.
改为使用"g"约束.无论如何,这效率更高,因为编译器将能够使用对目标寄存器的偏移量为帧指针的内存访问来直接在mov
指令中访问参数,而不是将其移至暂存器中,然后将暂存器移至最终寄存器中.目的地.
Use the "g" constraint instead. 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.
这篇关于Gcc内联汇编的“'asm'操作数具有不可能的约束"是什么?意思是?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!