Why Learn Assembly?

 

Why Learn Assembly?

Anyone who is serious about programming a particular architecture needs to learn its assembly language at some point. How can you get the most out of a chip if you don't understand what is really going on under the hood?

Learning assembly allows you to fully optimize your code for any situation and lets you write programs that do exactly what you want, how you want them to do it, with no compiler in the middle trying to interpret what you mean. Learning assembly gives you full transparency to your program and best of all, will make you a better C programmer.

Even though you may not end up writing all your programs in assembly, just knowing how is extremely beneficial. For example, it allows you to inspect the output your compiler generates from C code and find areas that are slowing down exectution. Hand tweeking the output will give you an extremely efficient program that benefits from the ease of writing in C with the finesse of assembly.

In addition, time critical algorithms can be written in assembly and called from a main program written in C. Mixing the two allows you to take advantage of the strengths of each language to produce the best programs possible.

Do I need to learn assembly to improve my code?

People will often jump to assembly as their first recourse when a program they wrote in C doesn't run fast enough - they figure they need to get down in the weeds and optimize it at the machine level.

The truth is, most of the time the problem lies in the programmer's poor understanding of C.

Very efficient programs can be written in C if you are knowledgeable in the language. If you are only here because you are want to make a particular program run faster you may want to consider some alternatives.

Learning to write better C code will carry over to other architectures and make you a better programmer in general. All things being equal, you will probably get more out of learning to write better C code than diving straight into assembly.

The bottomline

If you don't know C very well, you're probably better off brushing up on it rather than diving straight into assembly. But if you're pretty comfortable with C and want to take things to the next level (or just have an academic curiosity), assembly is a great tool to have under your belt.

إرسال تعليق

Post a Comment (0)

أحدث أقدم