24個(gè)匯編實(shí)例小程序_第1頁
24個(gè)匯編實(shí)例小程序_第2頁
24個(gè)匯編實(shí)例小程序_第3頁
24個(gè)匯編實(shí)例小程序_第4頁
24個(gè)匯編實(shí)例小程序_第5頁
已閱讀5頁,還剩42頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

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

文檔簡介

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

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

3、為data的字?jǐn)?shù)組中,存放了100h的16位字?jǐn)?shù)據(jù),試編寫一個(gè)程序,求出平均值放在ax寄存器中,并求出數(shù)組中有多少個(gè)數(shù)小于此平均值,將結(jié)果放在bx寄存器中(f分別考慮有符號數(shù)、無符號數(shù)情況)15.一直數(shù)組A包含15個(gè)互不相等的整數(shù),數(shù)組B包含20個(gè)互不相等的整數(shù)。試編制一個(gè)程序,把既在A中又在B中出現(xiàn)的整數(shù)存放于數(shù)組C中16.設(shè)在A、B和D單元中分別存放著三個(gè)數(shù)。若三個(gè)數(shù)都不是0,則求出三個(gè)數(shù)的和并存放在S單元,若其中有一個(gè)數(shù)為0,則把其它兩個(gè)單元也清零。請編寫此程序17.從鍵盤輸入一系列字符(以回車鍵結(jié)束),并按字母、數(shù)字和其他字符分類計(jì)數(shù),最后顯示這三類的計(jì)數(shù)結(jié)果18.已定義兩個(gè)整數(shù)變量A

4、和B,試編寫程序完成以下功能(1) 若兩個(gè)樹種有一個(gè)是奇數(shù),則將奇數(shù)存入A中,偶數(shù)存入B中(2) 若兩個(gè)數(shù)均為奇數(shù),則將兩個(gè)數(shù)加1后存回原變量(3) 若兩個(gè)數(shù)均為偶數(shù),則兩個(gè)變量均不變19.寫一段子程序skiplines,完成輸出空行的功能??招械男袛?shù)由用戶在主程序中通過鍵盤輸入,并將行數(shù)放在ax寄存器中20.設(shè)有10個(gè)學(xué)生成績分別是76, 69,84,73,88,99,63,100和80。試編寫一個(gè)子程序統(tǒng)計(jì)60-69分,70-79分,80-89分,90-99分和100分的人數(shù),并分別放到S6,S7,S8,S9,S10單元中21.編寫子程序嵌套結(jié)構(gòu)的程序,把整數(shù)分別用二進(jìn)制和八進(jìn)制顯示出來2

5、2.在D盤根目錄建立一個(gè)文件abc.txt,第一次向文件寫入“123456”六個(gè)字符,第二次增加“abcdefg”幾個(gè)字符23從鍵盤上輸入文本文件:“d:temp.txt”的內(nèi)容后,然后新建一個(gè)文件“d:temp2.txt”,把前一個(gè)文件的所有內(nèi)容復(fù)制到后一個(gè)文件中24從鍵盤上輸入一個(gè)十進(jìn)制數(shù),以十六進(jìn)制數(shù)顯示出來。要求子程序用寄存器參數(shù)傳送方法25.試編制一個(gè)程序,把bx寄存器中的二進(jìn)制數(shù)用十六進(jìn)制數(shù)的形式在屏幕上顯示出來代碼:1.逆序輸出字符串“BASED ADDRESSING”s1 segment stack ;定義棧段s1 dw 100 dup(?) ;定義??臻g為100top lab

6、el word ;top指向棧頂s1 endss2 segment ;定義數(shù)據(jù)段s2s db BASED ADDRESSING,$ ;定義字符串sS2 endss3 segment ;定義代碼段s3 assume cs:s3,ds:s2,ss:s1main proc far mov ax,s1 ;棧初始化 mov ss,ax lea sp,top ;棧初始化 mov ax,s2 ;數(shù)據(jù)段初始化 mov ds,ax ;數(shù)據(jù)段初始化 mov si,15l: mov dl,ssi ;dl獲取字符串s的最后一個(gè)(從零開始的第十五個(gè)字符) mov ah,2 ;調(diào)用int 21h 2號功能輸出dl上的值

7、int 21h dec si ;寄存器減一,準(zhǔn)備獲取下一個(gè)字符 cmp si,0 ja l mov ah,4ch ;終止 int 21hmain endps3 ends end main2.從鍵盤上輸入兩個(gè)數(shù),分別放到x,y單元,求出它們的和s1 segment stack dw 100h dup(?)top label words1 endss2 segmenth1 db Please input x:,$ ;提示輸入h2 db Please input y:,$ ;提示輸入h3 db z=x+y:,$ ;提示輸出crlf db 0dh,0ah,24h ;定義回車換行x dw ?y dw ?

