首页 > 解决方案 > 我需要将我用 C(.c) 编写的代码转换为汇编(.asm)。我对用 C 编写非常陌生,现在我需要学习如何用汇编编写

问题描述

我需要将我的 C 代码转换为程序集

这是我需要转换为汇编(.asm)的C代码

int main()
{
   //Variables that stores the numbers
   int num1, num2, num3;
   // Variable that stores the result
   int result;
   // Asking the user to input the value of num1
   printf("Enter the first number:");
   scanf("%d",&num1);
   // Asking the user to input the value of num2
   printf("Enter the second number:");
   scanf("%d",&num2);
   // Asking the user to input the value of num3
   printf("Enter the third number: ");
   scanf("%d",&num3);
   //Performing the operation
   result = num3 - (num1 + num2);
   //Printing the result
   printf("The value of result is: %d",result);
   return 0;
}

标签: cassembly

解决方案


那么理论上你可以使用 gcc 编译它并命令它生成 asm 列表(这将是汇编程序),所以你可以将它的扩展名更改为 .asm (https://www.systutorials.com/240/generate-a-混合源和程序集列表使用 gcc/ )

不过一般来说,在汇编中包含 scanf 和 printf 或任何库函数是个坏主意(因为它们在 asm 中可能非常长,特别是系统调用,例如读/写/打开,printf)。

万一你在大学里有人要求你用 ASM 写一些东西,他们会知道这不是你写的。

同样从标题来看,盯着 C 列表学习 ASM 是不可能的(例如由于过程调用上的堆栈操作)。


推荐阅读