Skip to main content
Engineering LibreTexts

1.5: Assembly code

  • Page ID
  • Similar to the -c flag, the -S flag tells gcc to compile the program and generate assembly code, which is basically a human-readable form of machine code.

    $ gcc hello.c -S

    The result is a file named hello.s, which might look something like this:

            .file        "hello.c"
            .section     .rodata
            .string      "Hello World"
            .globl       main
            .type        main, @function
            pushq %rbp
            .cfi_def_cfa_offset 16
            .cfi_offset 6, -16
            movq %rsp, %rbp
            .cfi_def_cfa_register 6
            movl $.LC0, %edi
            call puts
            movl $0, %eax
            popq %rbp
            .cfi_def_cfa 7, 8
            .size        main, .-main
            .ident       "GCC: (Ubuntu/Linaro 4.7.3-1ubuntu1) 4.7.3"
            .section     .note.GNU-stack,"",@progbits

    gcc is usually configured to generate code for the machine you are running on, so for me it generates x86 assembly language, which runs on a wide variety of processors from Intel, AMD, and others. If you are running on a different architecture, you might see different code.

    • Was this article helpful?