《組譯工具》王爽–課程設計一

來源:互聯網
上載者:User

最近學習《組譯工具》王爽的組譯工具,經過一番努力終於實現了第一個課程設計,立文為證,隨便代碼寫的比較爛,不過總算是實現了功能。

一、實驗要求

在螢幕輸出實驗七中的資料

二、設計思路

1、將實驗七的程式編寫成一個子過程finishing,在主程式中調用,可以獲得實驗七種指定格式的table段資料,設定es:bx指向table段中第一行

2、建立一個資料緩衝區buffer,設定ds:si指向buffer

3、對於字串,從table中讀取後寫入buffer,末尾寫入0;對於數值,直接調用實驗10中寫好的dtoc轉換到buffer中

4、每次更新buffer中資料後調用實驗10中的show_str來顯示字串

要求的效果是

 

 

 

代碼:

assume cs:code
data segment
    dd 1975,1976,1977,1978,1979,1980,1981,1982,1983,1984,1985,1986,1987,1988,1989,1990,1991,1992,1993,1994,1995 
    dd 16,22,382,1356,2390,8000,16000,24486,50065,97479,140417,197514,345980,590827,803530,1183000,1843000,2759000,3753000,4649000,5937000
    dd 3,7,9,13,28,38,130,220,476,778,1001,1442,2258,2793,4037,5635,8226,11542,14430,15257,17800
    dd 5,3,42,104,85,210,123,111,105,125,140,136,153,211,199,209,224,239,260,304,333
    db 16 dup(0)
data ends
stack segment
    db 64 dup(0)
stack ends
code segment
    start:
        mov ax,data
        mov ds,ax
        mov ax,stack
        mov ss,ax
        mov sp,64
        mov ax,0B800H
        mov es,ax
        mov di,336
        mov si,0
        mov bh,2
        mov bl,2
        mov cx,4
      
      m:
        push cx
        mov cx,21
      s:
        mov dx,ds:[si+2]
        mov ax,ds:[si]
        call d2c
        mov dh,bh
        mov dl,bl
        call show_str
        inc bh
        add si,4
        loop s
       
        mov bh,2
        add bl,10
        pop cx
        loop m
       
       
       
        mov ax,4c00h
        int 21h
  ;子程式描述
  ;名稱: d2c
  ;功能: 將數字轉換成字串形式,放入[DI]為起始的記憶體單元中
  ;參數: (dx)=dword型資料的高16位 (ax)=dword型資料的低16位
  ;返回: 以0結尾的字串,放在[DI]為起始地址的記憶體單元中
  d2c:
    push di
    push cx
    push dx
    push bx
    mov bx,1
    d2c_s:
    call divdw
    add cx,30h  ;得到的餘數轉化為字串
    push cx
    mov cx,ax
    jcxz ok
   
    inc bx
    jmp d2c_s

   ok:
    mov cx,bx
  
   reverse: ;以正確的順序放入字串
    pop ax
   
    mov [di],al
    inc di
   
    loop reverse
    mov al,0
    mov [di],al
    inc di
    pop bx
    pop dx
    pop cx
    pop di
   
    ret
   
 
  ;子程式描述
  ;名稱: divdw
  ;功能: 進行不會產生溢出的除法運算,被除數為dword型,除數為word型,結果為dword型.
  ;參數: (dx)=dword型資料的高16位 (ax)=dword型資料的低16位 (cx)=除數
  ;返回: (dx)=結果的高16位 (ax)=結果的低16位        (cx)=餘數
  ;應用舉例: 計算1000000/10(F4240H/0AH) 
  divdw:
    push ax ;被除數的低16位入棧
    mov ax,dx
    mov dx,0
    mov cx,10
    div cx  ;得到的結果商放在AX中,餘數放在DX中
    mov cx,ax;暫時儲存商
    pop ax  ;取出低16位的值
    push cx ;儲存商入棧
   
    mov cx,10
    div cx
   
    mov cx,dx   ;餘數放入cx中
    pop dx  ;商的高16位存入dx中,ax中的結果就為商的低16位
   
    ret
   
   
  show_str:;子程式,bx中存放字串的首地址,si中存放字元緩衝區的首地址
        ;寄存器入棧
        push dx
        push cx
        push bx
        push si
        mov ax,160
        mov cl,dh
        mul cl
        mov bx,ax
        mov ah,0
        mov al,dl
        mov cl,2
        mul cl
        add ax,bx
        mov si,ax
        mov bx,0
    str:;顯示字串
        mov cl,[di+bx];判斷是否讀到0
        mov ch,0
        jcxz str_ok
        mov es:[si],cl;移動字串
        mov es:[si+1],02h
        add si,2
        inc bx
        jmp str
     str_ok:;寄存器出棧
        pop si
        pop bx
        pop cx
        pop dx
        ret
        ;返回
   
   
   
   
   
   
code ends
end start

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.