Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Learning to read GCC assembler output

Tags:

c++

c

gcc

assembly

I'm considering picking up some very rudimentary understanding of assembly. My current goal is simple: VERY BASIC understanding of GCC assembler output when compiling C/C++ with the -S switch for x86/x86-64.

Just enough to do simple things such as looking at a single function and verifying whether GCC optimizes away things I expect to disappear.

Does anyone have/know of a truly concise introduction to assembly, relevant to GCC and specifically for the purpose of reading, and a list of the most important instructions anyone casually reading assembly should know?

like image 353
porgarmingduod Avatar asked Apr 09 '10 22:04

porgarmingduod


People also ask

Does gcc output assembly?

Luckily, gcc does not output binary machine code directly. Instead, it internally writes assembler code, which then is translated by as into binary machine code (actually, gcc creates more intermediate structures). This internal assembler code can be outputted to a file, with some annotation to make it easier to read.

What is the output of the assembler C++?

Assembler makes two phases over the given input, first phase and the second phase. The output of compiler is a mnemonic version of machine code. The output of assembler is binary code. C, C++, Java, and C# are examples of compiled languages.

Does gcc use an assembler?

The GNU Assembler, commonly known as gas or as, is the assembler developed by the GNU Project. It is the default back-end of GCC. It is used to assemble the GNU operating system and the Linux kernel, and various other software.


1 Answers

You should use GCC's -fverbose-asm option. It makes the compiler output additional information (in the form of comments) that make it easier to understand the assembly code's relationship to the original C/C++ code.

like image 121
Wyzard Avatar answered Oct 14 '22 14:10

Wyzard