I learned from Kip Irvine's book. If you ignore the (fair) criticisms of his (irrelevant) libraries, I can recommend it as a good introduction to the language itself -- although for the really interesting stuff you have to hunt out obsessives on the net.
I think it's useful to understand what happens at the lower levels. As you research assembler you will learn about cpu pipelining, branch prediction, cache alignment, SIMD, instruction reordering and so on. Knowledge of these will help you write better high-level code.
Furthermore, the conventional wisdom is to not try to hand-optimise assembly most of the time but let the compiler worry about it. When you see some examples of the twisted things that compilers generate, you will better understand why the conventional wisdom holds.
Example: LFSRs run fast with the rotate-with-carry instruction, for specific cases like this it's just as easy to write the assembler version as it is to discover whether or not the compiler is smart enough to figure it out. Sometimes you just know something that the compiler doesn't.
It also increases you understanding of security issues -- write-or-execute, stack overruns, etc.
Some concurrency issues only become apparent when you are aware of what is happening at the per-instruction level.
It can be useful sometimes when debugging if you don't have the complete source code.
There's the curiousity value. How are virtual functions implemented anyway? Ever try to write DirectX or COM programs in assembler? How do large structures get returned, does the calling function offer a space for them or vice-versa?
Then there are special assembly languages for graphics hardware, although shader languages went high-level a few years ago, anything which lets you think about a problem a different way is good.
我肯定无法编写汇编(即在汇编中编写任何重要的代码段),但我可以阅读它,并结合实际硬件架构的知识以及正在使用的调用约定足以分析性能并确定哪段 C++ 代码是该程序集的源代码。
I find it interesting that so many people jump to say that yes, you need/should learn assembly. To me the question is how much assembly do you need to know? I don't think you have to know assembly like a programming language, that is I don't believe that everyone should be able to write a program in assembly, but on the other hand, being able to read it and understand what it actually means (which might require more knowledge of the architecture than the assembler) is enough.
I for sure cannot write assembly (i.e. write any non trivial piece of code in assembly), but I can read it and that together with knowledge of the actual hardware architecture, and the calling conventions that are being used is enough to analyze performance, and identify what piece of C++ code was the source of that assembly.
是的 - C 和 C++ 开发人员学习汇编的主要原因是它有助于理解 C 和 C++ 代码背后发生的事情。这并不是说您实际上会用汇编语言编写代码,但您将能够查看代码反汇编以评估其效率并您将了解不同的 C 和 C++ 功能如何更好地工作。
Yes - the primary reason to learn assembly for C and C++ developers is it helps understanding what's going on under the hood of C and C++ code. It's not that you will actually write code in assembly, but you will be able to look at code disassembly to assess its efficiency and you will understand how different C and C++ features work much better.
It's worthwhile to learn lots of different languages, from lots of different paradigms. Learning Java, C++, C#, and Python doesn't count, since they are all instances of the same paradigm.
As assembly is at the root (well, close to the root) of all languages, I for one say that it is worthwhile to learn assembly.
Then again, it's worthwhile to learn a functional programming language, logic programming, scripting languages, math-based languages. You only have so much time, so you do have to pick and choose.
取决于您希望达到的编程水平。 如果您需要使用调试器,那么可以。 如果您需要知道编译器如何工作,那么是的。 任何汇编器/调试器都依赖于 CPU,因此有很多工作,只需检查 x86 系列的大小和年龄即可。
Depend of which programming level you wish to reach. If you need to work with debuggers then YES. If you need to know how compilers works then YES. Any assembler/debugger is CPU dependent, so there is a lot of work, just check x86 family how big and old is it.
从更一般的意义上来说,是的,我认为 asm 非常值得学习(例如 x86 或 arm),它为您服务的效果取决于您编程的内容以及调试方式。
Do you have any use for it in what you plan to do? is it going to aid you in any way in what you currently do or plan to do? those are the two questions you should ask yourself, the answer to those is the answer to your question.
In a more general sense, yes, I'd say in my opinion is well worth learning asm (something like x86 or arm), how well it serves you depends on what you programming and how your debugging it.
发布评论
评论(7)
我是从 Kip Irvine 的书中学到的。如果你忽略对他的(不相关的)库的(公平的)批评,我可以推荐它作为对语言本身的一个很好的介绍——尽管对于真正有趣的东西,你必须寻找对它的痴迷者。网。
我认为了解较低级别发生的事情很有用。当您研究汇编程序时,您将了解 CPU 流水线、分支预测、缓存对齐、SIMD、指令重新排序等。了解这些将帮助您编写更好的高级代码。
此外,传统观点是大多数时候不要尝试手动优化汇编,而是让编译器担心它。当您看到编译器生成的一些扭曲事物的示例时,您将更好地理解为什么传统观点成立。
示例:LFSR 使用旋转进位指令运行得很快,对于像这样的特定情况,编写汇编程序版本就像发现编译器是否足够聪明来弄清楚它一样容易。有时你只知道一些编译器不知道的东西 't。
它还可以增强您对安全问题的理解——写入或执行、堆栈溢出等
。只有当您了解每条指令级别发生的情况时,并发问题才会变得明显。
如果您没有完整的源代码,有时在调试时它会很有用。
这就是好奇心的价值。虚拟函数到底是如何实现的?曾经尝试过用汇编程序编写 DirectX 或 COM 程序吗?如何返回大型结构,调用函数是否为它们提供空间,反之亦然?
然后还有用于图形硬件的特殊汇编语言,尽管着色器语言在几年前就已经达到了高级水平,但任何能让您以不同方式思考问题的语言都是好的。
I learned from Kip Irvine's book. If you ignore the (fair) criticisms of his (irrelevant) libraries, I can recommend it as a good introduction to the language itself -- although for the really interesting stuff you have to hunt out obsessives on the net.
I think it's useful to understand what happens at the lower levels. As you research assembler you will learn about cpu pipelining, branch prediction, cache alignment, SIMD, instruction reordering and so on. Knowledge of these will help you write better high-level code.
Furthermore, the conventional wisdom is to not try to hand-optimise assembly most of the time but let the compiler worry about it. When you see some examples of the twisted things that compilers generate, you will better understand why the conventional wisdom holds.
Example: LFSRs run fast with the rotate-with-carry instruction, for specific cases like this it's just as easy to write the assembler version as it is to discover whether or not the compiler is smart enough to figure it out. Sometimes you just know something that the compiler doesn't.
It also increases you understanding of security issues -- write-or-execute, stack overruns, etc.
Some concurrency issues only become apparent when you are aware of what is happening at the per-instruction level.
It can be useful sometimes when debugging if you don't have the complete source code.
There's the curiousity value. How are virtual functions implemented anyway? Ever try to write DirectX or COM programs in assembler? How do large structures get returned, does the calling function offer a space for them or vice-versa?
Then there are special assembly languages for graphics hardware, although shader languages went high-level a few years ago, anything which lets you think about a problem a different way is good.
我觉得很有趣的是,这么多人跳出来说是的,你需要/应该学习汇编。对我来说,问题是您需要了解多少汇编语言?我认为您不必像编程语言一样了解汇编语言,也就是说,我不相信每个人都应该能够编写汇编程序,但另一方面,能够阅读它并理解它的实际含义(这可能需要比汇编程序更多的体系结构知识)就足够了。
我肯定无法编写汇编(即在汇编中编写任何重要的代码段),但我可以阅读它,并结合实际硬件架构的知识以及正在使用的调用约定足以分析性能并确定哪段 C++ 代码是该程序集的源代码。
I find it interesting that so many people jump to say that yes, you need/should learn assembly. To me the question is how much assembly do you need to know? I don't think you have to know assembly like a programming language, that is I don't believe that everyone should be able to write a program in assembly, but on the other hand, being able to read it and understand what it actually means (which might require more knowledge of the architecture than the assembler) is enough.
I for sure cannot write assembly (i.e. write any non trivial piece of code in assembly), but I can read it and that together with knowledge of the actual hardware architecture, and the calling conventions that are being used is enough to analyze performance, and identify what piece of C++ code was the source of that assembly.
是的 - C 和 C++ 开发人员学习汇编的主要原因是它有助于理解 C 和 C++ 代码背后发生的事情。这并不是说您实际上会用汇编语言编写代码,但您将能够查看代码反汇编以评估其效率并您将了解不同的 C 和 C++ 功能如何更好地工作。
Yes - the primary reason to learn assembly for C and C++ developers is it helps understanding what's going on under the hood of C and C++ code. It's not that you will actually write code in assembly, but you will be able to look at code disassembly to assess its efficiency and you will understand how different C and C++ features work much better.
从许多不同的范例中学习许多不同的语言是值得的。学习 Java、C++、C# 和 Python 并不算数,因为它们都是同一范例的实例。
由于汇编是所有语言的根源(嗯,接近根源),因此我认为学习汇编是值得的。
话又说回来,学习函数式编程语言、逻辑编程、脚本语言、基于数学的语言是值得的。你的时间有限,所以你必须做出选择。
It's worthwhile to learn lots of different languages, from lots of different paradigms. Learning Java, C++, C#, and Python doesn't count, since they are all instances of the same paradigm.
As assembly is at the root (well, close to the root) of all languages, I for one say that it is worthwhile to learn assembly.
Then again, it's worthwhile to learn a functional programming language, logic programming, scripting languages, math-based languages. You only have so much time, so you do have to pick and choose.
了解 ASM 在调试时也很有用,因为有时您所拥有的只是“错误的 ASM 转储”。
Knowing ASM is also useful when debugging, as sometimes all you have is "ASM dump of the error".
取决于您希望达到的编程水平。
如果您需要使用调试器,那么可以。
如果您需要知道编译器如何工作,那么是的。
任何汇编器/调试器都依赖于 CPU,因此有很多工作,只需检查 x86 系列的大小和年龄即可。
Depend of which programming level you wish to reach.
If you need to work with debuggers then YES.
If you need to know how compilers works then YES.
Any assembler/debugger is CPU dependent, so there is a lot of work, just check x86 family how big and old is it.
您在您计划做的事情中是否有任何用途?它会对您目前正在做或计划做的事情有任何帮助吗?这是你应该问自己的两个问题,这些问题的答案就是你问题的答案。
从更一般的意义上来说,是的,我认为 asm 非常值得学习(例如 x86 或 arm),它为您服务的效果取决于您编程的内容以及调试方式。
Do you have any use for it in what you plan to do? is it going to aid you in any way in what you currently do or plan to do? those are the two questions you should ask yourself, the answer to those is the answer to your question.
In a more general sense, yes, I'd say in my opinion is well worth learning asm (something like x86 or arm), how well it serves you depends on what you programming and how your debugging it.