C变量的内容复制到寄存器(GCC) [英] Copy content of C variable into a register (GCC)
本文介绍了C变量的内容复制到寄存器(GCC)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
由于我很新的GCC,我面临的内联汇编code的一个问题。问题是,我无法弄清楚如何复制C变量(其类型为 UINT32
)的进入寄存器的内容 EAX
。我曾尝试低于code:
Since I'm very new to GCC, I'm facing a problem in inline assembly code. The problem is that I'm not able to figure out how to copy the contents of a C variable (which is of type UINT32
) into the register eax
. I have tried the below code:
__asm__
(
// If the LSB of src is a 0, use ~src. Otherwise, use src.
"mov $src1, %eax;"
"and $1,%eax;"
"dec %eax;"
"xor $src2,%eax;"
// Find the number of zeros before the most significant one.
"mov $0x3F,%ecx;"
"bsr %eax, %eax;"
"cmove %ecx, %eax;"
"xor $0x1F,%eax;"
);
但 MOV $ SRC1,EAX%;
不起作用
有人能提出一个解决的办法?
Could someone suggest a solution to this?
推荐答案
我猜测你正在寻找的是的扩展组件例如:
I guess what you are looking for is extended assembly e.g.:
int a=10, b;
asm ("movl %1, %%eax; /* eax = a */
movl %%eax, %0;" /* b = eax */
:"=r"(b) /* output */
:"r"(a) /* input */
:"%eax" /* clobbered register */
);
在上面的例子中,我们做了的值b
等于的 A
使用汇编指令和 EAX
注册:
In the example above, we made the value of b
equal to that of a
using assembly instructions and eax
register:
int a = 10, b;
b = a;
请参阅内嵌批注。
注意:
mov $4, %eax // AT&T notation
mov eax, 4 // Intel notation
有关GCC 内联汇编一个良好的阅读环境。
这篇关于C变量的内容复制到寄存器(GCC)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文