汇编编程比高级语言(如c)花费更长的时间,更难编程,这似乎是一种主流观点。因此,出于这些原因以及更好的可移植性,似乎建议或假设用高级语言编写更好。
最近我一直在用x86汇编语言写作,我开始意识到这些原因可能都不是真的,除了可移植性。也许这更多的是一个熟悉的问题,知道如何写好汇编。我还注意到在汇编中编程与在HLL中编程有很大的不同。也许一个好的、有经验的汇编程序员可以像一个有经验的C程序员用C写程序一样轻松、快速地编写程序。
也许是因为汇编编程与hll有很大的不同,因此需要不同的思维、方法和方式,这使得对不熟悉的人编写程序看起来非常尴尬,因此给汇编编程带来了不好的名声。
如果可移植性不是问题,那么C语言比NASM这样的优秀汇编器有什么优势呢?
编辑:
我只是想指出。当你用汇编语言写作时,你不必只写指令代码。您可以使用宏、过程和您自己的约定来进行各种抽象,使程序更模块化、更可维护、更易于阅读。这就是熟悉如何编写好的汇编的原因。
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攻击,反之亦然。
对不起,我的英语不好,尽管我不是一个新技术,我不是广为人知,我是一个孩子。很有希望。来,看看我的资料!
你好,我是一个编译器。
I just scanned thousands of lines of code while you were reading this sentence. I browsed through millions of possibilities of optimizing a single line of yours using hundreds of different optimization techniques based on a vast amount of academic research that you would spend years getting at. I won't feel any embarrassment, not even a slight ick, when I convert a three-line loop to thousands of instructions just to make it faster. I have no shame to go to great lengths of optimization or to do the dirtiest tricks. And if you don't want me to, maybe for a day or two, I'll behave and do it the way you like. I can transform the methods I'm using whenever you want, without even changing a single line of your code. I can even show you how your code would look in assembly, on different processor architectures and different operating systems and in different assembly conventions if you'd like. Yes, all in seconds. Because, you know, I can; and you know, you can't.
附言:哦,顺便说一下,你没有使用你写的一半代码。我帮了你一个忙,把它扔了。
人们似乎忘记了还有另一个方向。
为什么你一开始要用汇编语言写东西?为什么不用一种真正低级的语言来编写程序呢?
而不是
mov eax, 0x123
add eax, 0x456
push eax
call printInt
你还是写吧
B823010000
0556040000
50
FF15.....
这有很多好处,你知道你的程序的确切大小,你可以重用指令的值作为其他指令的输入,你甚至不需要汇编程序来编写它,你可以使用任何文本编辑器……
你仍然喜欢汇编程序的原因,是其他人喜欢C语言的原因。