微機(jī)原理與匯編語言-實(shí)驗(yàn)3-循環(huán)程序設(shè)計(jì)實(shí)驗(yàn)匯總(共12頁)_第1頁
微機(jī)原理與匯編語言-實(shí)驗(yàn)3-循環(huán)程序設(shè)計(jì)實(shí)驗(yàn)匯總(共12頁)_第2頁
微機(jī)原理與匯編語言-實(shí)驗(yàn)3-循環(huán)程序設(shè)計(jì)實(shí)驗(yàn)匯總(共12頁)_第3頁
微機(jī)原理與匯編語言-實(shí)驗(yàn)3-循環(huán)程序設(shè)計(jì)實(shí)驗(yàn)匯總(共12頁)_第4頁
微機(jī)原理與匯編語言-實(shí)驗(yàn)3-循環(huán)程序設(shè)計(jì)實(shí)驗(yàn)匯總(共12頁)_第5頁
已閱讀5頁,還剩7頁未讀 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、微機(jī)原理與匯編語言實(shí)驗(yàn)報(bào)告姓 名xxx學(xué) 號(hào)xxxxxx專業(yè)班級(jí)計(jì)科x班課程名稱微機(jī)原理與匯編語言實(shí)驗(yàn)日期2014.10.22實(shí)驗(yàn)名稱循環(huán)程序設(shè)計(jì)實(shí)驗(yàn)成 績(jī)一、實(shí)驗(yàn)?zāi)康?、掌握循環(huán)程序的設(shè)計(jì)方法。2、掌握比較指令、轉(zhuǎn)移指令和循環(huán)指令的使用方法。3、進(jìn)一步掌握調(diào)試工具的使用方法。二、實(shí)驗(yàn)內(nèi)容 1、實(shí)驗(yàn)原理 (1)鍵盤輸入的十進(jìn)制數(shù)如368在計(jì)算機(jī)中是以33H,36H,38H形式存放的,如何將它們轉(zhuǎn)換為一個(gè)二進(jìn)制數(shù)101110000B,以便對(duì)累加循環(huán)的循環(huán)次數(shù)進(jìn)行控制是本程序首先要解決的問題(2)累加結(jié)果為一個(gè)16位的二進(jìn)制數(shù),為了顯示結(jié)果,必需把它們轉(zhuǎn)換為十進(jìn)制數(shù) 2、實(shí)驗(yàn)步驟 (1)流程圖從鍵

2、盤輸入一個(gè)十進(jìn)制數(shù),并將其轉(zhuǎn)換為二進(jìn)制數(shù),存放在AX中開始結(jié)束素、(CX)-1=0累加循環(huán)次數(shù)送CX(MOV CX,AX)AX清0(AX中存放累加和)BX送1(BX存放每次循環(huán)累加的數(shù),每循環(huán)一次,BX值加1)ADD AX,BX INC BX累加和(在AX中)轉(zhuǎn)換為十進(jìn)制數(shù)并顯示YN (2)實(shí)驗(yàn)源碼.model small.stack;定義堆棧段 .data;定義數(shù)據(jù)段 inf1 db "Please input a number(1-627):$" inf2 db 0ah, 0dh, "1+2+.+$" ibuf db 7, 0, 6 dup(0) o

3、buf db 6 dup(0) .codestart: mov ax, data mov ds, ax mov dx, offset inf1 ;將屏幕輸入的十進(jìn)制數(shù)(存放于ibuf)轉(zhuǎn)化為二進(jìn)制數(shù)存儲(chǔ)于ax中 mov ah, 09h int 21h mov dx, offset ibuf mov ah, 0Ah int 21h mov cl, ibuf+1 mov ch, 0 mov si, offset ibuf+2 mov ax, 0loop1: mov dx, 10 mul dx and byte ptr si, 0Fh add al, si adc ah, 0 inc si loop

4、 loop1 mov cx, ax ;計(jì)算1+2+3+.+n mov ax, 0 mov bx, 1loop2: add ax, bx inc bx loop loop2 mov di, offset obuf+6 ;將ax中的二進(jìn)制數(shù)轉(zhuǎn)換為十進(jìn)制數(shù)并以ascii的形式存于obuf mov byte ptr di, '$' mov bx, 10loop3: mov dx, 0 div bx add dl, 30h dec di mov di, dl or ax, ax jnz loop3 dec di mov di, '=' mov dx, offset inf

5、2 ;結(jié)果輸出 mov ah, 09h int 21h mov cl, ibuf+1 ;顯示n mov ch, 0 mov si, offset ibuf+2loop4: mov dl, si add dl, 30h inc si mov ah, 02h int 21h loop loop4 mov dx, di mov ah, 09h int 21h mov ax, 4c00h int 21h end start實(shí)驗(yàn)習(xí)題1源碼:; multi-segment executable file template.model small;定義程序的存儲(chǔ)模式(small表示小型模式).stack;定

