Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 320839
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T08:47:26+00:00 2026-05-12T08:47:26+00:00

I was wondering how to use GCC on my C source file to dump

  • 0

I was wondering how to use GCC on my C source file to dump a mnemonic version of the machine code so I could see what my code was being compiled into. You can do this with Java but I haven’t been able to find a way with GCC.

I am trying to re-write a C method in assembly and seeing how GCC does it would be a big help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T08:47:26+00:00Added an answer on May 12, 2026 at 8:47 am

    If you compile with debug symbols (add -g to your GCC command line, even if you’re also using -O31),
    you can use objdump -S to produce a more readable disassembly interleaved with C source.

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

    objdump -drwC -Mintel is nice:

    • -r shows symbol names on relocations (so you’d see puts in the call instruction below)
    • -R shows dynamic-linking relocations / symbol names (useful on shared libraries)
    • -C demangles C++ symbol names
    • -w is "wide" mode: it doesn’t line-wrap the machine-code bytes
    • -Mintel: use GAS/binutils MASM-like .intel_syntax noprefix syntax instead of AT&T
    • -S: interleave source lines with disassembly.

    You could put something like alias disas="objdump -drwCS -Mintel" in your ~/.bashrc. If not on x86, or if you like AT&T syntax, omit -Mintel.


    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
    

    Note that this isn’t using -r so the call rel32=-4 isn’t annotated with the puts symbol name. And looks like a broken call that jumps into the middle of the call instruction in main. Remember that the rel32 displacement in the call encoding is just a placeholder until the linker fills in a real offset (to a PLT stub in this case, unless you statically link libc).


    Footnote 1: Interleaving source can be messy and not very helpful in optimized builds; for that, consider https://godbolt.org/ or other ways of visualizing which instructions go with which source lines. In optimized code there’s not always a single source line that accounts for an instruction but the debug info will pick one source line for each asm instruction.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was wondering if it is safe to use the latest GCC version, or
So I just found out GCC could do inline assembly and I was wondering
I've prepared a .pro file for use Qt and CUDA in a linux machine
I was wondering is there a free Windows version of GCC. I know there
I was wondering if you use @staticmethod decorator in your code. Personally I don't
Being fairly new to Grails i was wondering what people use to consume a
I wondering whether use a webView to create a complex text area done with
Studying compilers course, I am left wondering why use registers at all. It is
I am wondering how to use Model Binding in a scenario where I am
I'm wondering how to use functions from another script in Lua. For example, say

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.