Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do you ever need to write real code in assembly language?

Tags:

x86

assembly

Often I hear people around me who like to discussion about writing in assembly language and which is one of those reasons I'm also want to learn to write it. Currently I'm learning assembly and C together.

So, my question is when do you ever need to write assembly in real code?
Is it just good to learn?
Are there are any real uses of it when writing code in C?

Any helpful comments or answers will be appreciated!

like image 445
user1086635 Avatar asked Dec 15 '11 17:12

user1086635


3 Answers

Despite the fact that writing code in assembly became increasingly rare, it is still very good to learn assembly simply to understand how things work under the hood. Modern optimizing compilers of C/C++ let you write code in C that translates into assembly instructions of very high quality, often surpassing what you could write manually at the expense of making the result less readable (e.g by inserting empty instructions to optimize the use of CPU's pipeline).

If you write a compiler for a new architecture, a very low-level library, or an embedded system with strict resource constraints, you may need to use assembly. For everything else, C and C++ will do as well or better.

like image 183
Sergey Kalinichenko Avatar answered Sep 22 '22 18:09

Sergey Kalinichenko


I was going to write a long post but decided to summarize instead:

  1. embedded code, boot loaders, compiler backends
  2. yes, it will help you understand and debug your compiled code
  3. the only time I have used it in c is for reading the real time clock register
like image 23
Bashwork Avatar answered Sep 24 '22 18:09

Bashwork


It's rare. I've never had to in 23 years + of career. But I work in the Client Server DB application space mainly, there are jobs where you'll use it a lot, or at least need to know how processors actually work.

However it was the first thing I learned, not counting basic digital electronics, and I'd say the learning has been a great help over my career and hobby programming.

like image 22
Tony Hopkinson Avatar answered Sep 20 '22 18:09

Tony Hopkinson