6、義堆棧段 .data;定義數(shù)據(jù)段 inf1 db 0ah, 0dh, "1+2+.+$" obuf1 db 6 dup(0) obuf2 db 7 dup(0) ;除了六位數(shù)字外還要有一個(gè)=號(hào) .codestart: mov ax, data mov ds, ax mov dx, offset inf1 ;輸出 1+2+.+ mov ah, 09h int 21h mov ax, 0 ;計(jì)算1+2+3+.+n mov bx, 1loop1: add ax, bx inc bx cmp ax, 60000 jbe loop1 push ax ;將最終結(jié)果備份入棧 push b

7、x ;將n備份 pop cx mov di, offset obuf1+5 ;將cx二進(jìn)制數(shù)轉(zhuǎn)換為十進(jìn)制數(shù)并以ascii的形式存于obuf1 mov byte ptr di, '$' mov ax, cx mov bx, 10loop2: mov dx, 0 div bx add dl, 30h dec di mov di, dl or ax, ax jnz loop2 mov dx, di ;輸出n mov ah, 09h int 21h pop ax mov di, offset obuf2+6 ;將ax中的二進(jìn)制數(shù)轉(zhuǎn)換為十進(jìn)制數(shù)并以ascii的形式存于obuf2 mov

8、byte ptr di, '$' mov bx, 10loop3: mov dx, 0 div bx add dl, 30h dec di mov di, dl or ax, ax jnz loop3 dec di mov di, '=' mov dx, di ;=輸出結(jié)果 mov ah, 09h int 21h mov ax, 4c00h int 21h end start實(shí)驗(yàn)習(xí)題2源碼:; multi-segment executable file template.model small;定義程序的存儲(chǔ)模式(small表示小型模式).stack;定義堆棧段

9、 .data;定義數(shù)據(jù)段 inf1 db 'Please input six num:', 0ah, 0dh, '$' inf2 db 'sum:$' obuf0 db 0ah, 0dh, '$' ibuf db 5, 0, 4 dup(0) obuf db 6 dup(0).codestart: mov ax, data mov ds, ax mov dx, offset inf1 ;輸出提示信息 mov ah, 09h int 21h mov bx, 6 ;設(shè)置外層循環(huán)次數(shù)loop1: mov dx, offset ibuf

10、mov ah, 0Ah int 21h mov cl, ibuf+1 ;設(shè)置內(nèi)層循環(huán)次數(shù) mov ch, 0 mov si, offset ibuf+2 mov ax, 0loop2: mov dx, 10 ;將屏幕輸入的十進(jìn)制數(shù)(存放于ibuf)轉(zhuǎn)化為二進(jìn)制數(shù)存儲(chǔ)于ax中 mul dx and byte ptrsi, 0Fh add al, si adc ah, 0 inc si loop loop2 push ax ;將結(jié)果入棧保存 mov dx, offset obuf0 ;回車換行 mov ah, 09h int 21h dec bx cmp bx, 0 jnz loop1 mov c

11、x, 6 mov ax, 0 loop3: pop bx add ax, bx loop loop3 mov di, offset obuf+5 ;將ax中的二進(jìn)制數(shù)轉(zhuǎn)換為十進(jìn)制數(shù)并以ascii的形式存于obuf mov byte ptr di, '$' mov bx, 10loop4: mov dx, 0 div bx add dl, 30h dec di mov di, dl or ax, ax jnz loop4 mov dx, offset inf2 ;輸出提示信息 mov ah, 09h int 21h mov dx, di mov ah, 09h int 21h m

12、ov ax, 4c00h int 21h end start實(shí)驗(yàn)習(xí)題3源碼:; multi-segment executable file template.model small;定義程序的存儲(chǔ)模式(small表示小型模式).stack;定義堆棧段 .data;定義數(shù)據(jù)段 inf db "Please input a num(0-65535):$" inf2 db 0ah, 0dh, "The num of 1:$" ibuf db 6, 0, 5 dup(0) obuf db 6 dup(0).codestart: mov ax, data mov

13、ds, ax mov es, ax mov ah, 09h ;輸出提示信息Please input a num: mov dx, offset inf int 21h mov ah, 0Ah ;接收一個(gè)無符號(hào)十進(jìn)制整數(shù)(小于65536) mov dx, offset ibuf int 21h mov ax, 0 mov cl, ibuf+1;將屏幕輸入的十進(jìn)制數(shù)(存放于ibuf)轉(zhuǎn)化為二進(jìn)制數(shù)存儲(chǔ)于ax中 mov ch, 0 mov si, offset ibuf+2loop1: mov dx, 10 mul dx and byte ptrsi, 0Fh add al, si adc ah,

