How do you get assembler output from C/C++ source in gcc?

后端 未结 17 1799
天命终不由人
天命终不由人 2020-11-22 02:43

How does one do this?

If I want to analyze how something is getting compiled, how would I get the emitted assembly code?

相关标签:
17条回答
  • 2020-11-22 03:17

    Use "-S" as an option. It displays the assembly output in the terminal.

    0 讨论(0)
  • 2020-11-22 03:19

    Use the -S switch

    g++ -S main.cpp
    

    or also with gcc

    gcc -S main.c
    

    Also see this

    0 讨论(0)
  • 2020-11-22 03:20

    If you're looking for LLVM assembly:

    llvm-gcc -emit-llvm -S hello.c
    
    0 讨论(0)
  • 2020-11-22 03:20

    I don't see this possibility among answers, probably because the question is from 2008, but in 2018 you can use Matt Goldbolt's online website https://godbolt.org

    You can also locally git clone and run his project https://github.com/mattgodbolt/compiler-explorer

    0 讨论(0)
  • 2020-11-22 03:21

    Here are the steps to see/print the assembly code of any C program on your Windows

    console /terminal/ command prompt :

    1. Write a C program in a C code editor like codeblocks and save it with an extention .c

    2. Compile and run it.

    3. Once run successfully, go to the folder where you have installed your gcc compiler and give the

      following command to get a ' .s ' file of the ' .c' file

      C:\ gcc> gcc -S complete path of the C file ENTER

      An example command ( as in my case)

      C:\gcc> gcc -S D:\Aa_C_Certified\alternate_letters.c

      This outputs a ' .s' file of the original ' .c' file

    4 . After this , type the following command

    C;\gcc> cpp filename.s ENTER

    Example command ( as in my case)

    C;\gcc> cpp alternate_letters.s

    This will print/output the entire Assembly language code of your C program.

    0 讨论(0)
提交回复
热议问题