Skip to content
Advertisement

Is there any merit about assembly language? [closed]

I heard some of developers use assembly language in embedded system.

I wonder what merit they have from learning assembly language and what field use assembly language.

Do you have any experience?

Advertisement

Answer

The need for assembly code is proportional to the lack of specific compiler support.

Embedded systems are tailored to specific needs, for example Texas Instruments DSP have some “exotic” address modes, like circular and bit reversing addressing modes that are absent into other architectures.
The C language cannot address all these differences in a standard way.

However the C standard doesn’t forbid vendor extensions and compilers targeting specific environments come with built-in functions with the purpose of exposing some low-level functionality. These functions are called intrinsics and being non standard reserved keywords, they start with an underscore.

For example, the TMSxC6000 Optimization Manual lists the intrinsics at 7.5.4.
One very common operation done in DSP is saturated addition where in a n bits word (2n – 1) + 1 = 2n – 1 as opposed to (2n – 1) + 1 = 0 for the usual modular addition.
In TI C dialect this translates to

int x1, x2, y;
y = _sadd(x1, x2);   //_sadd mimics the name of sadd assembly instruction

With the opportune intrinsics you can avoid assembly language at all.


There are however at least three situations where assembly language is still needed:

  1. No adequate intrinsics are present.
    The programmer is forced to fallback to assembly.

  2. The compiler is known particularly bad at optimizing code and you want to write critical part by your self.
    Think at least thrice before taking this path.

  3. You need to use the same C code base for different platforms.
    This is the case of the Linux kernel for example, where they use a small portion of assembly to “abstract” the execution environment enough to be handled with mostly pure C code.
    Often the diversities are so accentuated that simply calling intrinsics is not enough, a different management is needed instead, an abstraction.
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement