Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it worthwile to learn assembly language? [closed]

Is it still worthwhile to learn ASM?

I know a little of it, but I haven't really used it or learned it properly because everything I learn to do in assembler I can do in 1/10th the time with some language like C or C++. So, should I really learn and use ASM? Will it do me any good professionally? Will it increase my resourcefulness? In short, would it make me a better programmer?

Note: I am talking about low-level assembly like FASM or NASM and not something like HLA (High-Level Assembler).

like image 222
ApprenticeHacker Avatar asked Jul 08 '11 10:07

ApprenticeHacker


People also ask

Is it worth to learn assembly language in 2021?

Originally Answered: Is assembly language still useful to learn in 2021? yes. most embedded applications require some amount of assembly (low level code) to directly interface with hardware devices.

Is it still worth it to learn assembly language?

Originally Answered: Is learning Assembly language worth the time? No, it's not worth the effort for modern programmers unless you plan to work on hardware drivers, BIOS, operating systems, or compilers.

Is assembly language still used in 2021?

Today, assembly language is still used for direct hardware manipulation, access to specialized processor instructions, or to address critical performance issues.

Is there a point to learning assembly?

Learning assembly language: Teaches you how the machine works, and. Gives you access to the best possible performance (in theory).


2 Answers

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.

like image 187
spraff Avatar answered Oct 16 '22 15:10

spraff


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.

like image 23
David Rodríguez - dribeas Avatar answered Oct 16 '22 15:10

David Rodríguez - dribeas