To view the assembled results in gcc

Asked 2 years ago, Updated 2 years ago, 82 views

I received a task to analyze the results of the compiled code, but I'm not used to gcc yet, so I don't know what options to give.

How do I view the assembly code of C/C++ in gcc?

c++ c debugging gcc assembly

2022-09-22 11:07

2 Answers

Give the -S option.

The gcc-S source code.c


2022-09-22 11:07

The -S option in gcc allows the assembly code to be generated as shown below. If you do not give the -o option separately, for the same name as the source code.Generate assembly code as a file with s suffix.

$ cat hello.c
#include <stdio.h>

int main(void)
{
    printf("hello dcslab guest ;)\n");

    return 0;
}
$ $ gcc -S hello.c
$ $ cat hello.s
    .file   "hello.c"
    .section    .rodata
.LC0:
    .string "hello dcslab guest ;)"
    .text
    .globl  main
    .type   main, @function
main:
.LFB0:
    .cfi_startproc
    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
    ret
    .cfi_endproc
.LFE0:
    .size   main, .-main
    .ident  "GCC: (Ubuntu 4.8.4-2ubuntu1~14.04.1) 4.8.4"
    .section    .note.GNU-stack,"",@progbits


2022-09-22 11:07

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.