由于我是 GCC 的新手,我在内联汇编代码中遇到了问题。问题是我不知道如何将 C 变量(UINT32
类型)的内容复制到寄存器 eax
中。我试过下面的代码:
__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;
不起作用。
有人可以对此提出解决方案吗?
最佳答案
我猜你要找的是 extended assembly例如:
int a=10, b;
asm ("movl %1, %%eax; /* eax = a */
movl %%eax, %0;" /* b = eax */
:"=r"(b) /* output */
:"r"(a) /* input */
:"%eax" /* clobbered register */
);
在上面的示例中,我们使用汇编指令和 eax
寄存器使 b
的值等于 a
的值:
int a = 10, b;
b = a;
请查看内联评论。
注意:
mov $4, %eax // AT&T notation
mov eax, 4 // Intel notation
一本关于 inline assembly 的好书在 GCC 环境中。
关于将 C 变量的内容复制到寄存器 (GCC),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14494818/