为什么没有这个代码设定temp
为1? 实际上,我怎么做呢?
int temp;
__asm__(
".intel_syntax;"
"mov %0, eax;"
"mov eax, %1;"
".att_syntax;"
: : "r"(1), "r"(temp) : "eax");
printf("%d\n", temp);
为什么没有这个代码设定temp
为1? 实际上,我怎么做呢?
int temp;
__asm__(
".intel_syntax;"
"mov %0, eax;"
"mov eax, %1;"
".att_syntax;"
: : "r"(1), "r"(temp) : "eax");
printf("%d\n", temp);
你想temp
为输出,而不是输入,我想。 尝试:
__asm__(
".intel_syntax;"
"mov eax, %1;"
"mov %0, eax;"
".att_syntax;"
: "=r"(temp)
: "r"(1)
: "eax");
此代码你想达到的目标。 我希望这可以帮助你:
#include <stdio.h>
int main(void)
{
/* Compile with C99 */
int temp=0;
asm
( ".intel_syntax;"
"mov %0, 1;"
".att_syntax;"
: "=r"(temp)
: /* no input*/
);
printf("temp=%d\n", temp);
}
你必须通过一个参数传递给GCC汇编。
gcc.exe -masm=intel -c Main.c
gcc.exe Main.o -oMain.exe
你有C代码是这样的:
#include <conio.h>
#include <stdio.h>
int myVar = 0;
int main(int argc, char *argv[])
{
asm("mov eax, dword ptr fs:[0x18]");
asm("mov eax, dword ptr ds:[eax+0x30]");
asm("movzx eax, byte ptr ds:[eax+0x2]");
asm("mov _myVar, eax");
if(myVar == 1) printf("This program has been debugged.\r\n");
printf("Welcome.\r\n");
getch();
return 0;
}
不要忘了加上前缀下划线(_)为每一个变量ASM()的关键字,否则将无法识别它。
和关键字ASM()使用前缀加“0x”为每一个十六进制整数,没有后缀“H”。