如何访问C变量的内联汇编操作 [英] How to access c variable for inline assembly manipulation
问题描述
有鉴于此code:
的#include<&stdio.h中GT;INT主(INT ARGC,字符** argv的)
{
INT X = 1;
的printf(你好X =%d个\\ N,X);
}
我想内联汇编访问和操作变量x。理想情况下,我想用内联汇编来改变其值。 GNU汇编器,并使用AT&安培; T语法
ASM挥发性(MOVL $ 0%(有些)
:[有些]= R(X)
);
在此之后,x包含0。注意,这个作品只在海湾合作委员会。其他编译器需要不同的语法
例如,对于MSVC你这样做:
__ ASM MOV X,0
和 X
将价值 0
该语句之后。
请注明您要使用的编译器。
另外请注意,这样做会限制你的程序编译,只有特定的编译器,汇编器组合,并将朝着一个特定的架构只管。
Given this code:
#include <stdio.h>
int main(int argc, char **argv)
{
int x = 1;
printf("Hello x = %d\n", x);
}
I'd like to access and manipulate the variable x in inline assembly. Ideally, I want to change its value using inline assembly. GNU assembler, and using the AT&T syntax.
asm volatile("movl $0, %[some]"
: [some] "=r" (x)
);
after this, x contains 0. Note, this works in GCC only. Other compilers require different syntax
For example, for MSVC you do this:
__asm mov x, 0
and x
will have the value of 0
after this statement.
Please specify the compiler you would want to use.
Also note, doing this will restrict your program to compile with only a specific compiler-assembler combination, and will be targetted only towards a particular architecture.
这篇关于如何访问C变量的内联汇编操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!