Enough x86 Assembly to Be Dangerous
This tutorial is an introduction to x86 assembly language aimed at C++ programmers of all levels who are interested in what the compiler does with their source code. C++ is a programming language that cares about performance. As with any technology, a deep understanding of C++ is helped by knowledge of the layer below, and this means knowledge of assembly language. Knowing what the compiler does with your source code and the limitations under which it operates can inform how you design and write your C++. We learn how to generate, inspect and interpret the assembly language for your C++ functions and programs. We take a short tour of common assembly instructions and constructs, and discover why extreme caution should be exercised if we are trying to infer performance characteristics from a simple inspection of assembly code. Starting with a simple `operator+` for a user-defined class, we take a look at how interface and implementation choices affect the generated assembly code and observe the effect of copy elisions and related optimizations that compilers commonly perform.