8、s2 endss3 segment assume cs:s3,ds:s2,ss:s3main proc far mov ax,s1 ;初始化 mov ss,ax lea sp,top mov ax,s2 mov ds,ax ;初始化 lea dx,h1 ;int 21h 9號功能輸出“提示輸入x”的字符串 mov ah,9 int 21h xor bx,bx ;bx清零,即把bx置零InputX: mov ah,1 ;輸入一個(gè)字符 int 21h cmp al,0dh ;判斷時(shí)候?yàn)椤盎剀嚒弊址?jz exit1 ;如果是回車字符就跳轉(zhuǎn)到exit1 cmp al,30h ;和30h(即字符0的a

9、sii值)比較 jl exit1 ;如果輸入字符小于0,跳轉(zhuǎn)到exit1 cmp al,39h ;和39h(即字符9的ascii值)比較 jg exit1 ;如果輸入字符大于9,跳轉(zhuǎn)到exit1 sub al,30h ;al減去30h,輸入字符轉(zhuǎn)化成數(shù)字(從這一行開始到后面的add bx,ax為輸入字符轉(zhuǎn)化為數(shù)字的處理方法) cbw ;al擴(kuò)充為ax xchg ax,bx mov cx,10 mul cx xchg ax,bx add bx,ax ;sub al,30h開始到這一行為輸入字符轉(zhuǎn)化為數(shù)字的處理方法 jmp InputX exit1: movx,bx ;把輸入的存于bx的放到x中

10、lea dx,crlf mov ah,9 int 21h lea dx,h2 mov ah,9 int 21h xor bx,bxInputY: ;和InputX類似,輸入y mov ah,1 int 21h cmp al,0dh jz exit2cmp al,30hjl exit2 cmp al,39h jg exit2 sub al,30h cbw xchg ax,bx mov cx,10 mul cx xchg ax,bx add bx,ax jmp InputYexit2: movy,bx ;把輸入的存于bx的放到y(tǒng)中movbx,x add bx,y ;此時(shí)bx為兩數(shù)加和 lea dx

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

12、ch int 21Hmain endps3 ends end main3.是編寫一段程序,要求在長度為10的數(shù)組中,找出大于42h的無符號數(shù)的個(gè)數(shù)并存入地址為up開始區(qū)域,找出小于42h的無符號數(shù)的個(gè)數(shù)并存入地址為down的開始區(qū)域,并分別顯示up、down數(shù)組的個(gè)數(shù)和數(shù)組內(nèi)的數(shù)字s1 segment stack dw 100h dup(?)top label words1 endss2 segmenth1dbthe num of up array and the up array are(prints in decimalism) :,$h2dbthe num of down array a

13、nd the down array are(prints in decimalism) :,$crlf db 0dh,0ah,24harray db 0,50h,11h,61h,22h,72h,33h,73h,41h,74h,$ ;定義數(shù)組arrayup db 10 dup(?) ;定義up數(shù)組 down db 10 dup(?) ;定義down數(shù)組s2 endss3 segment assume cs:s3,ds:s2,ss:s3main proc far mov ax,s1 mov ss,ax lea sp,top mov ax,s2 mov ds,ax mov si,0 mov di,1

14、 mov bp,1 repeat: cmp arraysi,42h ;把a(bǔ)rray數(shù)組中小于42h的值放到down數(shù)組里,大于42h的值放到up數(shù)組里面 jb downarray mov dl,arraysi mov upbp,dl inc si cmp si,10 jz exit1inc bp jmp repeatdownarray:mov dl,arraysi mov downdi,dl inc si cmp si,10 jz exit2inc di jmp repeatexit1:subdi,1jmpexitexit2:subbp,1exit: mov dx,bp ;把分配好的up數(shù)組和

15、down數(shù)組在其有效數(shù)字后面添加$,便于后面的輸出結(jié)束 mov up0,dlincbpmov upbp,$ mov dx,di mov down0,dlincdi mov downdi,$ mov cl,10 mov si,0leadx,h1movah,9int21hPrintUparray: cmp upsi,$ jz nextmoval,upsi call print inc si jmp PrintUparraynext:leadx,crlfmovah,9int21hleadx,h2int21hxorsi,siPrintDownArray: cmp downsi,$ jz atendmo

