中文字幕 另类精品,亚洲欧美一区二区蜜桃,日本在线精品视频免费,孩交精品乱子片免费

<sup id="3hn2b"></sup>

    1. <sub id="3hn2b"><ol id="3hn2b"></ol></sub><legend id="3hn2b"></legend>

      1. <xmp id="3hn2b"></xmp>

      2. 新聞中心

        EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > 匯編技術(shù)內(nèi)幕(1)

        匯編技術(shù)內(nèi)幕(1)

        作者: 時(shí)間:2016-11-24 來源:網(wǎng)絡(luò) 收藏
        最簡(jiǎn)單C代碼分析
        為簡(jiǎn)化問題,來分析一下最簡(jiǎn)的c代碼生成的匯編代碼

        # vi test1.c
        int main()
        {
        return 0;
        }

        編譯該程序,產(chǎn)生二進(jìn)制文件:
        # gcc test1.c -o test1
        # file test1
        test1: ELF 32-bit LSB executable 80386 Version 1, dynamically linked, not stripped
        test1是一個(gè)ELF格式32位小端(Little Endian)的可執(zhí)行文件,動(dòng)態(tài)鏈接并且符號(hào)表沒有去除。
        這正是Unix/Linux平臺(tái)典型的可執(zhí)行文件格式。

        用mdb反匯編可以觀察生成的匯編代碼:
        # mdb test1
        Loading modules: [ libc.so.1 ]
        > main::dis ; 反匯編main函數(shù),mdb的命令一般格式為 <地址>::dis
        main: pushl %ebp;ebp寄存器內(nèi)容壓棧,即保存main函數(shù)的上級(jí)調(diào)用函數(shù)的棧基地址
        main+1: movl %esp,%ebp ; esp值賦給ebp,設(shè)置main函數(shù)的?;穖ain+3:subl $8,%esp
        main+6:andl $0xf0,%esp
        main+9:movl $0,%eax
        main+0xe:subl %eax,%esp
        main+0x10: movl $0,%eax ; 設(shè)置函數(shù)返回值0
        main+0x15:leave; 將ebp值賦給esp,pop先前棧內(nèi)的上級(jí)函數(shù)棧的基地址給ebp,恢復(fù)原?;?/div>
        main+0x16: ret ; main函數(shù)返回,回到上級(jí)調(diào)用

        注:這里得到的匯編語言語法格式與Intel的手冊(cè)有很大不同,Unix/Linux采用AT&T匯編格式作為匯編語言的語法格式

        問題:誰調(diào)用了 main函數(shù)?
        在C語言的層面來看,main函數(shù)是一個(gè)程序的起始入口點(diǎn),而實(shí)際上,ELF可執(zhí)行文件的入口點(diǎn)并不是main而是_start。
        mdb也可以反匯編_start:
        > _start::dis ;從_start 的地址開始反匯編
        _start: pushl $0
        _start+2: pushl $0
        _start+4: movl %esp,%ebp
        _start+6: pushl %edx
        _start+7: movl $0x80504b0,%eax
        _start+0xc: testl %eax,%eax
        _start+0xe: je +0xf <_start+0x1d>
        _start+0x10: pushl $0x80504b0
        _start+0x15: call -0x75
        _start+0x1a: addl $4,%esp
        _start+0x1d: movl $0x8060710,%eax
        _start+0x22: testl %eax,%eax
        _start+0x24: je +7 <_start+0x2b>
        _start+0x26: call -0x86
        _start+0x2b: pushl $0x80506cd
        _start+0x30: call -0x90
        _start+0x35: movl +8(%ebp),%eax
        _start+0x38: leal +0x10(%ebp,%eax,4),%edx
        _start+0x3c: movl %edx,0x8060804
        _start+0x42: andl $0xf0,%esp
        _start+0x45: subl $4,%esp
        _start+0x48: pushl %edx
        _start+0x49: leal +0xc(%ebp),%edx
        _start+0x4c: pushl %edx
        _start+0x4d: pushl %eax
        _start+0x4e: call +0x152 <_init>
        _start+0x53: call -0xa3 <__fpstart>
        _start+0x58: call +0xfb
        ;在這里調(diào)用了main函數(shù)
        _start+0x5d: addl $0xc,%esp
        _start+0x60: pushl %eax
        _start+0x61: call -0xa1
        _start+0x66: pushl $0
        _start+0x68: movl $1,%eax
        _start+0x6d: lcall $7,$0
        _start+0x74: hlt


        關(guān)鍵詞: 匯編技術(shù)匯編代

        評(píng)論


        技術(shù)專區(qū)

        關(guān)閉