Configuring GNU tools to use Intel assembly syntax

Unix tools that work with assembly language—regardless of architecture—generally use a format invented for the unix environment, which is called ‘AT&T syntax’ after the company that sponsored Research Unix. Different architectures will have different actual instructions and other differences, but AT&T syntax has common features such as source-then-destination order of operands, sigils (e.g. % for registers and $ for literal values), operand size encoded in instruction mnemonics, and parentheses () for memory references. So, an instruction to add 2 to some local variable might look like this.

addl    $2, -4(%rbp)

An x86 architecture, including x86-64, will have documentation published in a different format, called ‘Intel syntax’ after the company that created the x86 architecture family. Although different assemblers have somewhat different assembly languages, Intel syntax has common features such as destination-then-source order of operands, operand size encoded in the operands, and square brackets [] for memory references. Most assembly language tools and documentation for x86 use Intel syntax. So, the same instruction to add 2 to some local variable might look like this.

add     DWORD PTR [rbp-4], 2

When working in a unix environment on an x86 architecture, which is the case for the vast majority of GNU/Linux users, these two traditions come into conflict. In CS205 at Chemeketa, we will be using the Intel syntax, emphasizing the syntax best-suited for the assembly language we will be using over unix tradition.

Therefore, configure the GNU tools that work with assembly language to adopt the Intel syntax.

You can configure gdb using this command.

set disassembly-flavor intel

It is most convenient to add that as a line in your ~/.gdbinit configuration file.

It is possible to configure the gas assembler and gcc compiler on the command line to read assembly in Intel syntax, but it is better to annotate the assembly input itself. When you write assembly code to be used as input to Gnu tools, put this directive at the top.

.intel_syntax noprefix

Conversely, when you are asking gcc to emit assembly code, such as when you are using the -S option to see what assembly is generated from compiling C source code, you can configure Intel syntax using the -masm=intel command-line option.

The objdump utility generates assembly when disasembling. You can have it generate Intel syntax using the -M intel option.

If you want to avoid having to type a command-line option and make it the default, one way you can do so for any command is using a shell alias.

You have attempted of activities on this page