16、val,downsi call print inc si jmp PrintDownArrayprint proc near ;print為輸出十進(jìn)制輸出某個(gè)數(shù)的子程序 mov di,0rediv: mov ah,0 div cl mov dl,ah mov dh,0 push dx inc di cmp al,0 jnz redivbreak: pop dx add dl,30h mov ah,2 int 21h dec di cmp di,0 jnz break mov dl, mov ah,2 int 21H retprint endpatend:mov ah,4ch int 21Hma

17、in endps3 ends end main4.鍵盤輸入一段字符串,其中小寫字母以大寫字母輸出,其他字符不變輸出s1 segment stack dw 100h dup(?)top label words1 endss2 segmenth1 db Please input a string:,$h2 db The changed string is:,$crlf db 0dh,0ah,24htemp db ?s2 endss3 segment assume cs:s3,ds:s2,ss:s3main proc far mov ax,s1 mov ss,ax lea sp,top mov ax

18、,s2 mov ds,ax lea dx,h1 mov ah,9 int 21hmovsi,0l:movah,1int21hcmpal,0dhjzexitcmpal,ajlputincmpal,zjgputinsubal,20h ;把小寫字符變?yōu)榇髮懽址鹥utin:movtempsi,al ;把字符放到temp數(shù)組里 inc si jmp lexit: lea dx,crlf ;輸出tmp數(shù)組 mov ah,9 int 21h lea dx,h2 mov ah,9 int 21h inc si mov tempsi,$ lea dx,temp mov ah,9int21h mov ah,4ch

19、 int 21Hmain endps3 ends end main5.從鍵盤上就收一個(gè)小寫字母,找出它的前導(dǎo)字符和后續(xù)字符,在順序顯示這三個(gè)字符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 segment assume cs:s3,ds:s2,ss:s3main proc far mov ax,s1 mov ss,ax lea

20、sp,top mov ax,s2 mov ds,axl: lea dx,h1 mov ah,9 int 21hmovah,1int21hcmpal,ajllcmpal,zjgl mov cl,al lea dx,crlf mov ah,9 int 21Hleadx,h2movah,9int21h dec cl mov dl,cl ;輸出前導(dǎo)字符 mov ah,2 int 21h mov dl, mov ah,2 int 21h inc cl mov dl,cl ;輸出該字符movah,2int21h mov dl, mov ah,2 int 21h inc cl mov dl,cl ;輸出后導(dǎo)

21、字符 mov ah,2int21h mov ah,4ch int 21Hmain endps3 ends end main6.把一個(gè)包含20個(gè)數(shù)據(jù)的數(shù)組M分成兩組:正整數(shù)組P和負(fù)整數(shù)組N,分別把這兩個(gè)數(shù)組中的數(shù)據(jù)的個(gè)數(shù)顯示出來s1 segment stack dw 100h dup(?)top label words1 endss2 segmenth1 db the positive number is: ,$h2 db the negative number is: ,$crlf db 0dh,0ah,24harray dw 50h,-11h,61h,-22h,72h,-33h,73h,-4

22、1h,74h,21h,67h,-90h,73h,77h,-1h,-89h,-11h,61h,-22h,20h,$s2 endss3 segment assume cs:s3,ds:s2,ss:s3main proc far mov ax,s1 mov ss,ax lea sp,top mov ax,s2 mov ds,ax mov bx,0 mov si,0l: mov dx,arraysi cmp dx,0 jl addlow ;有符號數(shù)比較用jl add si,2 cmp si,40 jz exit jmp laddlow: inc bxadd si,2 cmp si,40 jz exit

23、 jmp lexit: lea dx,h2 mov ah,9 int 21h mov ax,bx call print lea dx,crlf mov ah,9 int 21h lea dx,h1 mov ah,9 int 21hmovax,20 sub ax,bx call print jmp atendprint proc near ;打印數(shù)字字符的子程序 mov cl,10 mov si,0repeat: div cl mov dl,ahadddl,30h mov dh,0 push dx inc simovah,0 cmp al,0 jnz repeatl2: pop dx mov a

24、h,2 int 21h dec si cmp si,0 jnz l2 retprint endpatend: mov ah,4ch int 21Hmain endps3 ends end main7.打印輸出首地址為data的20個(gè)字?jǐn)?shù)組中的最小偶數(shù)s1 segment stack dw 100h dup(?)top label words1 endss2 segmenth1 db the min even number is: ,$crlf db 0dh,0ah,24hdata dw 50,-11,61,-22,72,-33,73,-41,74,21,67,-90,73,77,-1,-89,

25、-11,61,-22,20,$s2 endss3 segment assume cs:s3,ds:s2,ss:s1main proc far mov ax,s1 mov ss,ax lea sp,top mov ax,s2 mov ds,ax mov bx,65534 ;bx存最小數(shù),初始令最小值置為65534 mov si,0movcl,100movdl,2l2: mov ax,datasi cmp ax,0 jnl l4 neg ax ;如果是負(fù)數(shù),則求補(bǔ)l4: div cl mov al,ahmovah,0divdlcmpah,0jnzl1cmpbx,datasi ;比較最小值和數(shù)組中的

26、每個(gè)數(shù)jll1 ;如果數(shù)組中的數(shù)大于最小值跳轉(zhuǎn)到l1movbx,datasi ;如果數(shù)組中的數(shù)小于最小值則將其賦給最小值 l1:addsi,2cmpsi,40jzexitjmpl2exit: lea dx,h1 mov ah,9 int 21h cmp bx,0 jnl l5 neg bx mov dl,- mov ah,2 int 21hl5: mov ax,bx call print ;調(diào)用子程序輸出最小值 jmp atendprint proc near mov cl,10 mov si,0repeat: div cl mov dl,ahadddl,30h mov dh,0 push d

27、x inc simovah,0 cmp al,0 jnz repeatl3: pop dx mov ah,2 int 21h dec si cmp si,0 jnz l3 retprint endpatend: mov ah,4ch int 21Hmain endps3 ends end main8.輸入兩船字符串string1和string2,并比較兩個(gè)字符串是否相等,相等就顯示“match”,否則顯示“no match”s1 segment stack dw 100h dup(?)top label words1 endss2 segmenth1 db Please input the f

28、irst string: ,$h2 db Please input the second string: ,$h3db MATCH,$h4dbNO MATCH,$crlf db 0dh,0ah,24hstr1 db 50,?,50 dup($)str2 db 50,?,50 dup($)s2 endss3 segment assume cs:s3,ds:s2,ss:s3main proc far mov ax,s1 mov ss,ax lea sp,top mov ax,s2 mov ds,ax leadx,h1movah,9int21hleadx,str1movah,0ahint21hlea

29、dx,crlfmovah,9int21hleadx,h2int21hleadx,str2movah,0ahint21hleadx,crlfmovah,9int21h mov dl,str1+1 ;str1+1為str1實(shí)際的字符個(gè)數(shù) cmp dl,str2+1 ;str2+1為str2實(shí)際的字符個(gè)數(shù) jnz l mov 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

30、 int 21h mov ah,4ch int 21Hmain endps3 ends end main9.從鍵盤接收一個(gè)四位的十六進(jìn)制數(shù),并在終端顯示與它等值的二進(jìn)制數(shù)s1 segment stack dw 100h dup(?)top label words1 endss2 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 endss3 segment assume c

31、s:s3,ds:s2,ss:s3main proc far mov ax,s1 mov ss,ax lea sp,top mov ax,s2 mov ds,axrepeat: lea dx,h1movah,9int21hmov bx,0 mov cx,4 newchar: ;接收新字符 mov ah,1 int 21h cmp al,30h jb repeat cmp al,46h jg repeat cmp al,39h jnb l1 ;如果輸入字符大于9跳到l1 sub al,30h jmp l2l1: cmp al,41h jb repeat ;如果輸入字符小于A,則輸入錯(cuò)誤,跳到rep

32、eat sub al,37h ;輸入字符為AZ,故相應(yīng)地要減37h jmp l2l2: cbw ;l2為把輸入字符轉(zhuǎn)化為數(shù)值 xchg ax,bx mov dx,10h mul dx xchg ax,bx add bx,ax ;loop newchardeccxcmpcx,0jnznewchar lea dx,crlf mov ah,9 int 21h lea dx,h2 int 21h mov si,0 mov cx,10h ;cx作計(jì)數(shù)器,即待會要循環(huán)16次l5: rol bx,1 ;bx循環(huán)左移以為,最高位進(jìn)標(biāo)志位 jc l3 ;若標(biāo)志位為1則跳轉(zhuǎn)到l3 mov tempsi,0 jmp

33、 l4l3: mov tempsi,1l4: inc si loop l5 lea dx,temp mov ah,9 int 21h mov ah,4ch int 21Hmain endps3 ends end main10從鍵盤輸入一系列以$為結(jié)束符的字符串,然后對其中的非數(shù)字字符計(jì)數(shù),并顯示計(jì)數(shù)結(jié)果s1 segment stack dw 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 segment assume cs:s3,ds:s2,ss:s3main proc far mov ax,s1 mov ss,ax lea sp,top mov ax,s2 mov ds,ax lea dx,h1movah,9int21h mov cx,0l2: mov ah,1 int 21h cmp al,$ jz exit cmp al,30h jb l cmp al,39h jnb l jmp l2l: inc

溫馨提示

  • 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)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論