




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)
文檔簡介
1、0實驗一實驗一 基本程序編程和程序調(diào)試基本程序編程和程序調(diào)試一、實驗?zāi)康?、掌握數(shù)碼轉(zhuǎn)換等基本程序設(shè)計的技巧和方法。2、熟悉 debug 命令。3、學(xué)會和掌握用 debug 調(diào)試程序的方法。二、實驗設(shè)備pc 機(jī)一臺,裝有 dos 基本系統(tǒng)三、實驗內(nèi)容及步驟用 debug 建立、匯編和運(yùn)行調(diào)試程序的操作。debug 是 dos 系統(tǒng)支持的用于匯編語言源程序調(diào)試的系統(tǒng)軟件。它共有 19 條命令完成相應(yīng)的功能,命令及其格式可參閱附錄一。(一) debug 操作練習(xí)1)實驗調(diào)試程序程序的功能是從 3500h 內(nèi)存單元開始建立 0-15 共 16 個數(shù)據(jù)。程序略。2)實驗步驟:(1)輸入與修改 啟動 d
2、os,在 dos 提示符下輸入 debug 后回車,屏幕立即顯示 debug 提示符“” ,表明已進(jìn)入 debug 狀態(tài),可以執(zhí)行 debug 的各種命令。 用 debug 中的匯編命令“a 地址”將程序建立在內(nèi)存單元中。在提示符“”下鍵入 :“a 2000 ”此時顯示器上將會顯示程序的段地址 cs 和偏移地址 ip,則可以輸入以上的程序了。 用反匯編命令“u 地址”檢查程序:在提示符“”下,鍵入 “u 2000” ,將從 2000 內(nèi)存單元開始的內(nèi)容反匯編,屏幕上即顯示:(2)顯示和修改數(shù)據(jù)1用修改內(nèi)存單元命令 “e 地址” 在指定內(nèi)存單元中存入一個數(shù)。如要在 3500 為首址的單元中存入
3、14h 和 25h 兩個數(shù)據(jù),可在提示符“”下,鍵入:“e 3500”用顯示內(nèi)存命令 “d 地址” 檢查指定單元的內(nèi)容,在提示符“”下,鍵入 “d3500”用顯示和修改命令 “r ”或“r 寄存器名”顯示寄存器或修改其內(nèi)容,在提示符“”下,鍵入“r”(3)程序運(yùn)行程序的運(yùn)行方式有單步運(yùn)行、斷點運(yùn)行和連續(xù)運(yùn)行幾種方式。單步運(yùn)行 輸入 debug 跟蹤命令“t”或“t=地址”或“t=地址 指定次數(shù)” ,可從指定地址處運(yùn)行該單元中的一條指令,以后只要連續(xù)輸入“t”命令就能連續(xù)執(zhí)行一條一條指令。如在提示符“”下,鍵入“t=2000 ”斷點運(yùn)行用運(yùn)行命令 “g=地址 地址斷點 地址斷點”執(zhí)行指定地址的程
4、序,在提示符“”下,鍵入“g=2000 2011 ”2連續(xù)運(yùn)行輸入 debug 命令“g=地址” ,執(zhí)行指定地址的程序。(4)用顯示內(nèi)存命令檢查運(yùn)行結(jié)果,在提示符“”下,鍵入命令“d 地址” ,根據(jù)其中的內(nèi)容判斷程序運(yùn)行是否正確。如檢查以上程序執(zhí)行后的結(jié)果,在提示符“”下,鍵入“ d 3500” (二)數(shù)碼轉(zhuǎn)換程序及其調(diào)試1將 ascii 碼表示的十進(jìn)制數(shù)轉(zhuǎn)換為二進(jìn)制數(shù)1)程序設(shè)計的算法及其程序,十進(jìn)制數(shù)據(jù)可表示為:di代表十進(jìn)制數(shù) 1,2,3,9,0 上式可轉(zhuǎn)換為: 由上式可歸納十進(jìn)制數(shù)轉(zhuǎn)換為二進(jìn)制數(shù)的方法:從十進(jìn)制的最高位 dn 開始乘 10 加次位的操作,將結(jié)果再乘 10 再加下一次位,
5、如此重復(fù),則可求出二進(jìn)制數(shù)結(jié)果來。2)實驗步驟(1)輸入程序并檢查無誤。iniinnnndddd10101010000110121010)10)10)10(10ddddddnnninii(3(2)在 3500h3504h 單元存入十進(jìn)制數(shù) 12 的 ascii 碼,即 e3500h,并輸入3030303132h。(3)g=2000,運(yùn)行程序,并用 ctrl+c 來中斷程序返回監(jiān)控狀態(tài)。(4)用 d3510來查看結(jié)果,應(yīng)為:3510 0c 00(5)反復(fù)試幾組數(shù),考查程序的正確性。42將十進(jìn)制數(shù)的 ascii 碼轉(zhuǎn)換為 bcd 碼1)程序流程和程序設(shè)從鍵盤輸入的五位十進(jìn)制數(shù)的 ascii 碼已存
6、放在 3500h 起始的內(nèi)存單元內(nèi),把它轉(zhuǎn)換成 bcd 碼后,再按位分別存入 350ah 起始的內(nèi)存單元內(nèi)。若輸入的不是十進(jìn)制數(shù)的 ascii 碼,則對應(yīng)存放結(jié)果的內(nèi)容為“ff” 。一字節(jié) ascii 碼取其低四位即變?yōu)?bcd 碼。2)實驗步驟(1) 輸入程序并檢查無誤。(2) 在 3500h3504h 單元中存入五位十進(jìn)制數(shù)的 ascii 碼,即e3500,并輸入 31,32,33,34,35。(3) g=2000,運(yùn)行以上程序。(4) d350a,顯示結(jié)果為:0000:350a 01 02 03 04 05 cc(5) 反復(fù)試幾組數(shù),考查程序的正確性。53將十六位二進(jìn)制數(shù)轉(zhuǎn)換為 asci
7、i 碼表示的十進(jìn)制數(shù)1)程序及其流程:十六位二進(jìn)制數(shù)的值域為 065535,最大可轉(zhuǎn)換為五位十進(jìn)制數(shù)。算法:五位十進(jìn)制數(shù)可表示為:因此,將十六位二進(jìn)制數(shù)轉(zhuǎn)換為五位 ascii 碼表示表示的十進(jìn)制數(shù),就是求d1d4,并將它化為 ascii 碼。2)實驗步驟(1) 輸入程序并檢查無誤。dddddnd6(2) 在 35003501h 單元中存放 0c00,運(yùn)行程序并檢查結(jié)果,應(yīng)看到35103514h 單元中的數(shù)依次為 3030303132。(3) 反復(fù)試幾組數(shù),并運(yùn)行程序、觀察結(jié)果。4十六進(jìn)制數(shù)轉(zhuǎn)換為 ascii 碼1)程序及其流程經(jīng)過 cpu 處理后的十六進(jìn)制數(shù)存放在起始地址為 3500h 的內(nèi)存
8、單元中,把它們轉(zhuǎn)換成 ascii 碼之后,再分別存入起始地址為 350ah 的內(nèi)存單元中。十六進(jìn)制數(shù)加 30h 即可得到 0h9h 的 ascii 碼,而要得到 ahfh 的 ascii碼,則需再加 7h。2)實驗步驟(1) 輸入程序并檢查無誤。7(2) 在 35003501h 單元中存入四位十六進(jìn)制數(shù) 203b,即 e3500,并輸入 3b,20。(3) g=2000,運(yùn)行以上程序(4) d350a,顯示結(jié)果為:0000:350a 42 33 30 32 cc輸入數(shù)據(jù)與結(jié)果 ascii 碼對應(yīng)順序相反。(5) 反復(fù)試幾組數(shù)。考查程序的正確性。85bcd 碼轉(zhuǎn)換為二進(jìn)制數(shù) 1)程序及其流程設(shè)四
9、個二位十進(jìn)制數(shù)的 bcd 碼存放在起始地址為 3500h,的單元中,轉(zhuǎn)換出的二進(jìn)制數(shù)碼存入起始地址為 3510h 的內(nèi)存單元中。 2)實驗步驟 (1)輸入程序并檢查無誤。 (2)在 35003507 單元中存入四個十進(jìn)制數(shù)(12,34,56,78)的 bcd 碼,即 e3500 輸入 01,02,03,04,05,06,07,08。 (3)g=2000,運(yùn)行以上程序。 (4)d3510,顯示結(jié)果為 3510 0c 00 22 00 38 00 4e 00 (5)反復(fù)試幾組數(shù),考查程序的正確性。9四、思考題1、圖 1-1 程序,將一個五位十進(jìn)制數(shù)轉(zhuǎn)換為二進(jìn)制數(shù)(十六位)時,這個十進(jìn)制數(shù)最小可為多
10、少,最大又可為多少?為什么?2、將一個十六位二進(jìn)制數(shù)轉(zhuǎn)換為 ascii 碼十進(jìn)制數(shù)時,如何確定 d1的值?3、在十六進(jìn)制數(shù)轉(zhuǎn)換為 ascii 碼時,存轉(zhuǎn)換結(jié)果后,為什么要把 dx 向右移四次?104、自編 ascii 碼十六進(jìn)制、十進(jìn)制小數(shù)二進(jìn)制、二進(jìn)制bcd 碼的程序,并調(diào)試運(yùn)行。5、(1) ascii 碼十六進(jìn)制data segment data1 db 45h,34h,38h,43hbin db 4 dup (?)data endscode segment assume cs:code,ds:datastart: mov ax,data mov ds,axmov cx,04h mov s
11、i,offset data1mov di,offset binnext: mov al,si sub al,30hcmp al,0ahjb less1sub al,07hless1: inc si mov di,alinc diloop nextmov ah,4chint 21hcode endsend start(2)十進(jìn)制小數(shù)二進(jìn)制data segment inc sidata1 db 33h,38h,30h,35h loop again1bin db 4 dup (?) mov cx,02h11data ends xor ax,axcode segment assume cs:code,
12、ds:datastart: mov ax,data mov ds,axmov cx,02h mov si,offset data1mov di,offset binxor ax,axagain1: add ax,ax mov bx,axadd ax,axadd ax,axadd ax,bxmov bh,0hmov bl,si sub bl,30hadd ax,bxagain2: add ax,ax mov bx,axadd ax,axadd ax,axadd ax,bxmov bh,0hmov bl,si sub bl,30hadd ax,bxinc siloop again2mov di+0
13、2h,axmov ah,4chint 21hcode ends end start12(3)二進(jìn)制bcd 碼data segment bin dw 0cccchasdec db 5 dup (?)pwtab dw 10000,1000,100,10,1data endscode segment assume cs:code,ds:datastart: mov ax,data mov ds,axmov di,offset asdecmov si,offset pwtabmov ax,binlop1: xor cl,cl mov bx,silop2: sub ax,bx jb nextinc cl
14、jmp lop2next: add ax,bx mov di,clinc siinc siinc dicmp bx,1jnz lop1mov ah,4chint 21hcode ends end start1314實驗二實驗二 程序設(shè)計和程序設(shè)計和 pcpc 機(jī)上程序調(diào)試操作實驗機(jī)上程序調(diào)試操作實驗一、實驗?zāi)康?掌握常用程序設(shè)計的基本技巧和方法。2學(xué)會和熟悉使用 masm 匯編程序和 link 連接程序。3掌握使用 pc 機(jī)上編程和調(diào)試程序的方法。二、實驗設(shè)備pc 機(jī)一臺,裝有 dos 基本系統(tǒng)和 masm 宏匯編軟件三、實驗內(nèi)容及步驟(一)按要求編寫程序并在 debug 下建立、匯編和調(diào)試程
15、序1、四字節(jié)二進(jìn)制數(shù)的加法1)程序設(shè)計要求兩個字的被加數(shù)存放于 3500h3503h 單元,加數(shù)存于 3504h3507h 單元(存放格式為高位存高地址單元,低位存低地址單元) ,兩數(shù)之和(如不超過四字節(jié))存放于 3508h350bh 單元。2)實驗步驟(1)編寫程序。 (2)在 debug 下輸入程序并檢查(程序可存放于 2000h8000h 單元) 。(3)在 3500h3507h 單元中存入被加數(shù) 014527 和加數(shù) 146758。(4)運(yùn)行程序后,檢查 3508h350bh 單元中內(nèi)容。(5)反復(fù)選擇幾組被加數(shù)和加數(shù),檢查結(jié)果,驗證程序正確性。152、數(shù)據(jù)塊的搬移1)程序設(shè)計思想和要
16、求將內(nèi)存中一數(shù)據(jù)區(qū)中數(shù)據(jù)(源數(shù)據(jù)塊)傳送到另一數(shù)據(jù)區(qū)(目的數(shù)據(jù)塊) 。源數(shù)據(jù)塊和目的數(shù)據(jù)塊區(qū)在內(nèi)存中的位置有兩種情況:兩區(qū)重疊和不重疊,如下圖所示。對于兩個數(shù)據(jù)塊不重疊的情況,數(shù)據(jù)的傳送可從數(shù)據(jù)塊的首址開始,也可從數(shù)據(jù)塊的末址開始;對于兩個數(shù)據(jù)塊重疊的情況,則要加以分析,否則重疊部分會因搬移而遭破壞。處理方法可以是:在源數(shù)據(jù)塊首址目的數(shù)據(jù)塊首址時,從數(shù)據(jù)塊的首址開始傳送,在數(shù)據(jù)塊首址目的數(shù)據(jù)塊首址時,從數(shù)據(jù)塊的末址開始傳送。若源數(shù)據(jù)塊首址存放于 si 中,目的數(shù)據(jù)塊首址存放于 di 中,塊字節(jié)數(shù)存放于 cx 中。要求設(shè)計的程序能夠?qū)崿F(xiàn)不同情況下的數(shù)據(jù)塊傳送。2)實驗步驟(1)編寫程序。(2)在
17、 debug 下鍵入程序并檢查(程序可存放于 2000h8000h 單元) 。(3)確定源數(shù)據(jù)塊和目的數(shù)據(jù)塊區(qū)不重疊時的首址,確定數(shù)據(jù)塊個數(shù)為 16個,并在源數(shù)據(jù)區(qū)送入任意 16 個數(shù)據(jù)。(4)運(yùn)行程序后,檢查目的數(shù)據(jù)區(qū)的內(nèi)容。16(5)確定源數(shù)據(jù)塊和目的數(shù)據(jù)塊區(qū)重疊時, 源區(qū)首址目的區(qū)首址時的首址, 以及數(shù)據(jù)塊個數(shù)為 16 個,并在源數(shù)據(jù)區(qū)送入任意 16 個數(shù)據(jù)。運(yùn)行程序后,檢查目的數(shù)據(jù)區(qū)的內(nèi)容。(6)確定源數(shù)據(jù)塊和目的數(shù)據(jù)塊區(qū)重疊時, 源區(qū)首址目的區(qū)首址時的首址, 以及數(shù)據(jù)塊個數(shù)為 16 個,并在源數(shù)據(jù)區(qū)送入任意 16 個數(shù)據(jù)。運(yùn)行程序后,檢查目的數(shù)據(jù)區(qū)的內(nèi)容。173、無序數(shù)據(jù)塊的遞增排序
18、1)程序設(shè)計思想和要求在首址為 3000h 的數(shù)據(jù)區(qū)中存放著一組無符號數(shù), 數(shù)據(jù)的長度存于 3500h單元內(nèi),要求用冒泡法對該區(qū)中的數(shù)據(jù)按遞增次序排列。冒泡法的基本思想是從最后一個數(shù)(或從第一個數(shù))開始,依次把相鄰兩個數(shù)比較,即第個數(shù)與第個數(shù)比較,若大則交換,否則不交換,直到個數(shù)都比較完為止。此時,其中最小數(shù)排在最前列。然后將剩下的-1 個數(shù)再按前述方法進(jìn)行,找到 n-1 個數(shù)中最小的數(shù)。以后重復(fù)進(jìn)行,直到全部按序排列。2)實驗步驟 (1)編寫程序。 (2)在 debug 下鍵入程序并檢查(程序可存放于 2000h8000h 單元,只要不與數(shù)據(jù)區(qū)重疊即可) 。 (3)確定數(shù)據(jù)個數(shù)并輸入 350
19、0h 單元中,在首址為 3500h 的數(shù)據(jù)區(qū)中存入任意無符號數(shù)。 (4)運(yùn)行程序并檢查運(yùn)行結(jié)果。 (5)反復(fù)修改數(shù)據(jù)個數(shù)和數(shù)據(jù)區(qū)中的數(shù),運(yùn)行程序、觀察結(jié)果,驗證程序的正確性。184、求數(shù)的平方根)程序設(shè)計思想和要求減奇數(shù)法是一種求取近似平方根和平方根的整數(shù)部分的方法。有公式: n12) 12(knk若要求數(shù) s 的平方根 s, 則可以從 s 中減去奇數(shù) 1、3、5直到減為零或不夠減下一個奇數(shù)為止,然后統(tǒng)計減去的奇數(shù)個數(shù),它就是 s 的近似平方根。19被開方數(shù)為一個足夠大的二進(jìn)制數(shù), 存于首址為 4000h 的單元內(nèi),它的方根存放在以 4500h 為首的單元內(nèi)。2)實驗步驟(1)編寫程序(2)在
20、 debug 下輸入程序并檢查(程序可存放于 2000h8000h 單元,和數(shù)據(jù)存放單元不要重疊) 。(3)在 4000h 為首的單元中存入一個任意大的數(shù)。(4)運(yùn)行程序并檢查運(yùn)行結(jié)果。(5)反復(fù)修改被開方數(shù),運(yùn)行程序、觀察結(jié)果,驗證程序的正確性。205、思考題 如果二進(jìn)制加數(shù)和被加數(shù)不限于四字節(jié)而為任意字節(jié)時,程序應(yīng)作如何改動? 修改原有的無符號數(shù)的排序程序為帶符號數(shù)的排序程序。 被開方數(shù)是一壓縮型的 bcd 碼十進(jìn)制數(shù)時,程序應(yīng)作如何修改?(二)二)masmmasm 匯編程序和匯編程序和 linklink 連接程序的使用操作連接程序的使用操作在 debug 中,使用 a 命令建立程序,一般
21、不能使用標(biāo)號和偽指令,并不能保存匯編語言源程序,適用于簡單程序。masm 宏匯編程序可以將編輯程序建立的源程序文件進(jìn)行匯編,匯編后在盤上建立目標(biāo)文件、列表文件和交叉參考文件。而目標(biāo)文件經(jīng) link 程序連接以后成為可執(zhí)行的文件,它可以在 dos 下執(zhí)行21也可在 debug 下調(diào)試。1、計算機(jī)鋼琴程序1)實驗內(nèi)容根據(jù)樂曲中不同的音符是由輸出不同頻率的聲波而產(chǎn)生的原理,通過設(shè)置pc 機(jī)中 8253 定時器不同的計數(shù)值,可由揚(yáng)聲器發(fā)出不同的曲調(diào)。 以下是實現(xiàn)pc 機(jī)作為一架可彈奏的鋼琴演奏預(yù)定的曲調(diào)。程序中采用了 int 21h 軟中斷調(diào)用了 dos 的常用子程序。2)在 dos 下直接鍵入由 m
22、asm 宏匯編和 link 連接程序生成的可執(zhí)行文件文件名playpia,運(yùn)行程序觀察運(yùn)行結(jié)果。3)修改程序中延時子程序的循環(huán)次數(shù),重新匯編、連接后運(yùn)行。2、求數(shù)據(jù)塊的最小值和最大值1)實驗內(nèi)容在以 buffer 為首址的內(nèi)存中存放了若干個帶符號數(shù), 其個數(shù)存放在首單元,尋找出它們最大值放到存儲單元 maxval 中, 最小值放到存儲單元 minval中。匯編語言源程序代碼略。 2)實驗步驟(1)用編輯程序建立源程序文件,文件名自定。(2)用 masm 宏匯編程序和 link 連接程序?qū)⒃闯绦蛭募R編生成以 exe 為擴(kuò)展名的執(zhí)行文件。(3)用 debug 調(diào)試程序?qū)⒂缮袭a(chǎn)生的 exe 可執(zhí)行
23、文件送入內(nèi)存,先用反匯編命令檢查程序內(nèi)容和首末地址,然后檢查以 buffer 為首址的存儲單元中數(shù)據(jù)塊和minval、maxval 單元的內(nèi)容。buffer 地址單元的段地址和偏移地址是由系統(tǒng)在匯編和連接時指定的。各個不同的系統(tǒng)都不一樣,一般來說,偏移地址為零,段地址可在反匯編程序時,根據(jù)指令 mov ax, data 對應(yīng)機(jī)器碼中 data 的值來確定。(4)在 debug 下運(yùn)行程序,檢查運(yùn)行結(jié)果。(5)修改源程序中 buffer 數(shù)據(jù)區(qū)的各數(shù)據(jù),重新匯編后再運(yùn)行,檢查結(jié)果。3、從無序數(shù)列中刪除一個元素1)實驗內(nèi)容在 buffer 為首址的內(nèi)存區(qū)中存放了一個無序字符串,其長度存放在第一個字
24、節(jié)單元,在 key 單元內(nèi)存放了要刪除的一個字符,查找此無序字串,若找到則刪除并作相應(yīng)調(diào)整,若字串中無此字符則在 flag 單元內(nèi)置 ffh 標(biāo)志。其程序流程22圖如下。2)實驗步驟(1)按以上框圖編寫程序,并任意設(shè)定字符個數(shù)和字符串。(2)輸入?yún)R編語言源程序,文件名自定。(3)用 masm 和 link 程序匯編和連接生成 exe 執(zhí)行程序。(4)運(yùn)行該程序,并檢查結(jié)果。(5)修改字符串及其個數(shù),再運(yùn)行程序,驗證程序的正確性。data segmentbuffer db asdnhjtgftrghngyh,$key db tflag db ?code segmentassume cs:code
25、,ds:datastart:mov ax,data mov ds,ax lea ax,buffer lea bx,key mov si,ax mov di,bx mov cx,0019 mov al,dicontinue:mov bl,si cmp bl,al jz move add si,1 loop continue lea ax,flag mov di,ax mov ax,0ffh mov di,ax jmp completemove:sub cx,1take:mov ah,si+1 xchg ah,si add si,1 loop takecomplete:mov dx,offset
26、buffer mov ah,9 int 21h mov ah,7 int 21h mov ah,41h int 21hcode endsend start4 4、思考題、思考題 計算機(jī)鋼琴程序中,int 21 的作用是什么?指令 div word ptrtable+bx中為什么要用操作符 word ptr?延時子程序 delay 中為什么要把 ax、cx 壓入棧? 在求最大和最小值的程序中,有指令 mov minval,al 和 mov max maxval,al 將第一個數(shù)存入這兩個單元,可以用哪兩個立即數(shù)直接存入這兩個單元也可達(dá)到同樣效果? 若求無符號數(shù)據(jù)塊的最大和最小值,那么程序要作哪些
27、修改? 刪除一個升序或降序字符串中一個字符時,程序應(yīng)如何修改可使在找不到這個字符時搜集次數(shù)減少?23實驗三實驗三 dosdos 系統(tǒng)功能調(diào)用及模塊化程序設(shè)計系統(tǒng)功能調(diào)用及模塊化程序設(shè)計一、實驗?zāi)康?、熟悉 dos 系統(tǒng)中基本功能子程序的作用及其調(diào)用方法。2、結(jié)合 dos 系統(tǒng)中鍵盤和顯示功能子程序的調(diào)用和匯編語言源程序結(jié)構(gòu)設(shè)計有關(guān)程序。3、掌握復(fù)雜程序的設(shè)計思想模塊化程序設(shè)計的方法。二、實驗設(shè)備pc 機(jī)一臺,裝有 dos 基本系統(tǒng)和 masm 宏匯編軟件。三、實驗內(nèi)容及步驟(一)dos 鍵盤、顯示基本功能子程序調(diào)用dos 提供了許多系統(tǒng)功能子程序可由程序設(shè)計者調(diào)用,其中最基本的是鍵盤和顯示操作
28、功能的調(diào)用,具體調(diào)用的方法可參閱教科書。1、顯示緩沖區(qū)的字符串1)實驗程序代碼略2)實驗步驟: (1)建立源程序文件。(2)用 masm 宏匯編程序和 link 連接程序生成執(zhí)行程序。(3)運(yùn)行執(zhí)行程序,輸入不同字母,觀察結(jié)果。242、鍵盤輸入小寫字母,顯示器顯示大寫字母1)實驗程序代碼略2) 實驗步驟: (1)建立源程序文件。(2)用 masm 宏匯編程序和 link 連接程序生成執(zhí)行程序。(3)運(yùn)行執(zhí)行程序,輸入不同字母,觀察結(jié)果。3、從鍵盤輸入一個二位十進(jìn)制的月份數(shù)(01-12) ,顯示相應(yīng)月份的英文縮寫名1)程序及其結(jié)構(gòu) 程序采用子程序的結(jié)構(gòu)形式,子程序有:將輸入的二位月份數(shù)轉(zhuǎn)換為二進(jìn)
29、制數(shù)的子程序;從字符表中查找相應(yīng)的英文縮寫的子程序;將月份的英文字母顯示在屏幕上的子程序。程序如下代碼略。25 (二)采用 dos 功能調(diào)用設(shè)計源程序,并運(yùn)行調(diào)試程序1、十進(jìn)制加法和結(jié)果顯示程序(自行設(shè)計)1)程序設(shè)計要求將數(shù)據(jù)段 dseg 中的 addop1 定義的雙字變量的 4 位十進(jìn)制數(shù)和附加段 eseg中的 addop2 定義的雙字變量的 4 位十進(jìn)制數(shù)相加,和存放于數(shù)據(jù)段 dseg 中的sum 中,采用 dos 顯示功能調(diào)用將和顯示在屏幕上。2)實驗步驟: (1)建立源程序文件,程序代碼略。(2)用 masm 宏匯編程序和 link 連接程序生成執(zhí)行程序。(3)運(yùn)行執(zhí)行程序,輸入不同
30、的加數(shù)和被加數(shù),觀察結(jié)果。dsegsegmentaddop1dd1234sumdd ?dsegendsesegsegmentaddop2dd2345esegendsstack segmentparastack stack db 100 dup(?)stack endscodesegmentassumeds:dseg,cs:code,es:esegstart: movax,dsegmovds,axmovax,esegmoves,axmovax,wordptraddop1addax,word ptraddop2movword ptr sum,axmovax,word ptr addop1+2adc
31、ax,word ptr addop2+2movword ptr sum+2,axmovbx,word ptrsum+2call displaymovbx,word ptrsumcall displaymovah,4chint 21h26 display proc nearmov cx,10000d call dec_divmov cx,1000d call dec_divmov cx,100d call dec_divmov cx,10d call dec_divmov cx,1d call dec_divret dec_div proc near mov ax,bx mov dx,0 div
32、 cx mov bx,dx mov dl,al ;print the contents of dl on screenadd dl,30h mov ah,2hint 21h ret dec_div endpdisplay endpcode endsend start2、十進(jìn)制加法和算式顯示程序(自行設(shè)計)1) 程序設(shè)計要求在以上十進(jìn)制數(shù)加法要求的基礎(chǔ)上,將加法算式及和在顯示器上顯示。如 addop1 中存放 1234h,在 addop2 中存放 6789h,執(zhí)行程序后顯示器上顯示:1234+6789=80232) 實驗步驟: (1)建立源程序文件。(2)用 masm 宏匯編程序和 link 連
33、接程序生成執(zhí)行程序。(3)運(yùn)行執(zhí)行程序,輸入不同的加數(shù)和被加數(shù),觀察結(jié)果。dsegsegmentaddop1dd1234jiahao db +,$denghao db =,$ten dw 10sum dd?dsegendsesegsegmentaddop2dd6789esegendsstack segment parastack stack db 100 dup(?)27stackendscodesegmentassumeds:dseg,cs:code,es:esegstart:mov ax,dsegmov ds,axmov ax,esegmov es,axmov ax,word ptr ad
34、dop1add ax,word ptr addop2mov word ptr sum,axmov ax,word ptr addop1+2adc ax,word ptr addop2+2mov word ptr sum+2,ax mov bx,word ptr addop1+2calldisplaymov bx,word ptr addop1calldisplaymov ah,09hmov dx,offset jiahaoint 21hmov bx,word ptr addop2+2calldisplaymov bx,word ptr addop2calldisplaymov ah,09hmo
35、v dx,offset denghaoint 21hmov bx,word ptr sum+2call displaymov bx,word ptr sumcall displaymov ah,4chint 21hdisplay proc nearmov cx,10000d call dec_divmov cx,1000d call dec_divmov cx,100d call dec_divmov cx,10d call dec_divmov cx,1d call dec_divret dec_div proc near mov ax,bx mov dx,0 div cx mov bx,d
36、x mov dl,al ;print the contents of dl on screenadd dl,30h mov ah,2h int 21h ret dec_div endpdisplay endpcode endsend start283、鍵盤輸入加數(shù)和被加數(shù)進(jìn)行十進(jìn)制數(shù)加法,顯示結(jié)果程序(自行設(shè)計)1)程序設(shè)計要求采用 dos 的鍵盤功能調(diào)用和顯示功能調(diào)用,將鍵盤輸入的 4 位十進(jìn)制被加數(shù)和 4 位加數(shù)相加,和存入有關(guān)內(nèi)存單元,并將算式及和顯示在顯示器上。要求采用子程序的設(shè)計方法設(shè)計程序,例如設(shè)計一個從鍵盤讀入輸入數(shù)據(jù)的子程序和將數(shù)據(jù)顯示的子程序。dsegsegmentaddop
37、dw2 dup(?)addop1dd?jiahao db +,$denghao db =,$ten dw 10sumdd?go db please input two number: $goo db the sum is: $tishi db the number you input is not right,must 10000,please input again! $dsegendsesegsegmentaddop2dd?esegendsstack segment parastack stack db 100 dup(?)stackendscodesegmentassumeds:dseg
38、,cs:code,es:esegstart:mov ax,dsegmov ds,axmov ax,esegmov es,axts:mov si,0mov cx,2 lea dx, go mov ah, 09int 21hagain: push cxcall inputcmp ax,10000jl rightpop cxcall crlfmov dx,offset tishimov ah,09hint 21hcall crlfjmp tsright: mov addopsi,ax;add sum,ax29inc siinc sipop cxloop againcall crlflea dx, g
39、oo mov ah, 09int 21hmov si,0mov bx,addopsimov word ptr addop1,bxmov word ptr addop1+2,0inc siinc simov bx,addopsimov word ptr addop2,bxmov word ptr addop2+2,0push axmov ax,word ptr addop1add ax,word ptr addop2mov word ptr sum,axmov ax,word ptr addop1+2adc ax,word ptr addop2+2mov word ptr sum+2,axpop
40、 axmov bx,word ptr addop1+2calldisplaymov bx,word ptr addop1calldisplaymov ah,09hmov dx,offset jiahaoint 21hmov bx,word ptr addop2+2calldisplaymov bx,word ptr addop2calldisplaymov ah,09hmov dx,offset denghaoint 21hmov bx,word ptr sum+2call displaymov bx,word ptr sumcall displaymov ah,4chint 21hcrlf
41、proc nearmov dl,0ah mov ah,02hint 21hmov dl,0dh mov ah,02h int 21hretcrlf endpinput proc nearmov ax,0push axagain1: mov ah,01h int 21hcmp al,30h jl exitcmp al,39hjg exitsub al,30h mov bl,almov bh,0pop axcwdimul ten add ax,bxpush axjmp again1exit:pop axretinput endpdisplay proc nearmov cx,10000d call
42、 dec_divmov cx,1000d call dec_divmov cx,100d call dec_divmov cx,10d call dec_divmov cx,1d call dec_divret dec_div proc near 30mov ax,bx mov dx,0 div cx mov bx,dx mov dl,al add dl,30h mov ah,2hint 21h ret dec_div endpdisplay endpcode endsend start(三)模塊化程序設(shè)計模塊化程序設(shè)計是指將一個較大的功能分解成幾個獨立功能的子模塊,每個子模塊獨立編緝各自建立
43、一個文件,通過單獨的匯編生成各個獨立的目標(biāo)文件,然后由 link 程序?qū)⒏鱾€目標(biāo)文件鏈接在一起,形成一個完整的執(zhí)行文件。1)實驗程序的設(shè)計思想及其實現(xiàn)功能程序?qū)崿F(xiàn)鍵盤輸入十進(jìn)制數(shù),以十六進(jìn)制數(shù)形式在屏幕上顯示的功能。程序分成兩個模塊,模塊 a 為主程序,負(fù)責(zé)從鍵盤輸入一個十進(jìn)制數(shù),處理后存入指定內(nèi)存單元。模塊 b 主要實現(xiàn)屏幕提示和將十六進(jìn)制數(shù)轉(zhuǎn)換及顯示的功能。 實驗程序參見教科書“微型計算機(jī)原理及應(yīng)用” (吳寧主編)p185 頁上 模塊化程序設(shè)計例 1。extrn prompt:far,binhex:farpublicdec_num,key_inssegsegment para stack
44、stackdb100 dup(?)ssegendsdseg1 segmentdec_numdw?dseg1 endscseg1 segmentassumecs:cseg1,ds:dseg1start:mov ax,dseg1mov ds,axpushdsjmp far ptr promptkey_in:calldecbinmov dec_num,bxcallfar ptr binhexmov ah,4chint 21hdecbinprocnearmov bx,031getchar:movah,1int 21hsub al,30hjlexitcmp al,09hjgexitmov ah,0xch
45、gax,bxmov cx,0ahmul cxxchgax,bxadd bx,axjmp getcharcall crlfexit: retdecbinendpcrlf proc nearmov dl,0ah mov ah,02hint 21hmov dl,0dh mov ah,02h int 21hretcrlf endpcseg1 endsend startextrn dec_num:word,key_in:farpublicprompt,binhexssegsegment parastackstackdb200 dup(?)ssegendsdseg2 segmentmsgdbplease
46、input:$dseg2 endscseg2 segment paraassumecs:cseg2,ds:dseg2prompt:mov ax,dseg2mov ds,axlea dx,msgmov ah,09hint 21hpop dsjmp far ptr key_inbinhexprocfarcall crlfmov bx,dec_nummov ch,04hrotate:mov cl,04hrol bx,clmov al,bland al,0fhadd al,30hcmp al,3ahjlprintitadd al,07hprintit:mov dl,almov ah,02h int 2
47、1hdec chjnz rotateret binhexendpcrlf proc nearmov dl,0ah mov ah,02hint 21hmov dl,0dh mov ah,02h int 21hretcrlf endpcseg2 endsend322) 實驗步驟:(1)輸入模塊 a 程序和模塊 b 程序,各產(chǎn)生一個文件。(2)匯編兩個程序生成兩個目標(biāo)文件。(3)用 link 文件名 1+文件名 2 命令鏈接為一個可執(zhí)行文件。(4)運(yùn)行程序,輸入不同的十進(jìn)制數(shù),觀察結(jié)果。第一個文件public tishi1,tishi2extrn zc:neardata segment common
48、 da db 4 dup(?)tishi1 db please input a decimil number :,$tishi2 db the result is :,$receive db 5 dup(?)data endscode segment publicassume cs:code,ds:datastart: mov ax,data mov ds,ax call zc mov si,offset receive mov ah,1sss:int 21h mov si,al cmp al,20h jz q inc si jmp sssq: lea si,receive mov bx,10
49、 mov ax,0 mov al,si mov cx,3 sub al,30hdff: mul bx add al,si+1 adc ah,0 sub al,30h sbb ah,0 inc si loop dff call zx mov ah,7 int 21h mov ah,4ch int 21h zx proc lea di,da add di,3 mov bx,16goon: mov dx,0 div bx33 mov di,dl dec di cmp ax,0 lea si,da jmp goon jz concon:mov cx,0004continue:mov al,si cmp
50、 al,10 jb a add al,37h mov si,al inc si jmp nexa: add al,30h movsi,al inc sinex: loop continue mov ah,9 mov dx,offset tishi2 int 21h lea si,da mov ah,2 mov cx,0004ssr: mov dl,si int 21h inc si loop ssr retzx endpcode endsend start第二個文件public zcextrn tishi1:bytedata segment common db 5 dup(?)data end
51、scode segment publicassume cs:code,ds:datazc proc mov ah,9 mov dx,offset tishi1 int 21h ret zc endp code ends end (四)思考題1、在實驗(一)題 3 中,如輸入 0112 以外的數(shù)時將會出現(xiàn)什么結(jié)果?2、如果輸入非法的十進(jìn)制數(shù)時,你所設(shè)計的實驗(二)題 3 的程序是如何處理的?若無這種功能請增加提示、出錯處理等功能,完善以上程序。3、實驗(三)的程序中是否對輸入任何位的十進(jìn)制數(shù)都能在屏幕上顯示其十六進(jìn)制數(shù)?4、在實驗(三)的程序中如果以回車鍵作為對輸入數(shù)據(jù)的確認(rèn),程序應(yīng)作什么修改?
52、34實驗四實驗四 教材第四章習(xí)題程序設(shè)計教材第四章習(xí)題程序設(shè)計1試編寫一個程序段,完成兩個以壓縮 bcd 格式表示的 16 位十進(jìn)制數(shù)(8 個字節(jié))的加法運(yùn)算,相加的兩個數(shù) x 和 y 可定義為字節(jié)變量,并假定高位在前,和數(shù) sum 也同樣定義為字節(jié)變量。程序如下:data segmentorg 0000hx db 10h,11h,12h,13h,14h,15h,16h,17hy db 21h,22h,23h,24h,25h,26h,27h,28hsum db 10 dup(0)data endsstack segment para stack satckdb 100 dup(0)stack
53、ends35code segmentassume cs:code,ds:datastart:mov ax,datamov ds,axlea si,xmov cx,8lea bx,ylea di,sumagain:mov al,si+7mov dl,bx+7adc al,dl ;兩數(shù)相加daa ;bcd 運(yùn)算調(diào)整mov di+7,aldec sidec bxdec diloop againmov ah,4chint 21hcode endsend start結(jié)果如下:2從 first 開始的 10 個單元中存放著一個字符串,結(jié)束符為$ 。編寫一個程序,統(tǒng)計該字符串中字母a的個數(shù)。程序如下:data segmentorg 2000hfirst db dbabacqwe,$count db 0data endscode segmentassume cs:code,ds:datastart:mov ax,data mov ds,ax lea bx,first mov cx,10 mov dl,41h ;待統(tǒng)計字符a mov dh,0 ;統(tǒng)計個數(shù)again:cmp byte p
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 云南省楚雄彝族自治州祿豐市2024-2025學(xué)年八年級下學(xué)期開學(xué)生物學(xué)試題(含答案)
- 農(nóng)業(yè)政策支持措施作業(yè)指導(dǎo)書
- 私人美容師服務(wù)合同
- 基于大數(shù)據(jù)的商業(yè)決策支持系統(tǒng)開發(fā)合同
- 電子支付結(jié)算合作協(xié)議
- 農(nóng)業(yè)自動化系統(tǒng)安裝維護(hù)合同
- 活動籌備報告
- 《現(xiàn)代酒店管理基礎(chǔ)》(第二版)課件 任務(wù)7 酒店服務(wù)質(zhì)量管理
- 企業(yè)員工健康管理與促進(jìn)計劃指南
- 春蕾百合幼兒園入學(xué)條件
- 裝配式混凝土建筑體系介紹課件
- 零星工程(零星用工)簽認(rèn)單
- 數(shù)字邏輯-第四章-組合邏輯電路
- 菜品成本卡模版
- 最新2022年護(hù)理院基本標(biāo)準(zhǔn)
- 5G手機(jī)無線通訊濾波芯片產(chǎn)業(yè)化項目環(huán)境影響報告表
- 工會野炊活動方案
- 《對外援援助成套項目勘察設(shè)計取費(fèi)標(biāo)準(zhǔn)內(nèi)部暫行規(guī)定(稿)》
- 通用反應(yīng)單元工藝
- 空冷塔施工方案
- Inplan 操作手冊初稿
評論
0/150
提交評論