when use “r" as constraint, gcc will store output or input in GPR (General Purpose Register). When specifying the GPR, list following:
"r" GPR
"a" %eax, %ax, %al
"b" %ebx, %bx, %bl
"c" %ecx, %cx, %cl
"d" %edx, %dx, %dl
"S" %esi, %si
"D" %edi, %di
when you want a C variable updating in asm section, but without a register holding the value, use constraint "m", which will read memory location in register, update and write back to memory.
when a single variable serves both input and output, it match constraint, which specify the variable use the same register as matching. for example:
__asm__ volatile (
"movl %0,%0\n\t"
:"=a"(var)
:"0"(var)
:
);
it can use register more effective.
constraint modifier, for more control over the effect of constraint.
"=" write-only
"&" operand is an earlyclobber, which will be modified before the asm instruction finished.
本文详细介绍了GCC编译器中如何通过不同的约束符指定变量在汇编代码中的寄存器存储方式,包括通用寄存器的选择及m约束符的使用,以及变量在输入输出时的匹配约束,旨在提高代码效率。

2万+

被折叠的 条评论
为什么被折叠?



