新聞中心

        EEPW首頁 > 嵌入式系統 > 設計應用 > 匯編入門學習筆記 (十四)—— 直接定址表

        匯編入門學習筆記 (十四)—— 直接定址表

        作者: 時間:2016-11-09 來源:網絡 收藏
        瘋狂的暑假學習之 匯編入門學習筆記 (十四)—— 直接定址表

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

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

        1. 描述單元長度的標號

        普通的標號:a,b

        1. assumecs:code
        2. codesegment
        3. a:db1,2,3,4,5,6,7,8
        4. b:dw0
        5. start:
        6. movsi,offseta
        7. movdi,offsetb
        8. movah,0
        9. movcx,8
        10. s:
        11. moval,cs:[si]
        12. addcs:[di],ax
        13. incsi
        14. loops
        15. movax,4c00h
        16. int21h
        17. movax,4c00h
        18. int21h
        19. codeends
        20. endstart

        仔細看一下,下面代碼的標號的不同。下面的標號a、b后面沒有冒號。它們是可以描述單元長度的標號。又叫數據標號

        1. assumecs:code
        2. codesegment
        3. adb1,2,3,4,5,6,7,8
        4. bdw0
        5. start:
        6. movsi,offseta
        7. movah,0
        8. movcx,8
        9. s:
        10. moval,a[si]
        11. addb,ax
        12. incsi
        13. loops
        14. movax,4c00h
        15. int21h
        16. movax,4c00h
        17. int21h
        18. codeends
        19. endstart

        我們可以:

        mov ax,bx 相當于 mov ax,cs:[8]

        mov b,2 相當于 mov word ptr cs:[8],2

        inc b 相當于inc word ptr cs:[8]

        mov al,a[si]相當于 mov al,cs:0[si]

        mov al,a[3] 相當于mov al,cs:0[3]

        但是下面的是錯的

        mov al,b 因為b是dw,字型的

        add b,al

        2. 在其他段中使用數據標號

        普通的后面帶有“:”的標號,是只能定義在代碼段的。數據標號可以用在其他段中。

        例子:注意如果想把ds:b 直接寫成 b,就必須在assume 后加上 cs:data

        1. assumecs:code,ds:data
        2. datasegment
        3. adb1,2,3,4,5,6,7,8
        4. bdw0
        5. dataends
        6. codesegment
        7. start:
        8. movax,data
        9. movds,ax
        10. movsi,offseta
        11. movah,0
        12. movcx,8
        13. s:
        14. moval,a[si]
        15. addb,ax
        16. incsi
        17. loops
        18. movax,4c00h
        19. int21h
        20. movax,4c00h
        21. int21h
        22. codeends
        23. endstart

        3. 直接定址表

        我們可以建一個表,用查表的方式來大大加快處理速度。

        例子:在屏幕顯示對應16進制數字的字符。這里字符就用來一個表。

        1. assumecs:code
        2. codesegment
        3. start:
        4. moval,0eh
        5. callshowbyte
        6. movax,4c00h
        7. int21h
        8. showbyte:
        9. jmpshortshow
        10. tabledb0123456789ABCDE;字符表
        11. show:
        12. pushbx
        13. pushes
        14. movah,al
        15. shrah,1;右移4位,ah中保存高4位,al中保存第4位
        16. shrah,1
        17. shrah,1
        18. shrah,1
        19. andal,00001111b
        20. movbl,ah
        21. movbh,0
        22. movah,table[bx]
        23. movbx,0b800h
        24. moves,bx
        25. moves:[160*12+40*2],ah
        26. movbl,al
        27. movbh,0
        28. moval,table[bx]
        29. moves:[160*12+40*2+2],al
        30. popes
        31. popbx
        32. ret
        33. codeends
        34. endstart

        我們還可以在直接定址表中存儲子程序的地址,從而方便的實現不同子程序的調用。



        評論


        技術專區

        關閉
        主站蜘蛛池模板: 怀来县| 洛川县| 许昌县| 祁连县| 崇信县| 南召县| 鄂温| 巴彦淖尔市| 本溪市| 龙泉市| 桃园市| 浙江省| 庆元县| 兴山县| 新安县| 彭山县| 雷州市| 保山市| 普安县| 合江县| 郁南县| 枝江市| 辽宁省| 凉城县| 南华县| 博爱县| 西藏| 富宁县| 阿巴嘎旗| 阿拉善左旗| 阿克苏市| 湖北省| 伊吾县| 武穴市| 综艺| 永丰县| 湟源县| 精河县| 泗洪县| 霍邱县| 临沂市|