Posts Tagged ‘assembly’

C++ 64-bit Inline Assembly Primer – Part 2

In this series we examine the relationship and implementations of C++ and raw assembly code. In this post we create our own add function in gcc extended assembly.

In the previous post we wrote a short C++ program that loaded two numbers. Despite its simplicity in C++, we saw how the assembly version was comprised of several dozen individual instructions in a rather cryptic format. Much of this complexity stems from the fact that in our sample program we called a function to perform our addition. Calling functions means dealing with a stack, base pointers, and the setup and maintenance of that stack. It means dealing with memory offsets, relative positions, and several other factors. The good news is that at this point we can safely ignore these details. In fact, we will do well to ignore them and focus on just the core competencies of function implementation code. In other words, we’ll let gcc create the function shells, calls, and stack management, we’ll focus on the core logic.

Read More

C++ 64-bit Inline Assembly Primer – Part 1

We can talk directly to our machines in C++ by inserting assembly code via the asm() or extended assembly __asm__ commands.

Doing so allows us to exploit potential performance gains, learn more about our machines, and is in all cases, a fascinating exercise in the lowest level of computer programming.

In this post I want to share a few tips and tricks I’ve learned when using AT&T style syntax on Linux/gcc, and also explain how basic assembly coding works. We’ll start by creating a simple function and checking out the gcc created assembly code. We’ll then take this apart and step through the code to understand how it works.

Read More