如何使用 Intel 语法内联汇编在 GCC 中设置变量? [英] How to set a variable in GCC with Intel syntax inline assembly?
本文介绍了如何使用 Intel 语法内联汇编在 GCC 中设置变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
为什么这段代码没有将 temp
设置为 1?我该怎么做?
Why doesn't this code set temp
to 1? How do I actually do that?
int temp;
__asm__(
".intel_syntax;"
"mov %0, eax;"
"mov eax, %1;"
".att_syntax;"
: : "r"(1), "r"(temp) : "eax");
printf("%d
", temp);
推荐答案
我认为,您希望 temp
成为输出,而不是输入.试试:
You want temp
to be an output, not an input, I think. Try:
__asm__(
".intel_syntax;"
"mov eax, %1;"
"mov %0, eax;"
".att_syntax;"
: "=r"(temp)
: "r"(1)
: "eax");
这篇关于如何使用 Intel 语法内联汇编在 GCC 中设置变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文