Larry’s Personal & Tech ramblings

Just another WordPress.com weblog

Why write in Assembly Language?

I’ve been asking myself this question for a long time.  As much as I hate the argument “machines are so fast, there’s no need for assembly language”, it’s starting to ring true.  Over the past several years I have written plenty of assembly language, but it’s been ARM, not X86.  I’ll probably never rewrite my 68k emulator in x86 because there’s just no need.  It’s more about what products I’m working on than about the “need” to write in asm.  I haven’t written a desktop PC product in a long time and the last time I did, I used some x86 asm.  The x86 is just such a mess of a design with insufficient registers that you can always beat the compiler with hand written asm.  I just don’t have any programs which need the speed.  If I were writing software to process video or audio (e.g. convert WMA to MP3), I would certainly write the inner loop in asm.  Such a large task should be done as quickly as possible (especially video conversion which can make you wait a long time).  I definitely enjoy coding on the bare metal and I’m sure I’ll be writing ARM asm for a long time, but I’ll probably never write another line of x86 asm (unless a job forces me to).

March 23, 2007 - Posted by bitbank | arm, asm, assembly language, performance, tech, x86 | | 5 Comments

5 Comments »

  1. There’s no way to know about real computing without knowing assembly language, but besides that, the only real reason to use assembly is really to develop main-loops and etc
    But there are also many, many times I’m happier to write straight in asm (so I don’t have to bother checking output code) just because it’s easier to manipulate things like a big framebuffer in asm than to do the same thing in any other language.
    The problem with assembly is that it’s kind of troubleful to develop a good, intuitive UI, and most programs need more a good UI than a fast do_everything() loop…

    Comment by Lint | April 12, 2007

  2. I absolutely agree that “machines are so fast….” is a weak argument against assembly language, and I will (with great disappointment) concede that it is becoming a truth. Likewise, there are still the arguments such as “portability,” and “maintainability” that I *DO* accept as valid concerns.

    However, it also seems to me that poor programming standards have lead to the need for bigger, faster CPUs, and then, because the cpu is faster, “why should I be so careful about my program?” seems to be the modern battle-cry of the programmer. Quite the downward spiral.

    I have taught ‘C’ and C++ programming, and more recently started teaching microcontrollers (all in assembly language), and although the scopes of the projects are different, students jdo just as well in the assembly language as they do in higher languages, and the eager student will be open to learning assembly language on other processors. The argument that “assembly language is too difficult” holds very little water!

    I think “why program in assembly” is best answered with another question: considering how much more efficient assembly is than ‘C’ (and we won’t even consider the insane overhead from C++), if some company devoted it’s efforts to writing assembly programs, at the current speeds of modern CPUs, what would those programs look like? They would by FAR outclass many current programs, but beyond that, it’s a little difficult to even imagine!

    Comment by Wenton | April 19, 2007

  3. very interesting, but I don’t agree with you
    Idetrorce

    Comment by Idetrorce | December 15, 2007

  4. And Intel opened the specs on IA-32 microcode, one could make SHA-1 on a Core2 almost as fast as the SSE4.2 crc32 instruction.

    By any chance, how many parallel frames on x264 can an Itanium decode (it has 128 int regs, 128 fp regs, and branch prediction regs - it has everything that’s missing in ia-32)?

    Comment by Andrey Vul | January 3, 2008

  5. It really depends on what you are trying to accomplish. Sure if you are writing for desktop applications using C or Java makes sense. However, if you are writing the firmware for an embedded system, it often makes more sense to write assembly. More code fitting into a smaller package means making the same product with the same functionality cheaper per unit to produce and run faster.

    Comment by AnyMouse | March 31, 2008

Leave a comment