What kind of projects (besides the obvious OS stuff) use assembly language?

后端 未结 16 1891
野的像风
野的像风 2021-02-14 15:48

Seemingly, no one uses assembly nowadays other than to develop device drivers, or the very core of OS kernels etc. Anyone has knowledge of it being currently used for other thin

相关标签:
16条回答
  • 2021-02-14 16:23

    Sometimes certain features are not implementable in a high level language, and inline assembly is used instead. There is some inline assembly in the C++ library Qt, for example; I believe it's used for part of the object introspection system.

    In addition, glibc (the C library for gcc) uses assembly for optimization. IIRC one of the software-based floating-point math implementations has significant chunks written in assembly.

    One of the primary reasons for learning assembly, however, is debugging. On a few occasions, I've gotten myself into situations where not knowing assembly would have prevented me from debugging a particularly sticky problem.

    0 讨论(0)
  • 2021-02-14 16:24

    One of the rate determining code (after whatever is needed dynamic for memory management) in nearly every language is the routine used by the runtime (-library) to move memory. Move(), memcpy etc, as well as primitives like searching for a byte (strchr ) etc.

    These quite often written in assembler too, with special dedicated code to exploit alignment.

    0 讨论(0)
  • 2021-02-14 16:25

    If you spend a lot of time looking at the assembly output of your C/C++ source, you'll notice very quickly that most good optimizing compilers make better assembly than even good assembly programmers. Decisions on when to inline a function, how to handle loops, post vs. pre increment (which many compilers decide how to handle for you now) etc. Best of luck outsmarting a compiler that has a large community developing it and a much better ability to manage addresses and definitions than you, under normal circumstances at least.

    Even device drivers and OS kernels are typically not written using a lot of assembly. Small performance critical sections of real time programs are where you'll find assembly in today's apps.

    It gets even worse when you start talking about RISC assembly which tends to have awesomely effective for optimization instructions like branch and exchange along with dozens of general purpose registers. Most people are not smarter than an optimizing compiler. Those who are are generally writing optimizing compilers.

    0 讨论(0)
  • 2021-02-14 16:25

    In C, at the fundamental level, it's pretty easy to see how a set of instructions becomes assembler (if you understand the underlying architecture). But sometimes, assembler can't be beat. Note that it is possible to write crappy, inefficient assembly code as easily as it is to write crappy C code. And assembler is way less maintainable. And it isn't portable anywhere.

    And it all depends on the quality of the C compiler you're using. Some do better than others. Most compilers allow you to see the assembler code they generate. If you think you can do better, and the code segment is critical, do it. Otherwise, avoid it. Carefully crafted C can be very close to the metal, given a decent compiler.

    0 讨论(0)
提交回复
热议问题