新聞中心

        EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計應(yīng)用 > 匯編入門學(xué)習(xí)筆記 (五)—— 包含多個段的程序

        匯編入門學(xué)習(xí)筆記 (五)—— 包含多個段的程序

        作者: 時間:2016-11-09 來源:網(wǎng)絡(luò) 收藏
        瘋狂的暑假學(xué)習(xí)之 匯編入門學(xué)習(xí)筆記 (五)—— 包含多個段的程序

        本文引用地址:http://www.104case.com/article/201611/317779.htm

        參考: 《匯編語言》 王爽 第6章

        1.在代碼中使用數(shù)據(jù)。

        1. assumecs:code
        2. codesegment
        3. dw0123h,0456h,0789h,0defh
        4. movax,0
        5. movbx,0
        6. movax,4c00H
        7. int21h
        8. codeends
        9. end

        dw 表示定義字型數(shù)據(jù),db 表示定義字節(jié)型數(shù)據(jù)。

        上面代碼編譯連接,用debug調(diào)試,-u cs:0 查看匯編代碼,發(fā)現(xiàn)沒有看到 mov ax,0 mov bx,0 等。直接運行不正常。因計算機不知道那些是數(shù)據(jù)那些是代碼。如果-u cs:8 就可以看到mov ax,0 mov bx,0 等。

        正確方法,要加上程序入口

        1. assumecs:code
        2. codesegment
        3. dw0123h,0456h,0789h,0defh
        4. start:movax,0
        5. movbx,0
        6. movax,4c00H
        7. int21h
        8. codeends
        9. endstart

        start可以改成其他的名字,只要入口處和end 后面的一樣就行了。

        2.在代碼中使用棧

        例子:交換0123H 跟 0456H

        dw 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 申請了棧的空間

        sp 30H 設(shè)置 棧頂?shù)钠鹗嘉恢?/p>

        1. assumecs:code
        2. codesegment
        3. dw0123h,0456h,0789h,0abch,0defh,0fedh,0cbah,0987h
        4. dw0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
        5. start:movax,cs
        6. movss,ax
        7. movsp,30h
        8. pushcs:[0]
        9. pushcs:[2]
        10. popcs:[0]
        11. popcs:[2]
        12. movax,4c00h
        13. int21h
        14. codeends
        15. endstart


        3.將數(shù)據(jù)、代碼、棧放入不同的段中

        例子:將數(shù)據(jù)段中的數(shù)據(jù),倒敘存放

        1. assumecs:code,ds:data,ss:stack
        2. datasegment
        3. dw0123h,0456h,0789h,0abch,0defh,0fedh,0cbah,0987h
        4. dataends
        5. stacksegment
        6. dw0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
        7. stackends
        8. codesegment
        9. start:movax,data
        10. movds,ax
        11. movax,stack
        12. movss,ax
        13. movsp,20h
        14. movbx,0
        15. movcx,8
        16. s:push[bx]
        17. addbx,2
        18. loops
        19. movbx,0
        20. movcx,8
        21. s0:pop[bx]
        22. addbx,2
        23. loops0
        24. movax,4c00h
        25. int21h
        26. codeends
        27. endstart

        這里定義了三個段,數(shù)據(jù)段,棧段,代碼段。ds,ss的值需要在代碼段中指定。



        關(guān)鍵詞: 匯編入門多個

        評論


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

        關(guān)閉
        主站蜘蛛池模板: 长顺县| 图们市| 新河县| 阿拉尔市| 太仆寺旗| 雷州市| 聂拉木县| 汉源县| 陕西省| 本溪| 和龙市| 镇原县| 莱阳市| 共和县| 丹凤县| 东阿县| 华亭县| 临湘市| 巴林左旗| 溆浦县| 云霄县| 平顶山市| 于都县| 凤阳县| 额济纳旗| 巍山| 东平县| 洛南县| 九龙坡区| 闸北区| 晴隆县| 九台市| 易门县| 鹤岗市| 墨竹工卡县| 阜城县| 吴江市| 平潭县| 海南省| 德江县| 靖州|