简体   繁体   English

不同编译器生成的汇编代码?

[英]Assembly code generated by different compilers?

I have started studying assembly for ARM arch. 我已经开始研究ARM拱门的装配。 I read in some pdf files, and small tutorials in net . 我读了一些pdf文件,并在net中读了一些小教程。 I understood the code there. 我了解那里的代码。 But when i wrote a simple hello world program in GCC then it gave a assembly file whose contents looked very different from what i learnt in pdf and internet.(I mean mainly the assembly directives). 但是当我用GCC编写一个简单的hello world程序时,它提供了一个汇编文件,其内容看上去与我在pdf和Internet中学到的内容大不相同(我主要指的是汇编指令)。

SO , it means that assembly code generated by different compilers is different(all use different way f writing the assembler directives and some other things). 因此,这意味着由不同的编译器生成的汇编代码是不同的(都使用不同的方式来编写汇编器指令和其他一些东西)。 As what ever tutorial i read in internet i guess they were based on Kiel compiler. 正如我在互联网上阅读的教程一样,我想它们是基于Kiel编译器的。

If what i wrote above is true, Then according to which compiler shall i learn assembly language for ARM. 如果我上面写的是对的,那么我应该根据哪个编译器学习ARM的汇编语言。

You should learn assembly according to the instruction set and architecture of the machine you have (and the directives according to the assembler you're using). 您应该根据所拥有的机器的指令集和体系结构(以及所使用的汇编器的指令)来学习汇编。 Two of the principal reasons for learning assembly are to understand an instruction set, and to do things that just aren't possible in a higher-level language - looking at the subset of functionality that maps to that higher language isn't all that useful in either respect, even less so if compiler optimisation has transformed it beyond recognition. 学习汇编的两个主要原因是理解指令集,并完成高级语言无法完成的工作-查看映射到该高级语言的功能子集并没有什么用处在任何一个方面,如果编译器优化已将其转换到无法识别的程度,则更是如此。 I'd say this is particularly true on ARM, where the instruction set can do all sorts of wacky things - it's quite a different paradigm from higher languages and best tackled on its own terms. 我要说的是在ARM上尤其如此,其中指令集可以完成各种古怪的事情-这是与高级语言完全不同的范例,并且可以按自己的方式进行最佳处理。

As you've noticed, looking at compiled output is good for learning how compilers work - different compilers with different optimisation strategies can sometimes end up implementing the same high-level code in very different ways. 正如你已经注意到了,看着编译的输出很好的学习如何编译工作-不同的编译器不同的优化策略,有时可以结束了非常不同的方式实现相同的高级代码。

That said, compiled code can be handy for the very basics like "what does this loop look like in assembly" - in which case the choice of compiler shouldn't matter at all since you'll want to keep things as simple as possible. 就是说,编译后的代码对于“循环在汇编中看起来像什么”这样的非常基础的代码来说可能非常方便-在这种情况下,编译器的选择根本不重要,因为您将希望使事情尽可能简单。 That means disable all optimisations, stick to standard C (personally I'd even go for ANSI C over C99), and keep the code of interest in small separate functions so it's easier to make sense of the disassembly. 这意味着禁用所有优化,坚持使用标准C(我个人甚至希望通过C99来使用ANSI C),并将感兴趣的代码保留在较小的单独函数中,以便更轻松地理解反汇编。 Past the basics, though, this is less "learning assembly language" and more "learning about C in the context of assembly language". 但是,从基础上讲,这不是“学习汇编语言”,而是“在汇编语言上下文中学习C”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM