24個匯編實例小程序文件_第1頁
24個匯編實例小程序文件_第2頁
24個匯編實例小程序文件_第3頁
24個匯編實例小程序文件_第4頁
24個匯編實例小程序文件_第5頁
已閱讀5頁,還剩39頁未讀, 繼續(xù)免費閱讀

下載本文檔

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

文檔簡介

1、24 個匯編小程序題目列表:逆序輸出字符串“ BASED ADDRESSIN”G從鍵盤上輸入兩個數(shù),分別放到x, y 單元,求出它們的和試編寫一段程序, 要求在長度為 10h的數(shù)組中, 找出大于 42h的無符號數(shù)的個數(shù)并存入地址 為 up 開始區(qū)域,找出小于 42h 的無符號數(shù)的個數(shù)并存入地址為 down 的開始區(qū)域 鍵盤輸入一段字符串,其中小寫字母以大寫字母輸出,其他字符不變輸出從鍵盤上就收一個小寫字母,找出它的前導字符和后續(xù)字符,在順序顯示這三個字符把一個包含 20 個數(shù)據(jù)的數(shù)組 M分成兩組:正整數(shù)組 P 和負整數(shù)組 N,分別把這兩個數(shù)組中 的數(shù)據(jù)的個數(shù)顯示出來求出首地址為 data 的

2、100 個字數(shù)組中的最小偶數(shù),并把它放在 ax 中輸入兩船字符串 string1 和 string2 ,并比較兩個字符串是否相等,相等就顯示“match ”,否則顯示“ no match ”從鍵盤接收一個四位的十六進制數(shù),并在終端顯示與它等值的二進制數(shù)從鍵盤輸入一系列以 $為結(jié)束符的字符串,然后對其中的非數(shù)字字符計數(shù),并顯示計數(shù)結(jié)果有一個首地址為 mem的 100 個字的數(shù)組, 試編程序刪除數(shù)組中所有為零的項, 并將后續(xù)項向 前壓縮,最后將數(shù)組的剩余部分補上零從鍵盤上輸入一串字符(用回車鍵結(jié)束, 使用 10 號功能調(diào)用) 放在 string 中,是編制一個 程序測試字符串中是否存在數(shù)字。如有,

3、則把 cl 的第五位置 1,否則將該位置置 0 在首地址為 data 的字數(shù)組中,存放了 100h 的 16 位字數(shù)據(jù),試編寫一個程序,求出平均值 放在 ax 寄存器中,并求出數(shù)組中有多少個數(shù)小于此平均值,將結(jié)果放在 bx 寄存器中 (f 分 別考慮有符號數(shù)、無符號數(shù)情況 )一直數(shù)組 A包含 15 個互不相等的整數(shù), 數(shù)組 B包含 20 個互不相等的整數(shù)。 試編制一個程序, 把既在 A中又在 B 中出現(xiàn)的整數(shù)存放于數(shù)組 C中設在 A、B 和 D單元中分別存放著三個數(shù)。 若三個數(shù)都不是 0,則求出三個數(shù)的和并存放在 S 單元,若其中有一個數(shù)為 0,則把其它兩個單元也清零。請編寫此程序從鍵盤輸入一

4、系列字符(以回車鍵結(jié)束) ,并按字母、數(shù)字和其他字符分類計數(shù),最后顯示 這三類的計數(shù)結(jié)果已定義兩個整數(shù)變量 A 和 B,試編寫程序完成以下功能(1)若兩個樹種有一個是奇數(shù),則將奇數(shù)存入A 中,偶數(shù)存入 B中(2)若兩個數(shù)均為奇數(shù),則將兩個數(shù)加1 后存回原變量(3)若兩個數(shù)均為偶數(shù),則兩個變量均不變寫一段子程序 skiplines ,完成輸出空行的功能??招械男袛?shù)由用戶在主程序過鍵盤輸入, 并將行數(shù)放在 ax 寄存器中設有 10 個學生成績分別是 76, 69 ,84,73,88,99,63, 100 和 80。試編寫一個子程序 統(tǒng)計 60-69 分, 70-79 分, 80-89 分, 90-

5、99 分和 100分的人數(shù),并分別放到 S6,S7,S8, S9, S10 單元中編寫子程序嵌套結(jié)構(gòu)的程序,把整數(shù)分別用二進制和八進制顯示出來在 D 盤根目錄建立一個文件 abc.txt ,第一次向文件寫入“ 123456”六個字符,第二次增加 “ abcdefg ”幾個字符從鍵盤上輸入文本文件: “ d:temp.txt ”的容后,然后新建一個文件“ d:temp2.txt ”,把 前一個文件的所有容復制到后一個文件中從鍵盤上輸入一個十進制數(shù),以十六進制數(shù)顯示出來。要求子程序用寄存器參數(shù)傳送方法試編制一個程序,把 bx 寄存器中的二進制數(shù)用十六進制數(shù)的形式在屏幕上顯示出來代碼:1.逆序輸出字

6、符串“ BASED ADDRESSIN”Gs1segment stack dw 100 dup(?)定義棧段 s1 定義棧空間為 100tops1label word ;top ends指向棧頂s2S2segment ; db BASED ADDRESSING,$ ends定義數(shù)據(jù)段 s2定義字符串 ss3 segment ; 定義代碼段 s3 assume cs:s3,ds:s2,ss:s1main proc far棧初始化; 棧初始化mov mov leaax,s1 ;ss,axsp,topmovax,s2 ;數(shù)據(jù)段初始化movds,ax; 數(shù)據(jù)段初始化movsi,15l: movdl,s

7、si;dl 獲取字符串 s 的最后一個(從零開始的第十movah,2; 調(diào)用 int 21h 2 號功能輸出 dl 上的值int21hdecsi ;寄存器減一,準備獲取下一個字符cmpsi,0jalmovah,4ch ;終止int21hmain endp五個字符)s3 endsend main s1 segment stack dw 100h dup(?) top label word s1 ends2. 從鍵盤上輸入兩個數(shù),分別放到x,y 單元,求出它們的和s2segmenth1dbPlease input x:,$ ;提示輸入h2dbPlease input y:,$ ;提示輸入h3dbz

8、=x+y:,$ ;提示輸出crlfdb0dh,0ah,24h ;定義回車換行xdw?ydw?s2endss3 segmentassume cs:s3,ds:s2,ss:s3main proc farmovax,s1 ;初始化movss,axleasp,topmovax,s2初始化mov ds,axlea mov intdx,h1ah,921h;int 21h 9號功能輸出“提示輸入 x”的字符串xorbx,bx;bx清零,即把 bx 置零InputX:movah,1輸入一個字符int21hcmpal,0dh判斷時候為“回車”字符jzexit1如果是回車字符就跳轉(zhuǎn)到 exit1cmpal,30h

9、和 30h (即字符 0 的 asii 值)比較jlexit1; 如果輸入字符小于 0 ,跳轉(zhuǎn)到 exit1cmpal,39h和 39h( 即字符 9 的 ascii 值 ) 比較jgexit1如果輸入字符大于 9 ,跳轉(zhuǎn)到 exit1subal,30h;al減去 30h,輸入字符轉(zhuǎn)化成數(shù)字 (從這一行開始到后面的 add bx,ax 為輸入字符轉(zhuǎn)化為數(shù)字的處理方法)cbw;al擴充為 axxchgax,bxmovcx,10mulcxxchgax,bxaddbx,ax;sub al,30h開始到這一行為輸入字符轉(zhuǎn)化為數(shù)字的處理方法jmpInputXexit1: mov x,bx把輸入的存于 b

10、x 的放到 x 中l(wèi)eadx,crlfmovah,9int21hleadx,h2movah,9int21hxorbx,bxInputY:和 InputX 類似,輸入 ymovah,1int21hcmpal,0dhjzexit2cmpal,30hjlexit2cmp al,39hjg exit2 sub al,30h cbw xchg ax,bx mov cx,10mul cxxchg ax,bx add bx,ax jmp InputYexit2: mov y,bx把輸入的存于 bx 的放到 y 中mov bx,x addbx,y此時 bx 為兩數(shù)加和leamov int leadx,crlf

11、ah,921Hdx,h3mov ah,9int 21hxor si,si ;si清零,用作計數(shù)mov ax,bx把和放到 ax 上l4: mov cl,10 div cl mov dl,ah mov dh,0 push dx inc si mov ah,0 cmp al,0 jnz l4把和連續(xù)除以 10 知道和變?yōu)榱悖鄶?shù)依次進棧重要,不能漏寫l5: pop dx add dl,30h mov ah,2 int 21h dec si cmp si,0 jnz l5余數(shù)依次出棧 余數(shù)轉(zhuǎn)換為顯示的余數(shù)字符 輸入余數(shù)字符mov ah,4chint 21H main endps3 endsend m

12、ain3. 是編寫一段程序,要求在長度為 10的數(shù)組中,找出大于 42h 的無符號數(shù)的個數(shù)并存入地 址為 up 開始區(qū)域, 找出小于 42h 的無符號數(shù)的個數(shù)并存入地址為 down 的開始區(qū)域, 并分別 顯示 up、down 數(shù)組的個數(shù)和數(shù)組的數(shù)字s1 segment stackdw 100h dup(?)top label words1 endss2 segmenth1 db the num of up array and the up array are(prints in decimalism) :,$h2 db the num of down array and the down ar

13、ray are(prints in decimalism) :,$ crlf db 0dh,0ah,24harray db 0,50h,11h,61h,22h,72h,33h,73h,41h,74h,$ ; 定義數(shù)組array up downdb 10 dup(?)db 10 dup(?)s2 endss3 segmentassume cs:s3,ds:s2,ss:s3main proc farmov ax,s1mov ss,axlea sp,topmov ax,s2mov ds,axmov si,0mov di,1mov bp,1repeat: cmp arraysi,42h ; 把 arr

14、ay 數(shù)組中小于 42h 的值放到 down 數(shù)組里, 大 于 42h 的值放到 up 數(shù)組里面jb downarraymov dl,arraysimov upbp,dlinc sicmp si,10jz exit1 inc bp jmp repeatdownarray:mov dl,arraysi mov downdi,dl inc si cmp si,10 jz exit2 inc di jmp repeatexit1: sub di,1把分配好的 up 數(shù)組和 down 數(shù)組在其有效數(shù)字后面添加jmp exit exit2: sub bp,1 exit: mov dx,bp ; $ ,便

15、于后面的輸出結(jié)束movup0,dlinc bpmovupbp,$movdx,dimovdown0,dlinc dimovdowndi,$movcl,10movsi,0lea dx,h1mov ah,9int 21hPrintUparray: cmp upsi,$ jz next mov al,upsi call print inc si jmp PrintUparraynext:lea dx,crlf mov ah,9int 21hlea dx,h2int 21h xor si,siPrintDownArray: cmp downsi,$ jz atend mov al,downsi call

16、 print inc si jmp PrintDownArrayprint proc near ;print 為輸出十進制輸出某個數(shù)的子程序 mov di,0rediv: mov ah,0divclmovdl,ahmovdh,0pushdxincdicmpal,0jnzredivbreak: pop dxadddl,30hmovah,2int21hdecdicmpdi,0jnzbreakmovdl, movah,2int21Hret print endpatend: mov ah,4ch int 21Hmain endps3 endsend main4. 鍵盤輸入一段字符串,其中小寫字母以大寫

17、字母輸出,其他字符不變輸出s1 segment stackdw100h dup(?)toplabelwords1endss2segmenth1dbPlease input a string:,$h2dbThe changed string is:,$crlfdb0dh,0ah,24htempdb?s2endss3 segment assume cs:s3,ds:s2,ss:s3 main proc far mov ax,s1 mov ss,ax lea sp,top mov ax,s2 mov ds,axlea dx,h1 mov ah,9 int 21hmov si,0l: mov ah,1

18、 int 21h cmp al,0dh jz exit cmp al,a jl putin cmp al,z jg putin sub al,20h; 把小寫字符變?yōu)榇髮懽址鹥utin: mov tempsi,al ; 把字符放到 temp 數(shù)組里 inc si jmp l輸出 tmp 數(shù)組exit: lea dx,crlf mov ah,9 int 21h lea dx,h2 mov ah,9 int 21hinc si mov tempsi,$ lea dx,temp mov ah,9 int 21hmov ah,4ch int 21H main endp s3 endsend main5

19、. 從鍵盤上就收一個小寫字母,找出它的前導字符和后續(xù)字符,在順序顯示這三個字符s1 segment stack dw 100h dup(?)top label words1 endss2 segmenth1 db Please input a lowercase: ,$h2 db The the three chars are: ,$ crlf db 0dh,0ah,24hs2 endss3 segmentassume cs:s3,ds:s2,ss:s3main proc far mov ax,s1 mov ss,ax lea sp,top mov ax,s2 mov ds,axl: lea

20、dx,h1 mov ah,9 int 21hmov ah,1 int 21h cmp al,a jl l cmp al,z jg l mov cl,allea dx,crlf mov ah,9 int 21H lea dx,h2 mov ah,9 int 21hdecclmovdl,clmovah,2int21hmovdl, movah,2int21hincclmovdl,clmov ah,2int 21hmovdl, movah,2int21hincclmovdl,clmovah,2int 21hmovah,4chint21H輸出前導字符輸出該字符輸出后導字符main endps3 ends

21、end main6. 把一個包含 20 個數(shù)據(jù)的數(shù)組 M分成兩組:正整數(shù)組 P和負整數(shù)組 N,分別把這兩個數(shù)組 中的數(shù)據(jù)的個數(shù)顯示出來dws1 segment stack dw 100h dup(?) top label word s1 endss2segmenth1dbthe positive number is: ,$h2dbthe negative number is: ,$crlfdb0dh,0ah,24harray50h,-11h,61h,-22h,72h,-33h,73h,-41h,74h,21h,67h,-90h,73h,77h,-1h,-89h,-11h,61h, -22h,2

22、0h,$s2 endss3 segmentassume cs:s3,ds:s2,ss:s3main proc farmov ax,s1mov ss,axlea sp,topmov ax,s2mov ds,axmov bx,0mov si,0l: mov dx,arraysicmp dx,0jl addlow ; 有符號數(shù)比較用 jladd si,2cmp si,40jz exitjmp laddlow: inc bx add si,2 cmp si,40 jz exit jmp lexit: lea dx,h2 mov ah,9 int 21hmov callax,bxprintleadx,c

23、rlfmovah,9int21hleadx,h1movah,9int21hmov ax,20subax,bxcallprintjmpatend打印數(shù)字字符的子程序print proc nearmov cl,10 mov si,0repeat: div cl mov dl,ah add dl,30h mov dh,0 push dx inc si mov ah,0 cmp al,0 jnz repeatl2: pop dx mov ah,2 int 21h dec si cmp si,0 jnz l2retprint endpatend: mov ah,4chint 21Hmain endps3

24、 endsend main7. 打印輸出首地址為 data 的 20個字數(shù)組中的最小偶數(shù)s1 segment stackdw 100h dup(?)top label words1 endss2 segmenth1 db the min even number is: ,$dwcrlf db 0dh,0ah,24hdata50,-11,61,-22,72,-33,73,-41,74,21,67,-90,73,77,-1,-89,-11,61,-22,20,$s2 endss3 segmentassume cs:s3,ds:s2,ss:s1main proc farmov ax,s1mov ss

25、,axlea sp,topmov ax,s2mov ds,axmov bx,65534 ;bx 存最小數(shù),初始令最小值置為 65534mov si,0mov cl,100mov dl,2l2: mov ax,datasicmp ax,0jnl l4neg ax ; 如果是負數(shù),則求補l4: div clmov al,ahmov ah,0div dl cmp ah,0比較最小值和數(shù)組中的每個數(shù)如果數(shù)組中的數(shù)大于最小值跳轉(zhuǎn)到 l1 如果數(shù)組中的數(shù)小于最小值則將其賦給最小值jnz l1cmp bx,datasi jl l1 ; mov bx,datasil1: add si,2 cmp si,40

26、jz exit jmp l2exit: lea dx,h1 mov ah,9 int 21hcmp bx,0 jnl l5 neg bxmov dl,- mov ah,2 int 21hl5: mov ax,bxcall print ; 調(diào)用子程序輸出最小值 jmp atendprint proc nearmov cl,10 mov si,0repeat: div cl mov dl,ah add dl,30h mov dh,0 push dx inc si mov ah,0 cmp al,0 jnz repeatl3: pop dx mov ah,2 int 21h dec si cmp s

27、i,0 jnz l3retprint endpatend: mov ah,4ch int 21Hmain endps3 endsend main8. 輸入兩船字符串 string1 和 string2 ,并比較兩個字符串是否相等, 相等就顯示 “ match”, 否則顯示“ no match ”s1 segment stack dw 100h dup(?) top label word s1 endss2 segmenth1 db Please input the first string: ,$h2 db Please input the second string: ,$h3dbMATCH

28、,$h4dbNO MATCH,$crlfdb0dh,0ah,24hstr1db50,?,50 dup($)str2db50,?,50 dup($)s2endss3segmentassume cs:s3,ds:s2,ss:s3 main proc farmov ax,s1mov ss,ax lea sp,top mov ax,s2 mov ds,axlea dx,h1 mov ah,9 int 21hlea dx,str1 mov ah,0ahint 21hlea dx,crlfmov ah,9int 21h lea dx,h2int 21hlea dx,str2 mov ah,0ahint 2

29、1hlea dx,crlfmov ah,9int 21hmov dl,str1+1 ;str1+1 cmp dl,str2+1 ;str2+1 jnz lmov si,2l2: mov dl,str1si cmp dl,str2si jnz l inc si cmp si,50 jz l3 jmp l2l: lea dx,h4 ;mov ah,9 int 21hl3: lea dx,h3 ; mov ah,9 int 21h為 str1 實際的字符個數(shù)為 str2 實際的字符個數(shù)輸出不匹配信息輸出匹配信息mov ah,4chint 21H main endps3 endsend main9.

30、從鍵盤接收一個四位的十六進制數(shù),并在終端顯示與它等值的二進制數(shù)s1 segment stack dw 100h dup(?) top label word s1 ends s2 segmenth1 db Please input a hexadecimal number: ,$ h2 db The number is printed in binary number: ,$ temp db 17 dup($)crlf db 0dh,0ah,24hs2 ends s3 segmentassume cs:s3,ds:s2,ss:s3main proc far mov ax,s1 mov ss,ax

31、 lea sp,top mov ax,s2 mov ds,axrepeat: lea dx,h1 mov ah,9 int 21hmovbx,0movcx,4newchar:movah,1int21hcmpal,30hjbrepeatcmpal,46h接收新字符jg cmp jnb sub jmprepeatal,39h9 跳到 l1l1 ;al,30hl2如果輸入字符大于l1: cmpal,41hjbrepeat ;如果輸入字符小于A,則輸入錯誤,跳到 repeatsubal,37h ;輸入字符為 AZ,故相應地要減 37hjmpl2l2: cbw;l2為把輸入字符轉(zhuǎn)化為數(shù)值xchgax,b

32、xmovdx,10hmuldxxchgax,bxaddbx,ax;loopnewchardec cx cmp cx,0 jnz newcharlea dx,crlf mov ah,9 int 21h lea dx,h2 int 21hmov si,0movcx,10h ;cx作計數(shù)器,即待會要循環(huán) 16 次l5:rolbx,1 ;bx循環(huán)左移以為,最高位進標志位jcl3 ;若標志位為 1 則跳轉(zhuǎn)到 l3movtempsi,0jmpl4l3:movtempsi,1l4:incsiloopl5leadx,tempmovah,9int21hmov ah,4chint 21H main endps3

33、endsend main 10 從鍵盤輸入一系列以 $為結(jié)束符的字符串,然后對其中的非數(shù)字字符計數(shù),并顯示計數(shù)結(jié) 果s1 segment stackdw 100h dup(?)top label words1 endss2 segmenth1 db Please input a string: ,$h2 db The number of the chars that is not digit:,$crlf db 0dh,0ah,24hs2 endss3 segmentassume cs:s3,ds:s2,ss:s3main proc farmov ax,s1mov ss,axlea sp,to

34、pmov ax,s2mov ds,axlea dx,h1mov ah,9int 21hmov cx,0l2: mov ah,1int 21hcmp al,$jz exitcmp al,30hjb lcmp al,39hjnb ljmp l2l: inc cxjmp l2exit: lea dx,crlfmov ah,9int 21hlea dx,h2int 21hmov si,0mov bl,10mov ax,cxl4: div blmov dl,ahmov dh,0push dxinc simov ah,0cmp al,0jnz l4l5: pop dxadd dl,30hmov ah,2i

35、nt 21hdec sicmp si,0jnz l5mov ah,4chint 21Hmain endps3 endsend main并將后續(xù)項11. 有一個首地址為 mem的10個字的數(shù)組, 試編程序刪除數(shù)組中所有為零的項, 向前壓縮,最后將數(shù)組的剩余部分補上零s1 segment stackdw 100h dup(?)top label words1 ends s2 segmentmem dw 0,1,0,3,0,0,4,5,6,0,$ crlf db 0dh,0ah,24hs2 ends s3 segmentassume cs:s3,ds:s2,ss:s3main proc far mo

36、v ax,s1 mov ss,ax lea sp,top mov ax,s2 mov ds,axmov si,0 mov di,2repeat: cmp di,20 jz exit mov bx,memsi mov dx,memdi cmp bx,0 jnz next xchg bx,dx mov memsi,bx mov memdi,dxnext: cmp memsi,0 jz l add si,2l: add di,2 jmp repeatexit: mov ah,4ch int 21Hmain endps3 ends end main; 以下是該算法描述bx,; 定義兩個指針,當前指針

37、si 和檢查指針 di ,先把 si 指針指向第一個字得到的值 ;di 指向第二個字得到的值 dx。若 bx 為 0, di 自加 2,否則,則交換這兩字,; 若此時 si 指向字為 0,則 di, 否則, di , si 都自己加 2。如此循環(huán)直到 di 指向最后一個 字。; 這樣就把所有非零字至于前面了。12. 從鍵盤上輸入一串字符(用回車鍵結(jié)束,使用 一個程序測試字符串中是否存在數(shù)字。如有,則把10 號功能調(diào)用)放在 string 中,是編制 cl 的第五位置 1,否則將該位置置 0s1 segment stack dw 100h dup(?) top label word s1 end

38、ss2segmenth1dbPlease input a string: ,$h2dbcx: ,$crlfdb0dh,0ah,24hstring db50,?,50 dup($)s2endss3 segment assume cs:s3,ds:s2,ss:s3 main proc far mov ax,s1 mov ss,ax lea sp,top mov ax,s2 mov ds,axand cl,0dfh ; 先假設無數(shù)字,置 0 lea dx,h1mov ah,9 int 21h lea dx,string mov ah,10d int 21hmov si,2l2: cmp string

39、si,$ jz exit mov dl,stringsi cmp dl,30h jb lcmp dl,39h jnb l or cl,20h ; 有數(shù)字,置 1 jmp exitl: inc si jmp l2exit: lea dx,crlf mov ah,9 int 21h lea dx,h2 int 21h mov ax,cx call print jmp atendprint proc nearmov cl,10 mov si,0repeat: div cl mov dl,ah add dl,30h mov dh,0 push dx inc si mov ah,0 cmp al,0 j

40、nz repeatl3: pop dx mov ah,2 int 21h dec si cmp si,0 jnz l3retprint endpatend: mov ah,4ch int 21Hmain endp s3 endsend main個程序, 求出平均值bx 寄存器中 (f 分13. 在首地址為 data 的字數(shù)組中, 存放了 10 個 16 位字數(shù)據(jù), 試編寫 放在 ax 寄存器中,并求出數(shù)組中有多少個數(shù)小于此平均值,將結(jié)果放在 別考慮有符號數(shù)、無符號數(shù)情況 )s1segment stackdw 100h dup(?)toplabel words1endss2segmentdata

41、dw -1,0,1,-2,2,3,-3,-4,4,15,$crlfdb 0dh,0ah,24hs2endss3segmentassume cs:s3,ds:s2,ss:s3mainproc farmov ax,s1 mov ss,ax lea sp,top mov ax,s2 mov ds,axmov si,0 mov ax,0l3: cmp datasi,$ jz exit mov dx,datasi cmp dx,0 jnl l1 neg dx sub ax,dx jmp l2l1: add ax,dx l2: add si,2 jmp l3exit: mov cl,10平均值放到 ax

42、中div cl mov ah,0mov si,0mov bx,0小于平均值的數(shù)的個數(shù)放到 bx 中l(wèi)5: cmp datasi,$ jz exit2cmp ax,datasi jz l6 jl l6 inc bxl6: add si,2 jmp l5exit2: mov ah,4ch int 21Hmain endps3 endsend main14. 一直數(shù)組 A包含 15個互不相等的整數(shù),數(shù)組 B包含 20個互不相等的整數(shù)。試編制一個 程序,把既在 A 中又在 B中出現(xiàn)的整數(shù)存放于數(shù)組 C中并顯示 C中的數(shù)值; 兩層循環(huán)比較得出兩個數(shù)組中相同的數(shù)值s1 segment stackdw 10

43、0h dup(?)top label words1 endss2 segmenta dw 1h,2h,3h,4h,5h,6h,7h,8h,9h,10h,11h,12h,13h,14h,15h,$dwb21h,22h,23h,24h,25h,6h,18h,19h,10h,11h,12h,34h,14h,53h,31h,32h,33h,36h,7h,67h,$cdw 16 dup($)crlfdb 0dh,0ah,24hs2endss3segmentassume cs:s3,ds:s2,ss:s3mainproc farmovax,s1movss,axleasp,topmovax,s2movds,

44、axmov si,0mov di,0mov bp,0l4: cmp di,40 jz l2 jmp l3l2: add si,2 cmp si,30 jz exit mov di,0l3: mov ax,asi mov bx,bdi cmp ax,bx jnz l mov cbp,ax add bp,2l: add di,2 jmp l4exit: mov bp,0l6: cmp cbp,$ jz atend mov ax,cbp call print add bp,2 mov dl, mov ah,2 int 21h jmp l6print proc nearmov cl,10mov si,

45、0repeat: div cl mov dl,ah add dl,30h mov dh,0 push dx inc si mov ah,0 cmp al,0 jnz repeatl5: pop dx mov ah,2 int 21h dec si cmp si,0 jnz l5retprint endpatend: mov ah,4ch int 21Hmain endps3 endsend main15. 設在 A、B和 D單元中分別存放著三個數(shù)。若三個數(shù)都不是0,則求出三個數(shù)的和并存放在 S 單元,若其中有一個數(shù)為 0,則把其它兩個單元也清零。請編寫此程序 s1 segment stackd

46、w 100h dup(?) top label word s1 endss2 segment a dw 1h,$ b dw -11h,$ d dw 0h,$ s dw 2 dup($) crlf db 0dh,0ah,24h s2 endss3 segmentassume cs:s3,ds:s2,ss:s3 main proc farmov ax,s1 mov ss,ax lea sp,top mov ax,s2 mov ds,axmov ax,a0 mov bx,b0 mov dx,d0 cmp ax,0 jz l cmp bx,0 jz l cmp dx,0 jz lmov cx,0 cm

47、p ax,0 jnl add_ax neg ax ; 減法需先求補 sub cx,ax jmp l2add_ax: add cx,axl2: cmp bx,0 jnl add_bx neg bx sub cx,bx jmp l3add_bx: add cx,bxl3: cmp dx,0 jnl add_dx neg dx sub cx,dx jmp l4 add_dx: add cx,dxl4: mov s0,cx jmp exitl: mov a0,0 mov b0,0mov d0,0 exit: mov ah,4chint 21Hmain endps3 endsend main最后顯16.

48、 從鍵盤輸入一系列字符 (以回車鍵結(jié)束) ,并按字母、數(shù)字和其他字符分類計數(shù), 示這三類的計數(shù)結(jié)果s1segment stackdw 100h dup(?)toplabel words1endss2segmentletterdb the number of letter: ,$digitdbthe number of digit: ,$others dbthe number of other chars: ,$crlf db 0dh,0ah,24hs2 ends s3 segmentassume cs:s3,ds:s2,ss:s3 main proc farmov ax,s1 mov ss,a

49、x lea sp,top mov ax,s2 mov ds,axmov bx,0mov cx,0 mov dx,0repeat: mov ah,1 int 21h cmp al,0dh jz exitcmp al,30h jb count_otherscmp al,z jnb count_others cmp al,39h jb count_digit cmp al,A jb count_others cmp al,Z jb count_letter cmp al,a jb count_others jmp count_lettercount_letter:inc bx jmp repeatc

50、ount_digit:inc cx jmp repeatcount_others:inc dx jmp repeatexit: push cx push dxcall print_crlf lea dx,letter mov ah,9 int 21h mov ax,bx callprint_axcallprint_crlflea dx,others mov ah,9 int 21h pop dx ; 棧,后進先出,先進后出 mov ax,dx callprint_axcallprint_crlflea dx,digitmov ah,9int 21hpop cx ;print_ax 會修改 cx 的值 , 故要先把 cx 進棧 mov ax,cxcall print_axjmp exit2print_crlf proc nearlea dx,crlfmov ah,9int 21hretprint_crlf endpprint_ax proc nearmovcl,10movsi,0re

溫馨提示

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

評論

0/150

提交評論