分析.cpp文件编译生成的汇编文件里语句的作用
| 1 2 3 4 | int?main(int?argc,char** argv) { return?1; } |
| 1 | g++ -S test.cpp |
生成test.s匯編文件
? .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 ?%edi, -4(%rbp)
? movq ?%rsi, -16(%rbp)
? movl ?$1, %eax
? popq ?%rbp
? .cfi_def_cfa 7, 8 ? ? ret
? .cfi_endproc ?//在函數(shù)結(jié)束的時(shí)候使用與.cfi_startproc相配套使用
.LFE0:
? .size main, .-main
? .ident ? "GCC: (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3"
? .section ?.note.GNU-stack,"",@progbits
看到上面有一些語(yǔ)句如
cfi_def_cfa? cfi_endproc? cfi_startproc的命令,這些前面都有個(gè)關(guān)鍵字cfi? 它是Call Frame infromation的意思。
查看堆棧的信息
id="iframe_0.622272088425234" src="data:text/html;charset=utf8,%3Cimg%20id=%22img%22%20src=%22http://upload.wikimedia.org/wikipedia/commons/thumb/d/d3/Call_stack_layout.svg/342px-Call_stack_layout.svg.png?_=2950718%22%20style=%22border:none;max-width:614px%22%3E%3Cscript%3Ewindow.onload%20=%20function%20()%20%7Bvar%20img%20=%20document.getElementById('img');%20window.parent.postMessage(%7BiframeId:'iframe_0.622272088425234',width:img.width,height:img.height%7D,%20'http://www.cnblogs.com');%7D%3C/script%3E" frameborder="0" scrolling="no" style="margin: 0px; padding: 0px; border-style: none; border-width: initial; width: 342px; height: 279px;">
CFA是什么意思就不太清楚了 可能是control flow analysis的意思吧?
.cfi_startproc 用在每個(gè)函數(shù)的開(kāi)始,用于初始化一些內(nèi)部數(shù)據(jù)結(jié)構(gòu) .cfi_endproc 在函數(shù)結(jié)束的時(shí)候使用與.cfi_startproc相配套使用 .cfi_def_cfa_offset 16| 1 2 | .cfi_def_cfa_offset offset .cfi_def_cfa_offset modifies a rule for computing CFA. Register remains the same, but offset is new. Note that it is the absolute offset that will be added to a defined register to compute CFA address. |
.cfi_def_cfa 7, 8
| 1 2 | .cfi_def_cfa register, offset .cfi_def_cfa defines a rule for computing CFA as: take address from register and add offset to it. |
.cfi_def_cfa_register 6
| 1 2 | .cfi_def_cfa_register register .cfi_def_cfa_register modifies a rule for computing CFA. From now on register will be used instead of the old one. Offset remains the same. |
.cfi_offset 6, -16
| 1 2 3 | .cfi_offset register, offset Previous value of register is saved at offset offset from CFA. |
.cfi_startproc 和 .cfi_endproc 分別是 dwarf2 CFI 的初始過(guò)程和結(jié)束過(guò)程指令,它們隱藏了一些 CFI 有關(guān)的操作。ret 是從當(dāng)前過(guò)程中返回的指令。這就是一個(gè)最簡(jiǎn)單的 main 函數(shù)內(nèi)部的三個(gè)步驟:CFI 初始操作 – 返回 – CFI 結(jié)束操作。由于第一個(gè)和最后一個(gè)步驟永遠(yuǎn)伴隨著函數(shù),我們大可將注意力集中在這兩個(gè)步驟之間的代碼,也就是 main 函數(shù)的實(shí)際內(nèi)容。
eax 是一個(gè)通用的寄存器,根據(jù) cdesl 調(diào)用約定(即 C 語(yǔ)言調(diào)用約定),在函數(shù)返回時(shí),返回值必須保存在 eax 寄存器中,交給調(diào)用者處理。
rbp寄存器 是ebp寄存器64位擴(kuò)展,ebp寄存器擴(kuò)展基址指針寄存器(extended base pointer) 其內(nèi)存放一個(gè)指針,該指針指向系統(tǒng)棧最上面一個(gè)棧幀的底部。BP
為基指針(Base Pointer)寄存器,用它可直接存取堆棧中的數(shù)據(jù),它的作用是在調(diào)用函數(shù)時(shí)保存ESP使函數(shù)結(jié)束時(shí)可以正確返回;加E(enhance)代表增強(qiáng)型寄存器,用于32位數(shù)據(jù)處理。 ?EAX也是一種32位通用寄存器。 EAX寄存器稱為累加器,AX寄存器是算術(shù)運(yùn)算的主要寄存器,所有的輸入、輸出只使用AL或AX人作為數(shù)據(jù)寄存器。在80386及其以上的微處理器中,EAX寄存器可以用來(lái)存儲(chǔ)單元的偏移地址。
將數(shù)據(jù)33221100H傳送到EAX寄存器的指令
EAX可稱為數(shù)據(jù)寄存器,你除了直接訪問(wèn)外,還可分別對(duì)其高十六位和低十六位進(jìn)行訪問(wèn)。它們的低十六位就是把它們前邊兒的E去掉,即EAX的低十六位就是AX。而且它們的低十六位又可以分別進(jìn)行八位訪問(wèn),也就是說(shuō),AX還可以再進(jìn)行分解,即AX還可分為AH(高八位)AL(低八位)。
?
.file,?.text, etc are assembler directives.
.LFB0,?.LFE0?are local labels, which are normally used as branch destinations within a function.
總結(jié)
以上是生活随笔為你收集整理的分析.cpp文件编译生成的汇编文件里语句的作用的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: linux下汇编语言开发总结
- 下一篇: kali2.0安装搜狗输入法