AT&T inline Assembly Constraint

本文详细介绍了GCC编译器中如何通过不同的约束符指定变量在汇编代码中的寄存器存储方式,包括通用寄存器的选择及m约束符的使用,以及变量在输入输出时的匹配约束,旨在提高代码效率。
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.

转载于:https://my.oschina.net/incarnation/blog/56723

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值