Compilers: Understanding assembly code generated from small programs

前端 未结 3 1346
礼貌的吻别
礼貌的吻别 2021-02-04 06:46

I\'m self-studying how compilers works. I\'m learning by reading the disassembly of GCC generated code from small 64-bit Linux programs.

I wrote this C

3条回答
  •  挽巷
    挽巷 (楼主)
    2021-02-04 07:30

    Regarding the second question, since the C99 standard it's allowed to not have an explicit return 0 in the main function, the compiler will add it implicitly. Note that this is only for the main function, no other function.

    As for the third question, the rbp register acts as the frame pointer.

    Lastly the PS. It's likely that the called function is using 16 bytes (0x10) for the arguments passed to the function. The subtraction is what "removes" those variables from the stack. Could it possibly be two pointers you pass as arguments?

    If you're serious learning how compilers in general works, and possibly want to create your own (it's fun! :)), then I suggest you invest in some books about the theory and practice of it. The dragon book is an excellent addition to any programmers bookshelf.

提交回复
热议问题