Inline Assembly with GCC on Linux

One cool feature of gcc is that it can inline assembly into C code. With inline assembly, the programmer can precisely control the execution of the processor, such as forcing variables to use registers, getting special processor state efficiently, and writing critical efficient code in assembly by hand.

I compile a list of tutorials from the Internet about inline assembly with gcc on Linux. These tutorials use AT&T syntax for assembly on x86 system. For x86-64, the difference with x86 is small. The method is similar, just the type of instructions and registers, such as movq, %rax, %r15.

GCC-Inline-Assembly-HOWTO by Sandeep.S

“This HOWTO explains the use and usage of the inline assembly feature provided by GCC. There are only two prerequisites for reading this article, and that’s obviously a basic knowledge of x86 assembly language and C.”

Brennan’s Guide to Inline Assembly by Brennan “Bas” Underwood

“This is meant to be an introduction to inline assembly under DJGPP. DJGPP is based on GCC, so it uses the AT&T/UNIX syntax and has a somewhat unique method of inline assembly.”

Using Assembly Language in Linux. by Phillip

“This article will describe assembly language programming under Linux. Contained within the bounds of the article is a comparison between Intel and AT&T syntax asm, a guide to using syscalls and a introductory guide to using inline asm in gcc.

This article was written due to the lack of (good) info on this field of programming (inline asm section in particular), in which case i should remind thee that this is not a shellcode writing tutorial because there is no lack of info in this field.”

Eric Ma

Eric is a systems guy. Eric is interested in building high-performance and scalable distributed systems and related technologies. The views or opinions expressed here are solely Eric's own and do not necessarily represent those of any third parties.

Leave a Reply

Your email address will not be published. Required fields are marked *