Meh*_*dad 12 gcc inline-assembly intel-syntax
为什么这段代码没有设置temp
为1?我该怎么做呢?
int temp;
__asm__(
".intel_syntax;"
"mov %0, eax;"
"mov eax, %1;"
".att_syntax;"
: : "r"(1), "r"(temp) : "eax");
printf("%d\n", temp);
Run Code Online (Sandbox Code Playgroud)
Car*_*rum 13
我想temp
,你想成为一个输出,而不是一个输入.尝试:
__asm__(
".intel_syntax;"
"mov eax, %1;"
"mov %0, eax;"
".att_syntax;"
: "=r"(temp)
: "r"(1)
: "eax");
Run Code Online (Sandbox Code Playgroud)
此代码执行您要实现的目标.我希望这可以帮助你:
#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);
}
Run Code Online (Sandbox Code Playgroud)
小智 6
您必须将参数传递给GCC汇编程序.
gcc.exe -masm=intel -c Main.c
gcc.exe Main.o -oMain.exe
Run Code Online (Sandbox Code Playgroud)
你有这样的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;
}
Run Code Online (Sandbox Code Playgroud)
不要忘记为asm()关键字中的每个变量添加前缀下划线(_),否则它将无法识别它.
关键字asm()对每个十六进制整数使用前缀'0x',而不是后缀'h'.
归档时间: |
|
查看次数: |
20822 次 |
最近记录: |