Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/assembly/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
以下是VS2012的一些汇编代码,如何在gcc上编写? #包括 int main() { int a=0; /*我如何在gcc上写呢*/ __asm{ mova,2; 增加a、4; } printf(“%d\n”,a); 返回0; }_C_Assembly - Fatal编程技术网

以下是VS2012的一些汇编代码,如何在gcc上编写? #包括 int main() { int a=0; /*我如何在gcc上写呢*/ __asm{ mova,2; 增加a、4; } printf(“%d\n”,a); 返回0; }

以下是VS2012的一些汇编代码,如何在gcc上编写? #包括 int main() { int a=0; /*我如何在gcc上写呢*/ __asm{ mova,2; 增加a、4; } printf(“%d\n”,a); 返回0; },c,assembly,C,Assembly,这是VS2012的一些汇编代码,如何在gcc上编写 #include <stdio.h> int main () { int a = 0 ; /*How can I write it on gcc*/ __asm { mov a, 2 ; add a, 4 ; } printf ("%d\n",a ); return 0 ; } int main() { int a=0; /*我如何在gcc上写呢

这是VS2012的一些汇编代码,如何在gcc上编写
#include <stdio.h>

int main ()
{
    int a = 0 ;
    /*How can I write it on gcc*/
    __asm {
         mov a, 2 ;
         add a, 4 ;
    }
    printf ("%d\n",a );
    return 0 ;
}
int main() { int a=0; /*我如何在gcc上写呢*/ 挥发性物质 ( mov$2,%0\n 添加$4,%0\n :“=r”(a)/*输出操作数*/ :/*输入操作数*/ :/*被删除的操作数*/ ); printf(“%d\n”,a); 返回0; }
请阅读了解更多信息。

例如,创建另一个文件
fun.s
,并执行以下操作

#include <stdio.h>

int main ()
{
    int a = 0 ;
    /*How can I write it on gcc*/
    asm volatile 
    (
         "mov $2, %0\n"
         "add $4, %0\n"
         : "=r"(a) /* output operand */
         : /* input operand */
         : /* clobbered operands */
    );
    printf ("%d\n",a );
    return 0 ;
}
然后在主函数中调用它

int main(){
我的乐趣(;
}


像这样编译:
g++-o prog-fun.s main.cpp

您可以在gcc中编写它,如下所示:

.global my_fun #to show where program should start
     my_fun:
     push %ebp  #save stack ptr
     #function body
     pop %ebp   #recover stack ptr
 ret
#包括
int main()
{
int a=0;
/*我如何在gcc上写呢*/
__asm\uuuuuu挥发性(
movl$2,%0\n\t
添加$4,%0\n\t
:“=r”(a)/*=r(egister),=m(emory)在这里都很好*/
);
printf(“%d\n”,a);
返回0;
}

向谷歌索要数百万个样本中的任何一个,然后复制样式。我在谷歌上输入了“gcc内联asm”,得到了19400000个结果。也许你需要再努力一点?嗯..你的代码有些错误..你能给我一些正确的代码吗?实际上,
“=r”(a)
是一个输出操作数。谢谢你指出这一点,我已经修正了答案。很抱歉给您带来不便。谢谢您。这就是我需要的
#include <stdio.h>

int main ()
{
  int a = 0 ;
  /*How can I write it on gcc*/
  __asm__ __volatile__ (
    "movl $2, %0\n\t"
    "addl $4, %0\n\t"
    :"=r"(a) /* =r(egister), =m(emory) both fine here */
  );
  printf ("%d\n",a );
  return 0 ;
}