If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Is Assembly Still Relevant To Most Linux Software?

04-02-2013, 05:40 AM

Phoronix: Is Assembly Still Relevant To Most Linux Software?

Steve McIntyre and the Linaro Enterprise Group recently analyzed Ubuntu and Fedora software packages to see what software was still relying upon hand-written Assembly code. This was done to see how much real Assembly is being used, to see what the code was used for, and whether it was worth porting to 64-bit ARM / AArch64 / ARMv8...

This is not surprising at all. There is a myth that programming in assembly produces faster executable code, but this is not always the case. It enterily depends on the programmer's ability. Many times a compiler produces better executables than hand written assembly, and is less prone to errors, not to mention developing in assembly takes ages...

There is absolutely no point in using it today, except for corner cases.

In fact, we are rapidly approaching an age where almost all programs will be written in managed languages like Java and C#. Virtual machines have come a long way in speed, and with multicores now the norm, managed code can be as fast or sometimes even more than unmanaged code.

Comment

This is not surprising at all. There is a myth that programming in assembly produces faster executable code, but this is not always the case. It enterily depends on the programmer's ability. Many times a compiler produces better executables than hand written assembly, and is less prone to errors, not to mention developing in assembly takes ages...

There is absolutely no point in using it today, except for corner cases.

In fact, we are rapidly approaching an age where almost all programs will be written in managed languages like Java and C#. Virtual machines have come a long way in speed, and with multicores now the norm, managed code can be as fast or sometimes even more than unmanaged code.

What? This isn't about managed vs unmanaged, and if anything the Linux development space is trending towards Qt, which is C++ and native, since Java is a slow boring piece of crap, and C# (mainly Xamarin) has been disowning the Linux developer scene hardcore. Neither are supported across mobile platforms either, which is key, and something that Qt actually has going for it as well, and as GTK and Gnome get its act together it remains a competitor. Maybe language binds for native toolkits, like pyside, but even that won't support mobile platforms like native will.

I'm honestly surprised 6% of packages have assembly. I mean, that is slightly more than 1 in 20 packages using assembly. When you factor in how many of those are written in Python / Java / C# / etc, you know, the managed languages, it means a quantifiable number of C/C++ packages use platform dependent hand written assembly still.

Comment

I'm actually kind of tired of reading comments from people regurgitating how "it is a myth that coding assembly produces faster code" or that it is overrated. These people obviously have no clue what they are talking about.

One "problem" with writing software in assembly is that you end up doing quite a few high-level function calls so the question ends up with; how much is low-level assembly really when most of the execution time of the program takes place in libraries (that most likely are not coded in assembly) rather than the program itself.

A person who decides to write particular routines in assembly knows what he is doing and in most cases hand-written code will be more optimized than code that is compiled from high-level. Sure, some cases may be debatable and you might find that e.g. Intel's c compiler sometimes generates really good code that is close to what one would have achieved with hand-written assembly.

But still in general, an experienced assembly programmer writes more optimized code than any high-level compiler in existence.

Comment

AFAIK compilers don't produce optimized assembly using SIMD instructions, which is the only "corner case" that comes to my mind for using assembly along with writing kernel code that directly interfaces with the hardware.

Comment

It's partially true that it's up to the programmer's skill on how small and fast he can make his code. But there's different limits for each programming language and assembly is the one you can make your executable most fastest and/or smallest possible compared to C, C++, java etc. because you are given more control over how memory is managed.

But because of advances in CPU power, such refinements and sleekness are not needed for most apps you use today. However, part of the Linux kernel is still in assembly while the rest is in C. So assembly is still important but not used as much. There's still however, one use of assembly in "Applications". Creating Worms and Viruses. These things need to be slick and small enough to easily get on computers. They need to manage memory properly and efficiently as well to stay hidden to such a point that only assembly provides the means to produce a program which achieves that.

So if you're a malicious cracker (and all crackers use Linux because they would have learned that Linux is the safest), assembly and assemblers like nasm are still relevant to you for creating viruses to infect Windows and BSD machines.

BSDs are so insecurity that you probability only need to write your code in C, C++ or even shell to be successful.

Comment

It's partially true that it's up to the programmer's skill on how small and fast he can make his code. But there's different limits for each programming language and assembly is the one you can make your executable most fastest and/or smallest possible compared to C, C++, java etc. because you are given more control over how memory is managed.

But because of advances in CPU power, such refinements and sleekness are not needed for most apps you use today. However, part of the Linux kernel is still in assembly while the rest is in C. So assembly is still important but not used as much. There's still however, one use of assembly in "Applications". Creating Worms and Viruses. These things need to be slick and small enough to easily get on computers. They need to manage memory properly and efficiently as well to stay hidden to such a point that only assembly provides the means to produce a program which achieves that.

So if you're a malicious cracker (and all crackers use Linux because they would have learned that Linux is the safest), assembly and assemblers like nasm are still relevant to you for creating viruses to infect Windows and BSD machines.

BSDs are so insecurity that you probability only need to write your code in C, C++ or even shell to be successful.

Now is it necessary (other than CPU probing and other hardware)? I stopped writing in ASM ~2002 for a reason. Still I am glad that you can insert _asm into a c project... too bad it's AT&T (yeah I know you can flag it to Intel) syntax.

Edit: man was it fun stuffing all the code in the .data section for obfuscation. Too bad anti viruses flagged the crap out those programs.