64 assembly output with gcc?

This question already has an answer here:

  • How to remove “noise” from GCC/clang assembly output? 3 answers

  • The stuff that goes into .eh_frame section is unwind descriptors, which you only need to unwind stack (eg with GDB). While learning assembly, you could simply ignore it. Here is a way to do the "clean up" you want:

    gcc -S -o - test.c | sed -e '/^.L/d' -e '/.eh_frame/Q'
            .file   "test.c"
            .text
    .globl main
            .type   main,@function
    main:
            pushq   %rbp
            movq    %rsp, %rbp
            movl    $0, %eax
            leave
            ret
            .size   main,.Lfe1-main
    

    You can try placing the code you want to study in a function.

    Eg:

    int ftest(void)
    {
        return 0;
    }
    
    int main(void)
    {
        return ftest();
    }
    

    If you look at the assembly-source for test it will be as clean as you need.

    ..snip..
    test:
    .LFB2:
            pushq   %rbp
    .LCFI0:
            movq    %rsp, %rbp
    .LCFI1:
            movl    $0, %eax
            leave
            ret
    ..snip..
    

    I've found that using the -Os flag makes things clearer. I tried it your tiny example, but it made very little difference.

    That said, I remember it being helpful when I was learning assembly (on a Sparc).

    链接地址: http://www.djcxy.com/p/80334.html

    上一篇: subl在这里做什么?

    下一篇: 64个汇编输出与GCC?