14、0 inc si loop loop1 mov bx, 0 loop2: shr ax, 1 adc bx, 0 cmp ax, 0 jnz loop2 mov ax, bx mov di, offset obuf+5 ;將ax中的二進(jìn)制數(shù)轉(zhuǎn)換為十進(jìn)制數(shù)并以ascii的形式存于obuf mov byte ptr di, '$' mov bx, 10loop3: mov dx, 0 div bx add dl, 30h dec di mov di, dl or ax, ax jnz loop3 mov ah, 09h ;輸出提示信息The num of 1: mov dx, of

15、fset inf2 int 21h mov ah, 09h ;將統(tǒng)計(jì)結(jié)果在屏幕上顯示出來 mov dx, di int 21h mov ax, 4c00h int 21h end start實(shí)驗(yàn)習(xí)題4源碼:; multi-segment executable file template.model small;定義程序的存儲(chǔ)模式(small表示小型模式).stack;定義堆棧段 .data;定義數(shù)據(jù)段 N equ 5 ibuf db 4, 0, 3 dup(0) inf1 db 'Please input N num(0-255):', 0ah, 0dh, '$'

16、; inf2 db 'Sort:', 0ah, 0dh, '$' buf db N dup(0) obuf2 db 4 dup(0) obuf db 0ah, 0dh, '$' .codestart: mov ax, data mov ds, ax mov dx, offset inf1 ;輸出提示信息 mov ah, 09h int 21h mov di, offset buf mov bx, N ;設(shè)置外層循環(huán)次數(shù)loop1: mov dx, offset ibuf mov ah, 0Ah int 21h mov cl, ibuf+1 ;設(shè)置

17、內(nèi)層循環(huán)次數(shù) mov ch, 0 mov si, offset ibuf+2 mov ax, 0loop2: mov dx, 10 ;將屏幕輸入的十進(jìn)制數(shù)(存放于ibuf)轉(zhuǎn)化為二進(jìn)制數(shù)存儲(chǔ)于ax中 mul dx and byte ptrsi, 0Fh add al, si inc si loop loop2 mov di, al inc di mov dx, offset obuf ;回車換行 mov ah, 09h int 21h dec bx cmp bx, 0 jnz loop1 mov bx, N-1 ;比較大小 mov cx, bx mov dx, bx mov di, offse

18、t bufloop3: mov si, di mov al, di inc siloop4: cmp si, al jbe loop5 mov al, si mov ah, di mov si, ah mov di, alloop5: inc si loop loop4 dec dx mov cx, dx inc di dec bx cmp bx, 0 jne loop3 mov dx, offset inf2 ;輸出提示信息 mov ah, 09h int 21h ;結(jié)果輸出 mov cx, N mov si, offset bufloop6: mov di, offset obuf2+3

19、;將buf中的二進(jìn)制數(shù)轉(zhuǎn)換為十進(jìn)制數(shù)并以ascii的形式存于obuf2,并輸出 mov byte ptr di, '$' mov bx, 10 mov al, si mov ah, 0loop7: mov dx, 0 div bx add dl, 30h dec di mov di, dl or ax, ax jnz loop7 mov dx, di mov ah, 09h int 21h mov dx, offset obuf mov ah, 09h int 21h inc si loop loop6 mov ax, 4c00h int 21h end start 3、實(shí)驗(yàn)結(jié)

20、果 (1) 實(shí)驗(yàn)結(jié)果(2) 實(shí)驗(yàn)習(xí)題1程序流程圖:(3) 實(shí)驗(yàn)習(xí)題2(4) 實(shí)驗(yàn)習(xí)題3(5) 實(shí)驗(yàn)習(xí)題4 3、 實(shí)驗(yàn)總結(jié) 1)通過本次實(shí)驗(yàn)我掌握循環(huán)程序的設(shè)計(jì)方法,掌握比較指令、轉(zhuǎn)移指令和循環(huán)指令的使用方法,進(jìn)一步掌握了調(diào)試工具的使用方法。 2)在實(shí)驗(yàn)過程中我也遇到過許多困難,我覺的最大的困難時(shí)匯編難于調(diào)試,特別是代碼寫的很多的時(shí)候,某處的錯(cuò)誤很難能夠查的出來。我的辦法是每寫一段程序就調(diào)試一下是否是正確的,比如說本次的實(shí)驗(yàn)大致可分為五個(gè)功能片段,第一個(gè)是輸出信息,第二個(gè)是接受屏幕上的數(shù)字串,第三個(gè)是將數(shù)字串轉(zhuǎn)化為二進(jìn)制數(shù),第四是累加求和,第五是將二進(jìn)制數(shù)轉(zhuǎn)化為十進(jìn)制數(shù)形式的數(shù)字串??梢杂梅珠_來調(diào)試的方法,通過一條功能后在進(jìn)行下一條功能的書寫與調(diào)試工作。另

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論