How can I view the C mnemonic code in GCC?

Asked 2 years ago, Updated 2 years ago, 124 views

The assembly that I made myself, Compared to the assembly that GCC converted in C, I want to compare how well it optimizes.

Is there such a function in C like looking at machine language on Java and mnemonic?

c gcc assembly

2022-09-21 21:05

1 Answers

If you compile it with a debug symbol, You can see mnemonic in objdump

>objdump --help
[...]
-S, --source             Intermix source code with disassembly
-l, --line-numbers       Include line numbers and filenames in output

Example:

> gcc -g -c test.c
> objdump -d -M intel -S test.o

test.o:     file format elf32-i386


Disassembly of section .text:

00000000 <main>:
#include <stdio.h>

int main(void)
{
   0:   55                      push   ebp
   1:   89 e5                   mov    ebp,esp
   3:   83 e4 f0                and    esp,0xfffffff0
   6:   83 ec 10                sub    esp,0x10
    puts("test");
   9:   c7 04 24 00 00 00 00    mov    DWORD PTR [esp],0x0
  10:   e8 fc ff ff ff          call   11 <main+0x11>

    return 0;
  15:   b8 00 00 00 00          mov    eax,0x0
}
  1a:   c9                      leave  
  1b:   c3                      ret


2022-09-21 21:05

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.