Using Assembly Language in C/C++

前端 未结 14 1363
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-23 02:39

I remember reading somewhere that to really optimize & speed up certain section of the code, programmers write that section in Assembly language. My questions are -

14条回答
  •  悲&欢浪女
    2020-12-23 02:54

    1. Yes. Use either inline assembly or link assembly object modules. Which method you should use depends on how much assembly code you need to write. Usually it's OK to use inline assembly for a couple of lines and switch to separate object modules once if it's more than one function.
    2. Definitely, but sometimes it's necessary. The prominent example here would be programming an operating system.
    3. Most compilers today optimize the code you write in a high-level language much better than anyone could ever write assembly code. People mostly use it to write code that would otherwise be impossible to write in a high-level language like C. If someone uses it for anything else means he is either better at optimization than a modern compiler (I doubt that) or just plain stupid, e.g. he doesn't know what compiler flags or function attributes to use.

提交回复
热议问题