5

Specifically for a game programmer.

If you really needed some assembly routines you could look for help, whereas back in the 80s/90s it was one of the mainstream languages. I read that compilers can generally equal (or beat) most hand written assembly code, so unless you are an embedded programmer who can only program some device in assembly, for example, is there any real point in learning it nowadays?

closed as primarily opinion-based by user40980, JeffO, GrandmasterB, mattnz, Kilian Foth Jul 16 '14 at 7:35

Many good questions generate some degree of opinion based on expert experience, but answers to this question will tend to be almost entirely based on opinions, rather than facts, references, or specific expertise. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 3
    Do you need to squeeze every last ounce of performance out of the system? If so, it'd be useful to be able to read assembly to understand the compiler's output when trying to optimize the critical section of code. If not, then you don't need to worry about assembly. – Doval Jul 15 '14 at 18:55
  • 4
    And who is going to create those magical assembly routines if no one learns assembly language? – GrandmasterB Jul 15 '14 at 19:11
  • @GrandmasterB He's really referring to it just for game developers' purposes. – Panzercrisis Jul 15 '14 at 19:20
  • 4
    Don't learn assembly. Learn computer architecture. It's immensely useful even if you never write or even look assembly code, and should you do get into that unfortunate position it'll make learning the specific of the assembly language much easier. – user7043 Jul 15 '14 at 19:21
  • Like @delnan said, learn how your target machine works. Assembly languages then follow naturally. Magic will disappear and you'll be able to rip any library apart and understand their internals, – Laurent LA RIZZA Oct 2 '15 at 9:15
10

Assembly was never a mainstream language. You learn it for the same reasons that people learned it in the 80s/90s, and before that: it's close to the metal.

Learning assembly language:

  • Teaches you how the machine works, and
  • Gives you access to the best possible performance (in theory).

I say "in theory," because it doesn't come without a cost. Everything you get for free in higher level languages (math, I/O, some organizational structure) is a slog in assembly language, because you're literally building everything from scratch.

That's why, when assembly is used, you'll typically find it in specialized library methods and in inline code, while a higher-level language does most of the heavy lifting. The assembly language optimizes that small bit of the code that will benefit the most from performance optimization.

Modern compilers give you most of the performance benefits of assembly language, without the cognitive cost. But learning assembly still teaches you how the machine works at a deep level, and that knowledge will influence your software development long after you learn assembly, even if you never use assembly all that much.

If you do decide to learn assembly, I recommend that you learn it on an embedded device, like an Atmel AVR. The number of opcodes to learn is smaller than a computer, and there's no operating system to worry about.

  • 11
    "never a mainstream language"? for a long while it was the only language! and for an even longer time compilers (even C) were only for "big" systems and game machines had to be programmed in assembly! I'd bet that in many cases the special purpose chips (sound, sprites, fpu) were in not for the raw speed, but to make it easier to do those sophisticated tasks without bit-banging hardware – Javier Jul 15 '14 at 19:51
  • 2
    You would be AMAZED how much IBM 360 business applications programming was done in assembly language, because of hard performance requirements that just could not be met with the high-level languages and compilers of the day (or because the compiler was considered to be too expensive, or because the code was ported from an earlier system...) – John R. Strohm Jul 15 '14 at 21:34
  • There was (probably still is) a lot of IBM 360-series-family-stuff which could only be done in assembler, because there was just no HLL support. – quickly_now Jul 16 '14 at 2:57
8

I think one of the values of assembly languages today that is often overlooked is the didactic value. I would contend that an assembly language is the best entry language for someone who has never programmed before. Why? Because it is simple and bare. In assembly you have basically three elements: Registers, opcodes and memory addresses. Learn how to mix-and-match those three basic elements and you can do a lot. Now take C for instance, for someone who has never coded before, C is pretty darn complex. Right out of the bat you have functions, #includes, macros, structs and more. That's a lot to take in. Go to a higher level language like Java and then you have the whole concept of classes and objects that must be understood beforehand. My personal opinion is that when learning something new, I prefer to start small. This is why I think assembly is an overlooked didactic tool.

Now on practical aspects, when you get the job of optimizing code, there is also value in being able to read and understand assembly. A lot of optimizations are about reading compiled code and seeing where the compiler is screwing up and how to change your higher level code in a way to allow the compiler to generate faster machine code.

Specifically on game programming, if you look back at the 80s and 90s, there was a lot of assembly programming going on on games and other high performance software, mainly because it was a pressing necessity. Most games used assembly code to be able to access special hardware features, like vectorization instructions such as MMX/SSE/AltiVec/etc. Today, these vectorization instructions are available as compiler intrinsics, so there is little gain in writing them using assembly.

Another issue that is driving game programmers away from assembly is portability. Not many studios can afford to release their games on a single platform these days. You need to write portable code, so assembly is only used as a last resort.

Last-gen Consoles like the PS3 still saw quite a bit of assembly programming, mainly due to its special hardware features that could not be accessed in any other way. But next-gen hardware is a lot closer to desktop PCs in architecture and performance, so again, assembly is loosing space there.

  • 5
    Not to take away from the value of learning assembly but I really question the notion of assembly as a beginner's language. Although not "close to the metal", Lisp is just as bare bones (everything is an s-expression) and you can do things with it right away. Starting with assembly risks giving the impression that programming is about tedious bit and byte manipulations and there's nothing catching your errors. – Doval Jul 15 '14 at 21:51
  • 1
    I started to learn assembly using the DOS "debug" command fairly early on in my programming journey and appreciated it; it helped pointers etc. make a lot of sense. I think it may be a matter of preference. – J Trana Jul 16 '14 at 2:43
5

Of course there's value. It just depends on whether the value is enough to offset the cost.

If you regularly program Kernel modules, device drivers or high-performance, lockless algorithms that rely on hardware-specific atomic primitives, then sometimes assembly language is your only choice. If you want those sort of programming tasks to be available to you, the cost of learning assembly might be worth it.

If you're primarily a PHP developer making web-apps, and you're not interested in doing anything else, you probably have little use for assembly.

Still, learning it has value, in the sense that it will help put into perspective the sort of code you write at a higher level. At the end of the day, despite all of our object-oriented, higher-order function wielding code, the programs we write ultimately compile into a stream of opcodes, mindlessly executed by a processor: load, store, load, store, cmp, jump, load, store, etc.

Learning assembly gives you perspective, and in that sense it has value. But again, whether or not the value is worth the cost of learning probably depends on what type of programmer you want to be.

Not the answer you're looking for? Browse other questions tagged or ask your own question.