汇编编程比高级语言(如c)花费更长的时间,更难编程,这似乎是一种主流观点。因此,出于这些原因以及更好的可移植性,似乎建议或假设用高级语言编写更好。

最近我一直在用x86汇编语言写作,我开始意识到这些原因可能都不是真的,除了可移植性。也许这更多的是一个熟悉的问题,知道如何写好汇编。我还注意到在汇编中编程与在HLL中编程有很大的不同。也许一个好的、有经验的汇编程序员可以像一个有经验的C程序员用C写程序一样轻松、快速地编写程序。

也许是因为汇编编程与hll有很大的不同,因此需要不同的思维、方法和方式,这使得对不熟悉的人编写程序看起来非常尴尬,因此给汇编编程带来了不好的名声。

如果可移植性不是问题,那么C语言比NASM这样的优秀汇编器有什么优势呢?

编辑: 我只是想指出。当你用汇编语言写作时,你不必只写指令代码。您可以使用宏、过程和您自己的约定来进行各种抽象,使程序更模块化、更可维护、更易于阅读。这就是熟悉如何编写好的汇编的原因。


当前回答

因为事情总是这样:时间流逝,美好的东西也会消逝:(

但是当你编写asm代码时,这与编写高级语言的感觉完全不同,尽管你知道它的效率要低得多。这就像你是一个画家:你可以自由地画任何你喜欢的东西,完全没有限制(嗯,只有CPU的功能)……这就是我喜欢它的原因。很遗憾这种语言消失了。但只要有人还记得它并对它进行编码,它就永远不会消亡!

其他回答

与高级语言相比,ASM的易读性很差,而且实际上难以维护。

此外,ASM开发人员比其他更流行的语言(如C)要少得多。

此外,如果您使用高级语言,并且有新的ASM指令可用(例如SSE),您只需要更新您的编译器,您的旧代码就可以轻松使用新的指令。

如果下一个CPU有两倍多的寄存器呢?

这个问题的反义词是:编译器提供了什么功能?

我怀疑你能够/想要/应该比gcc -O3更好地优化你的ASM。

早期的发现之一(你可以在布鲁克斯的《神秘的人月》中找到,这是20世纪60年代的经验)是,人们使用一种语言的效率或多或少与使用另一种语言的效率一样高,每天调试的代码行数也差不多。显然,这并不是普遍的事实,如果做得太过分,可能会崩溃,但对于Brooks时代的高级语言来说,这是普遍的事实。

因此,提高工作效率的最快方法是使用一行代码就能做更多工作的语言,这确实有效,至少对于像FORTRAN和COBOL这样复杂的语言,或者给出一个更现代的例子C。

浏览这些答案,我敢打赌9/10的回复者从未使用过组装。

这是一个经常出现的老问题,你得到的答案都是一样的,而且大多是错误的答案。如果不是为了便携性,我仍然会自己组装所有的东西。即便如此,我还是用C编写代码,就像用汇编一样。

我用汇编编程已经有一个月了。我经常用C写一段代码,然后把它编译成汇编来帮助我。也许我没有充分利用C编译器的优化功能,但似乎我的C asm源包含不必要的操作。所以我开始看到,一个好的C编译器胜过一个好的汇编编码器的说法并不总是正确的。

Anyways, my assembly programs are so fast. And the more I use assembly the less time it takes me to write out my code because it's really not that hard. Also the comment about assembly having poor legibility is not true. If you label your programs correctly and make comments when there is additional elaboration needed you should be all set. In fact in ways assembly is more clear to the programmer because they are seeing what is happening at the level of the processor. I don't know about other programmers but for me I like knowing what's happening, rather than things being in a sort of black box.

With that said the real advantage of compilers is that a compiler can understand patterns and relationships and then automatically code them in the appropriate locations in the source. One popular example are virtual functions in C++ which requires the compiler to optimally map function pointers. However a compiler is limited to doing what the maker of the compiler allows the compiler to do. This leads to programmers sometimes having to resort to doing bizarre things with their code , adding coding time, when they could have been done trivially with assembly.

Personally I think the marketplace heavily supports high level languages. If assembly language was the only language in existence today then their would be about 70% less people programming and who knows where our world would be, probably back in the 90's. Higher level languages appeal to a broader range of people. This allows a higher supply of programmers to build the needed infrastructure of our world. Developing nations like China and India benefit heavily from languages like Java. These countries will fast develop their IT infrastructure and people will become more interconnected. So my point is that high level languages are popular not because they produce superior code but because they help to meet demand in the world's marketplaces.

Oh hai, I'm a dataflow system. This App I'm running, are full of varrrious components. It's a distributed app, and it resides in 3 computers, on a powerful x86 and two smaller ARMs. Most of the components are written in C++, but there is a critical one written in ASM for the x86. Also, most components have several variations: compiled for different processors, also some components have special GPU versions. Shame or not, I have a script component (a wrapper component calls a script), which prints report, but only once a year. It doesn't even hurt that it's just a script, a slow script.

作为一个智能数据流应用程序,我知道,我的架构只适合特定的任务,其中信号/数据通过图形流动,例如自动化,视频/图像处理,音频处理(所有合成器使用数据流),但幸运的是,这些应用领域是非常需要功率的,其中优化是必不可少的。

我很确定有一天会出现一些其他的架构,它们也是关于优化(以及其他让编程更容易等的东西),它们将能够覆盖更多或其他领域,而我,数据流不能。

因此,“C vs ASM”的话题并不是一个真正的困境。这就像是在争论数字合成器还是模拟合成器更好(就像我之前提到的,我一直在研究合成器)。我建议,做好听的音乐。或倾听。无论什么。C不是相对于ASM。无论如何,我从未见过一个C程序被ASM攻击,反之亦然。

对不起,我的英语不好,尽管我不是一个新技术,我不是广为人知,我是一个孩子。很有希望。来,看看我的资料!