并排 C、x86 程序
有没有什么地方可以找到非常简单的 C 和 x86 程序的并行示例?到目前为止,我在 Internet 上找到的示例似乎直接从“这是 x86 中的 Hello World”跳到“编写您自己的操作系统!”当你执行诸如调用函数之类的操作时,我很难理解会发生什么。
Is there anywhere I can find side-by-side examples of dead simple C and x86 programs? The examples I've found so far on the Internet seem to jump straight from "here's Hello World in x86" to "write your own operating system!" I'm having trouble internalizing what has to happen when you do things like call a function.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我建议您查看 GCC 的中间汇编输出,例如调用
然后查看
,大多数情况下,更小且更易于理解的汇编是通过优化生成的,因此您宁愿使用
I would recommend a look at GCC's intermediate assembly output, for example call
then look at a.s
Most of the time, smaller and easier to understand assembly is generated by optimizing, so you would rather use
如果您指的是 x86 汇编语言,请使用 objdump --disassemble myprog (在任何 GNU 系统上)来显示 C 程序生成的汇编语言。如果您的系统没有 objdump,您可以使用 ndisasm。
If you mean x86 assembly language, use
objdump --disassemble myprog
(on any GNU system) to show the assembly language generated by your C program. If your system doesn't have objdump, you can use ndisasm.假设您指的是 x86 汇编器,那么使用 gcc 您可以使用 gcc -S yourhelloworldprogram.c 来获取汇编器输出。对于 Visual Studio,您可以通过以下方式获取汇编器输出: 如何从 VS2005 中的 C 文件获取汇编程序输出
Assuming you mean x86 assembler then with gcc you can use
gcc -S yourhelloworldprogram.c
to get assembler output. For Visual Studio you can get assembler output by following this: How do I get the assembler output from a C file in VS2005我推荐 ddd。您可以同时显示 C 源代码(如果您使用调试符号构建)和机器代码。您还可以交互式地单步执行代码来探测寄存器和内存值。一个很棒的学习工具。
I reccommend ddd. You can have the both C sources (if you built with debug symbols) and the machine code showing. You can also step over the code interactively probing register and memory values. A great learning tool.
在 gcc 上,您可以使用
-save-temps -fverbose-asm
选项,该选项比-S
选项更好,因为它仍然生成目标文件,并且您还可以获得预处理器文件。 verbose-asm 也很重要,因为它向汇编输出添加注释,从而在程序的函数和变量名称与生成的汇编代码之间建立链接。特别是在优化生成时,通常很难在源 C 和程序集之间建立链接。On gcc you can use the
-save-temps -fverbose-asm
options which is better than the-S
option because it still generates the object file and you get also the preprocessor file. The verbose-asm is also important because it adds comments to the assembly output that make the link between the function and variable names of your program and the generated assembly code. Especially when generating with optimization it often is difficult to make the link between the source C and the assembly.