如何使用英特尔语法内联汇编在GCC中设置变量? [英] How to set a variable in GCC with Intel syntax inline assembly?
本文介绍了如何使用英特尔语法内联汇编在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\n", 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");
这篇关于如何使用英特尔语法内联汇编在GCC中设置变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文