




版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
24個(gè)匯編實(shí)例小程序24個(gè)匯編實(shí)例小程序24個(gè)匯編實(shí)例小程序xxx公司24個(gè)匯編實(shí)例小程序文件編號(hào):文件日期:修訂次數(shù):第1.0次更改批準(zhǔn)審核制定方案設(shè)計(jì),管理制度24個(gè)匯編小程序題目列表:逆序輸出字符串“BASEDADDRESSING”從鍵盤上輸入兩個(gè)數(shù),分別放到x,y單元,求出它們的和試編寫一段程序,要求在長(zhǎng)度為10h的數(shù)組中,找出大于42h的無(wú)符號(hào)數(shù)的個(gè)數(shù)并存入地址為up開始區(qū)域,找出小于42h的無(wú)符號(hào)數(shù)的個(gè)數(shù)并存入地址為down的開始區(qū)域鍵盤輸入一段字符串,其中小寫字母以大寫字母輸出,其他字符不變輸出從鍵盤上就收一個(gè)小寫字母,找出它的前導(dǎo)字符和后續(xù)字符,在順序顯示這三個(gè)字符把一個(gè)包含20個(gè)數(shù)據(jù)的數(shù)組M分成兩組:正整數(shù)組P和負(fù)整數(shù)組N,分別把這兩個(gè)數(shù)組中的數(shù)據(jù)的個(gè)數(shù)顯示出來(lái)求出首地址為data的100個(gè)字?jǐn)?shù)組中的最小偶數(shù),并把它放在ax中輸入兩船字符串string1和string2,并比較兩個(gè)字符串是否相等,相等就顯示“match”,否則顯示“nomatch”從鍵盤接收一個(gè)四位的十六進(jìn)制數(shù),并在終端顯示與它等值的二進(jìn)制數(shù)從鍵盤輸入一系列以$為結(jié)束符的字符串,然后對(duì)其中的非數(shù)字字符計(jì)數(shù),并顯示計(jì)數(shù)結(jié)果有一個(gè)首地址為mem的100個(gè)字的數(shù)組,試編程序刪除數(shù)組中所有為零的項(xiàng),并將后續(xù)項(xiàng)向前壓縮,最后將數(shù)組的剩余部分補(bǔ)上零從鍵盤上輸入一串字符(用回車鍵結(jié)束,使用10號(hào)功能調(diào)用)放在string中,是編制一個(gè)程序測(cè)試字符串中是否存在數(shù)字。如有,則把cl的第五位置1,否則將該位置置0在首地址為data的字?jǐn)?shù)組中,存放了100h的16位字?jǐn)?shù)據(jù),試編寫一個(gè)程序,求出平均值放在ax寄存器中,并求出數(shù)組中有多少個(gè)數(shù)小于此平均值,將結(jié)果放在bx寄存器中(f分別考慮有符號(hào)數(shù)、無(wú)符號(hào)數(shù)情況)一直數(shù)組A包含15個(gè)互不相等的整數(shù),數(shù)組B包含20個(gè)互不相等的整數(shù)。試編制一個(gè)程序,把既在A中又在B中出現(xiàn)的整數(shù)存放于數(shù)組C中設(shè)在A、B和D單元中分別存放著三個(gè)數(shù)。若三個(gè)數(shù)都不是0,則求出三個(gè)數(shù)的和并存放在S單元,若其中有一個(gè)數(shù)為0,則把其它兩個(gè)單元也清零。請(qǐng)編寫此程序從鍵盤輸入一系列字符(以回車鍵結(jié)束),并按字母、數(shù)字和其他字符分類計(jì)數(shù),最后顯示這三類的計(jì)數(shù)結(jié)果已定義兩個(gè)整數(shù)變量A和B,試編寫程序完成以下功能若兩個(gè)樹種有一個(gè)是奇數(shù),則將奇數(shù)存入A中,偶數(shù)存入B中若兩個(gè)數(shù)均為奇數(shù),則將兩個(gè)數(shù)加1后存回原變量若兩個(gè)數(shù)均為偶數(shù),則兩個(gè)變量均不變寫一段子程序skiplines,完成輸出空行的功能。空行的行數(shù)由用戶在主程序過(guò)鍵盤輸入,并將行數(shù)放在ax寄存器中設(shè)有10個(gè)學(xué)生成績(jī)分別是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單元中編寫子程序嵌套結(jié)構(gòu)的程序,把整數(shù)分別用二進(jìn)制和八進(jìn)制顯示出來(lái)在D盤根目錄建立一個(gè)文件,第一次向文件寫入“123456”六個(gè)字符,第二次增加“abcdefg”幾個(gè)字符從鍵盤上輸入文本文件:“d:\”的容后,然后新建一個(gè)文件“d:\”,把前一個(gè)文件的所有容復(fù)制到后一個(gè)文件中從鍵盤上輸入一個(gè)十進(jìn)制數(shù),以十六進(jìn)制數(shù)顯示出來(lái)。要求子程序用寄存器參數(shù)傳送方法試編制一個(gè)程序,把bx寄存器中的二進(jìn)制數(shù)用十六進(jìn)制數(shù)的形式在屏幕上顯示出來(lái)代碼:1.逆序輸出字符串“BASEDADDRESSING”s1segmentstack;定義棧段s1dw100dup();定義棧空間為100toplabelword;top指向棧頂s1endss2segment ;定義數(shù)據(jù)段s2sdb'BASEDADDRESSING','$';定義字符串sS2endss3segment ;定義代碼段s3 assumecs:s3,ds:s2,ss:s1mainprocfarmovax,s1;棧初始化——movss,axleasp,top ;——棧初始化 movax,s2;數(shù)據(jù)段初始化——movds,ax ;——數(shù)據(jù)段初始化movsi,15l:movdl,s[si] ;dl獲取字符串s的最后一個(gè)(從零開始的第十五個(gè)字符)movah,2 ;調(diào)用int21h2號(hào)功能輸出dl上的值int21hdecsi;寄存器減一,準(zhǔn)備獲取下一個(gè)字符cmpsi,0jalmovah,4ch;終止int21hmainendps3endsendmain2.從鍵盤上輸入兩個(gè)數(shù),分別放到x,y單元,求出它們的和s1segmentstackdw100hdup()toplabelwords1endss2segmenth1db'Pleaseinputx:','$';提示輸入h2db'Pleaseinputy:','$';提示輸入h3db'z=x+y:','$';提示輸出crlfdb0dh,0ah,24h;定義回車換行xdwydws2endss3segmentassumecs:s3,ds:s2,ss:s3mainprocfarmovax,s1;初始化——movss,axleasp,topmovax,s2movds,ax ;——初始化leadx,h1;int21h9號(hào)功能輸出“提示輸入x”的字符串movah,9int21hxorbx,bx;bx清零,即把bx置零InputX: movah,1;輸入一個(gè)字符int21hcmpal,0dh;判斷時(shí)候?yàn)椤盎剀嚒弊址鹙zexit1;如果是回車字符就跳轉(zhuǎn)到exit1cmpal,30h;和30h(即字符0的asii值)比較jlexit1 ;如果輸入字符小于'0',跳轉(zhuǎn)到exit1cmpal,39h;和39h(即字符9的ascii值)比較jgexit1;如果輸入字符大于'9',跳轉(zhuǎn)到exit1subal,30h;al減去30h,輸入字符轉(zhuǎn)化成數(shù)字(從這一行開始到后面的addbx,ax為輸入字符轉(zhuǎn)化為數(shù)字的處理方法)cbw;al擴(kuò)充為axxchgax,bxmovcx,10mulcxxchgax,bxaddbx,ax;subal,30h開始到這一行為輸入字符轉(zhuǎn)化為數(shù)字的處理方法jmpInputXexit1:mov x,bx;把輸入的存于bx的放到x中l(wèi)eadx,crlfmovah,9int21hleadx,h2movah,9int21hxorbx,bxInputY:;和InputX類似,輸入ymovah,1int21hcmpal,0dhjzexit2 cmpal,30h jlexit2cmpal,39hjgexit2subal,30hcbwxchgax,bxmovcx,10mulcxxchgax,bxaddbx,axjmpInputYexit2:mov y,bx;把輸入的存于bx的放到y(tǒng)中 mov bx,xaddbx,y;此時(shí)bx為兩數(shù)加和leadx,crlfmovah,9int21Hleadx,h3movah,9int21hxorsi,si;si清零,用作計(jì)數(shù)movax,bx;把和放到ax上l4:movcl,10;把和連續(xù)除以10知道和變?yōu)榱悖鄶?shù)依次進(jìn)棧divclmovdl,ahmovdh,0pushdxincsi mov ah,0 ;重要,不能漏寫cmpal,0jnzl4l5:popdx;余數(shù)依次出棧adddl,30h;余數(shù)轉(zhuǎn)換為顯示的余數(shù)字符movah,2;輸入余數(shù)字符int21hdecsicmpsi,0jnzl5movah,4chint21Hmainendps3endsendmain3.是編寫一段程序,要求在長(zhǎng)度為10的數(shù)組中,找出大于42h的無(wú)符號(hào)數(shù)的個(gè)數(shù)并存入地址為up開始區(qū)域,找出小于42h的無(wú)符號(hào)數(shù)的個(gè)數(shù)并存入地址為down的開始區(qū)域,并分別顯示up、down數(shù)組的個(gè)數(shù)和數(shù)組的數(shù)字s1segmentstackdw100hdup()toplabelwords1endss2segmenth1 db 'thenumofuparrayandtheuparrayare(printsindecimalism):','$'h2 db 'thenumofdownarrayandthedownarrayare(printsindecimalism):','$'crlfdb0dh,0ah,24harraydb0,50h,11h,61h,22h,72h,33h,73h,41h,74h,'$';定義數(shù)組arrayupdb10dup();定義up數(shù)組downdb10dup() ;定義down數(shù)組s2endss3segmentassumecs:s3,ds:s2,ss:s3mainprocfarmovax,s1movss,axleasp,topmovax,s2movds,axmovsi,0movdi,1movbp,1repeat:cmparray[si],42h;把a(bǔ)rray數(shù)組中小于42h的值放到down數(shù)組里,大于42h的值放到up數(shù)組里面jbdownarraymovdl,array[si]movup[bp],dlincsicmpsi,10jzexit1 incbpjmprepeatdownarray: movdl,array[si]movdown[di],dlincsicmpsi,10jzexit2 incdijmprepeatexit1: sub di,1 jmp exitexit2: sub bp,1exit:movdx,bp;把分配好的up數(shù)組和down數(shù)組在其有效數(shù)字后面添加'$',便于后面的輸出結(jié)束movup[0],dl inc bp movup[bp],'$'movdx,dimovdown[0],dl inc dimovdown[di],'$'movcl,10movsi,0 lea dx,h1 mov ah,9 int 21hPrintUparray:cmpup[si],'$'jznext mov al,up[si]callprintincsijmpPrintUparraynext: lea dx,crlf mov ah,9 int 21h lea dx,h2 int 21h xor si,siPrintDownArray: cmpdown[si],'$'jzatend mov al,down[si]callprintincsijmpPrintDownArrayprintprocnear;print為輸出十進(jìn)制輸出某個(gè)數(shù)的子程序movdi,0rediv:movah,0divclmovdl,ahmovdh,0pushdxincdicmpal,0jnzredivbreak:popdxadddl,30hmovah,2int21hdecdicmpdi,0jnzbreakmovdl,''movah,2int21Hretprintendpatend: movah,4chint21Hmainendps3endsendmain4.鍵盤輸入一段字符串,其中小寫字母以大寫字母輸出,其他字符不變輸出s1segmentstackdw100hdup()toplabelwords1endss2segmenth1db'Pleaseinputastring:','$'h2db'Thechangedstringis:','$'crlfdb0dh,0ah,24htempdbs2endss3segmentassumecs:s3,ds:s2,ss:s3mainprocfarmovax,s1movss,axleasp,topmovax,s2movds,axleadx,h1movah,9int21h mov si,0l: mov ah,1 int 21h cmp al,0dh jz exit cmp al,'a' jl putin cmp al,'z' jg putin sub al,20h ;把小寫字符變?yōu)榇髮懽址鹥utin: mov temp[si],al;把字符放到temp數(shù)組里incsijmplexit:leadx,crlf;輸出tmp數(shù)組movah,9int21hleadx,h2movah,9int21hincsimovtemp[si],'$'leadx,tempmovah,9 int 21hmovah,4chint21Hmainendps3endsendmain5.從鍵盤上就收一個(gè)小寫字母,找出它的前導(dǎo)字符和后續(xù)字符,在順序顯示這三個(gè)字符s1segmentstackdw100hdup()toplabelwords1endss2segmenth1db'Pleaseinputalowercase:','$'h2db'Thethethreecharsare:','$'crlfdb0dh,0ah,24hs2endss3segmentassumecs:s3,ds:s2,ss:s3mainprocfarmovax,s1movss,axleasp,topmovax,s2movds,axl:leadx,h1movah,9int21h mov ah,1 int 21h cmp al,'a' jl l cmp al,'z' jg lmovcl,alleadx,crlfmovah,9int21H lea dx,h2 mov ah,9 int 21hdecclmovdl,cl;輸出前導(dǎo)字符movah,2int21hmovdl,''movah,2int21hincclmovdl,cl;輸出該字符 mov ah,2 int 21hmovdl,''movah,2int21hincclmovdl,cl;輸出后導(dǎo)字符movah,2 int 21h movah,4chint21Hmainendps3endsendmain6.把一個(gè)包含20個(gè)數(shù)據(jù)的數(shù)組M分成兩組:正整數(shù)組P和負(fù)整數(shù)組N,分別把這兩個(gè)數(shù)組中的數(shù)據(jù)的個(gè)數(shù)顯示出來(lái)s1segmentstackdw100hdup()toplabelwords1endss2segmenth1db'thepositivenumberis:','$'h2db'thenegativenumberis:','$'crlfdb0dh,0ah,24harraydw50h,-11h,61h,-22h,72h,-33h,73h,-41h,74h,21h,67h,-90h,73h,77h,-1h,-89h,-11h,61h,-22h,20h,'$'s2endss3segmentassumecs:s3,ds:s2,ss:s3mainprocfarmovax,s1movss,axleasp,topmovax,s2movds,axmovbx,0movsi,0l:movdx,array[si]cmpdx,0jladdlow;有符號(hào)數(shù)比較用jladdsi,2cmpsi,40jzexitjmpladdlow:incbx addsi,2cmpsi,40jzexitjmplexit:leadx,h2movah,9int21hmovax,bxcallprintleadx,crlfmovah,9int21hleadx,h1movah,9int21h mov ax,20subax,bxcallprintjmpatendprintprocnear;打印數(shù)字字符的子程序movcl,10movsi,0repeat:divclmovdl,ah add dl,30hmovdh,0pushdxincsi mov ah,0 cmpal,0jnzrepeatl2:popdxmovah,2int21hdecsicmpsi,0jnzl2retprintendpatend:movah,4chint21Hmainendps3endsendmain7.打印輸出首地址為data的20個(gè)字?jǐn)?shù)組中的最小偶數(shù)s1segmentstackdw100hdup()toplabelwords1endss2segmenth1db'theminevennumberis:','$'crlfdb0dh,0ah,24hdatadw50,-11,61,-22,72,-33,73,-41,74,21,67,-90,73,77,-1,-89,-11,61,-22,20,'$'s2endss3segmentassumecs:s3,ds:s2,ss:s1mainprocfarmovax,s1movss,axleasp,topmovax,s2movds,axmovbx,65534;bx存最小數(shù),初始令最小值置為65534movsi,0 mov cl,100 mov dl,2l2:movax,data[si]cmpax,0jnll4negax;如果是負(fù)數(shù),則求補(bǔ)l4:divclmoval,ah mov ah,0 div dl cmp ah,0 jnz l1 cmp bx,data[si];比較最小值和數(shù)組中的每個(gè)數(shù) jl l1;如果數(shù)組中的數(shù)大于最小值跳轉(zhuǎn)到l1 mov bx,data[si];如果數(shù)組中的數(shù)小于最小值則將其賦給最小值 l1: add si,2 cmp si,40 jz exit jmp l2 exit:leadx,h1movah,9int21hcmpbx,0jnll5negbxmovdl,'-'movah,2int21hl5:movax,bxcallprint;調(diào)用子程序輸出最小值jmpatendprintprocnearmovcl,10movsi,0repeat:divclmovdl,ah add dl,30hmovdh,0pushdxincsi mov ah,0 cmpal,0jnzrepeatl3:popdxmovah,2int21hdecsicmpsi,0jnzl3retprintendpatend:movah,4chint21Hmainendps3endsendmain8.輸入兩船字符串string1和string2,并比較兩個(gè)字符串是否相等,相等就顯示“match”,否則顯示“nomatch”s1segmentstackdw100hdup()toplabelwords1endss2segmenth1db'Pleaseinputthefirststring:','$'h2db'Pleaseinputthesecondstring:','$'h3 db 'MATCH','$'h4 db 'NOMATCH','$'crlfdb0dh,0ah,24hstr1db50,,50dup('$')str2db50,,50dup('$')s2endss3segmentassumecs:s3,ds:s2,ss:s3mainprocfarmovax,s1movss,axleasp,topmovax,s2movds,axlea dx,h1 mov ah,9 int 21h lea dx,str1 mov ah,0ah int 21h lea dx,crlf mov ah,9 int 21h lea dx,h2 int 21h lea dx,str2 mov ah,0ah int 21h lea dx,crlf mov ah,9 int 21hmovdl,str1+1;str1+1為str1實(shí)際的字符個(gè)數(shù)cmpdl,str2+1;str2+1為str2實(shí)際的字符個(gè)數(shù)jnzlmovsi,2l2:movdl,str1[si]cmpdl,str2[si]jnzlincsicmpsi,50jzl3jmpl2l:leadx,h4;輸出不匹配信息movah,9int21hl3:leadx,h3;輸出匹配信息movah,9int21hmovah,4chint21Hmainendps3endsendmain9.從鍵盤接收一個(gè)四位的十六進(jìn)制數(shù),并在終端顯示與它等值的二進(jìn)制數(shù)s1segmentstackdw100hdup()toplabelwords1endss2segmenth1db'Pleaseinputahexadecimalnumber:','$'h2db'Thenumberisprintedinbinarynumber:','$'tempdb17dup('$')crlfdb0dh,0ah,24hs2endss3segmentassumecs:s3,ds:s2,ss:s3mainprocfarmovax,s1movss,axleasp,topmovax,s2movds,axrepeat:leadx,h1 mov ah,9 int 21h movbx,0movcx,4newchar:;接收新字符movah,1int21hcmpal,30hjbrepeatcmpal,46hjgrepeatcmpal,39hjnbl1;如果輸入字符大于9跳到l1subal,30hjmpl2l1:cmpal,41hjbrepeat;如果輸入字符小于A,則輸入錯(cuò)誤,跳到repeatsubal,37h;輸入字符為A~Z,故相應(yīng)地要減37hjmpl2l2:cbw;l2為把輸入字符轉(zhuǎn)化為數(shù)值xchgax,bxmovdx,10hmuldxxchgax,bxaddbx,ax;loopnewchar dec cx cmp cx,0 jnz newcharleadx,crlfmovah,9int21hleadx,h2int21hmovsi,0movcx,10h;cx作計(jì)數(shù)器,即待會(huì)要循環(huán)16次l5:rolbx,1;bx循環(huán)左移以為,最高位進(jìn)標(biāo)志位jcl3;若標(biāo)志位為1則跳轉(zhuǎn)到l3movtemp[si],'0'jmpl4l3:movtemp[si],'1'l4:incsiloopl5leadx,tempmovah,9int21hmovah,4chint21Hmainendps3endsendmain10從鍵盤輸入一系列以$為結(jié)束符的字符串,然后對(duì)其中的非數(shù)字字符計(jì)數(shù),并顯示計(jì)數(shù)結(jié)果s1segmentstackdw100hdup()toplabelwords1endss2segmenth1db'Pleaseinputastring:','$'h2db'Thenumberofthecharsthatisnotdigit:','$'crlfdb0dh,0ah,24hs2endss3segmentassumecs:s3,ds:s2,ss:s3mainprocfarmovax,s1movss,axleasp,topmovax,s2movds,axleadx,h1 mov ah,9 int 21hmovcx,0l2:movah,1int21hcmpal,'$'jzexitcmpal,30hjblcmpal,39hjnbljmpl2l:inccxjmpl2exit:leadx,crlfmovah,9int21hleadx,h2int21hmovsi,0movbl,10movax,cxl4:divblmovdl,ahmovdh,0pushdxincsimovah,0cmpal,0jnzl4l5:popdxadddl,30hmovah,2int21hdecsicmpsi,0jnzl5movah,4chint21Hmainendps3endsendmain11.有一個(gè)首地址為mem的10個(gè)字的數(shù)組,試編程序刪除數(shù)組中所有為零的項(xiàng),并將后續(xù)項(xiàng)向前壓縮,最后將數(shù)組的剩余部分補(bǔ)上零s1segmentstackdw100hdup()toplabelwords1endss2segmentmemdw0,1,0,3,0,0,4,5,6,0,'$'crlfdb0dh,0ah,24hs2endss3segmentassumecs:s3,ds:s2,ss:s3mainprocfarmovax,s1movss,axleasp,topmovax,s2movds,ax mov si,0 mov di,2repeat: cmp di,20 jz exit mov bx,mem[si] mov dx,mem[di] cmp bx,0 jnz next xchg bx,dx mov mem[si],bx mov mem[di],dxnext: cmp mem[si],0 jz laddsi,2l: add di,2 jmp repeat exit:movah,4chint21Hmainendps3endsendmain;以下是該算法描述;定義兩個(gè)指針,當(dāng)前指針si和檢查指針di,先把si指針指向第一個(gè)字得到的值bx,;di指向第二個(gè)字得到的值dx。若bx為0,di自加2,否則,則交換這兩字,;若此時(shí)si指向字為0,則di,否則,di,si都自己加2。如此循環(huán)直到di指向最后一個(gè)字。;這樣就把所有非零字至于前面了。12.從鍵盤上輸入一串字符(用回車鍵結(jié)束,使用10號(hào)功能調(diào)用)放在string中,是編制一個(gè)程序測(cè)試字符串中是否存在數(shù)字。如有,則把cl的第五位置1,否則將該位置置0s1segmentstackdw100hdup()toplabelwords1endss2segmenth1db'Pleaseinputastring:','$'h2db'cx:','$'crlfdb0dh,0ah,24hstringdb50,,50dup('$')s2endss3segmentassumecs:s3,ds:s2,ss:s3mainprocfarmovax,s1movss,axleasp,topmovax,s2movds,ax andcl,0dfh ;先假設(shè)無(wú)數(shù)字,置0 lea dx,h1 mov ah,9 int 21hleadx,string mov ah,10d int 21h mov si,2l2: cmp string[si],'$' jz exit mov dl,string[si] cmp dl,30h jb l cmp dl,39h jnb l or cl,20h ;有數(shù)字,置1 jmp exit l: inc si jmp l2exit:leadx,crlfmovah,9int21h leadx,h2int21h movax,cxcallprintjmpatendprintprocnearmovcl,10movsi,0repeat:divclmovdl,ah add dl,30hmovdh,0pushdxincsi mov ah,0 cmpal,0jnzrepeatl3:popdxmovah,2int21hdecsicmpsi,0jnzl3retprintendpatend:movah,4chint21Hmainendps3endsendmain13.在首地址為data的字?jǐn)?shù)組中,存放了10個(gè)16位字?jǐn)?shù)據(jù),試編寫一個(gè)程序,求出平均值放在ax寄存器中,并求出數(shù)組中有多少個(gè)數(shù)小于此平均值,將結(jié)果放在bx寄存器中(f分別考慮有符號(hào)數(shù)、無(wú)符號(hào)數(shù)情況)s1segmentstackdw100hdup()toplabelwords1endss2segmentdatadw-1,0,1,-2,2,3,-3,-4,4,15,'$'crlfdb0dh,0ah,24hs2endss3segmentassumecs:s3,ds:s2,ss:s3mainprocfarmovax,s1movss,axleasp,topmovax,s2movds,ax mov si,0 mov ax,0l3: cmp data[si],'$' jz exit mov dx,data[si] cmp dx,0 jnl l1 neg dx sub ax,dx jmp l2l1: add ax,dx l2:addsi,2 jmp l3exit:movcl,10;平均值放到ax中divcl mov ah,0 mov si,0movbx,0l5:cmpdata[si],'$';小于平均值的數(shù)的個(gè)數(shù)放到bx中jzexit2cmpax,data[si]jzl6jll6incbxl6:addsi,2jmpl5exit2:movah,4chint21Hmainendps3endsendmain14.一直數(shù)組A包含15個(gè)互不相等的整數(shù),數(shù)組B包含20個(gè)互不相等的整數(shù)。試編制一個(gè)程序,把既在A中又在B中出現(xiàn)的整數(shù)存放于數(shù)組C中并顯示C中的數(shù)值;兩層循環(huán)比較得出兩個(gè)數(shù)組中相同的數(shù)值s1segmentstackdw100hdup()toplabelwords1endss2segmentadw1h,2h,3h,4h,5h,6h,7h,8h,9h,10h,11h,12h,13h,14h,15h,'$'bdw21h,22h,23h,24h,25h,6h,18h,19h,10h,11h,12h,34h,14h,53h,31h,32h,33h,36h,7h,67h,'$'c dw 16dup('$')crlfdb0dh,0ah,24hs2endss3segmentassumecs:s3,ds:s2,ss:s3mainprocfarmovax,s1movss,axleasp,topmovax,s2movds,ax mov si,0 mov di,0 mov bp,0l4: cmp di,40 jz l2 jmp l3l2: add si,2 cmp si,30 jz exit mov di,0l3: mov ax,a[si] mov bx,b[di] cmp ax,bx jnz l mov c[bp],ax add bp,2 l: add di,2 jmp l4exit:mov bp,0l6: cmp c[bp],'$' jz atend mov ax,c[bp] call print add bp,2 mov dl,'' mov ah,2 int 21h jmp l6 printprocnearmovcl,10movsi,0repeat:divclmovdl,ah add dl,30hmovdh,0pushdxincsi mov ah,0 cmpal,0jnzrepeatl5:popdxmovah,2int21hdecsicmpsi,0jnzl5retprintendpatend: movah,4chint21Hmainendps3endsendmain15.設(shè)在A、B和D單元中分別存放著三個(gè)數(shù)。若三個(gè)數(shù)都不是0,則求出三個(gè)數(shù)的和并存放在S單元,若其中有一個(gè)數(shù)為0,則把其它兩個(gè)單元也清零。請(qǐng)編寫此程序s1segmentstackdw100hdup()toplabelwords1endss2segmentadw1h,'$'bdw-11h,'$'d dw 0h,'$'s dw 2dup('$')crlfdb0dh,0ah,24hs2endss3segmentassumecs:s3,ds:s2,ss:s3mainprocfarmovax,s1movss,axleasp,topmovax,s2movds,ax mov ax,a[0] mov bx,b[0] mov dx,d[0] cmp ax,0 jz l cmp bx,0 jz l cmp dx,0 jz l mov cx,0 cmp ax,0 jnl add_ax neg ax ;減法需先求補(bǔ) sub cx,ax jmp l2 add_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 l4add_dx: add cx,dxl4: mov s[0],cx jmp exitl: mov a[0],0 mov b[0],0 mov d[0],0exit: movah,4chint21Hmainendps3endsendmain16.從鍵盤輸入一系列字符(以回車鍵結(jié)束),并按字母、數(shù)字和其他字符分類計(jì)數(shù),最后顯示這三類的計(jì)數(shù)結(jié)果s1segmentstackdw100hdup()toplabelwords1endss2segmentletterdb'thenumberofletter:','$'digitdb 'thenumberofdigit:','$'othersdb 'thenumberofotherchars:','$'crlf db 0dh,0ah,24hs2endss3segmentassumecs:s3,ds:s2,ss:s3mainprocfarmovax,s1movss,axleasp,topmovax,s2movds,ax mov bx,0 mov cx,0 mov dx,0 repeat: mov ah,1 int 21h cmp al,0dh jz exit cmp al,30h jb count_others cmp 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 repeatcount_digit: inc cx jmp repeatcount_others: inc dx jmp repeat exit: push cx push dx call print_crlf lea dx,letter mov ah,9 int 21h mov ax,bx call print_ax call print_crlf lea dx,others mov ah,9 int 21h pop dx ;棧,后進(jìn)先出,先進(jìn)后出 mov ax,dx call print_ax call print_crlf lea dx,digit mov ah,9 int 21h pop cx ;print_ax會(huì)修改cx的值,故要先把cx進(jìn)棧 mov ax,cx call print_ax jmp exit2print_crlf proc near lea dx,crlf mov ah,9 int 21h retprint_crlf endpprint_axprocnearmovcl,10movsi,0repeat2: divclmovdl,ah add dl,30hmovdh,0pushdxincsi mov ah,0 cmpal,0jnzrepeat2l3:popdxmovah,2int21hdecsicmpsi,0jnzl3retprint_axendpexit2: movah,4chint21Hmainendps3endsendmain17.已定義兩個(gè)整數(shù)變量A和B,試編寫程序完成以下功能若兩個(gè)樹種有一個(gè)是奇數(shù),則將奇數(shù)存入A中,偶數(shù)存入B中若兩個(gè)數(shù)均為奇數(shù),則將兩個(gè)數(shù)加1后存回原變量若兩個(gè)數(shù)均為偶數(shù),則兩個(gè)變量均不變s1segmentstackdw100hdup()toplabelwords1endss2segmenta dw12,'$'b dw -13,'$'s2endss3segmentassumecs:s3,ds:s2,ss:s3mainprocfarmovax,s1movss,axleasp,topmovax,s2movds,ax mov si,0 mov di,0 mov dx,0 mov cx,2 mov ax,a[0] cmp ax,0 jnl next neg axnext: div cx cmp dx,1 jnz l mov si,1l: mov dx,0 mov ax,b[0] cmp ax,0 jnl next2 neg axnext2: div cx cmp dx,1 jnz l2 mov di,1l2: cmp si,0 jnz l3 cmp di,0 jnz l4 jmp exit;都是偶數(shù),跳轉(zhuǎn)到末尾l3: cmp di,0 jnz l5 jmp exit ;a[0]為奇數(shù),b[0]為偶數(shù),跳轉(zhuǎn)到末尾l5: mov ax,a[0] ;a[0],b[0]為奇數(shù),a[0]加一存回原變量 cmp ax,0 jnl l6 neg ax dec ax neg ax jmp l7l6: inc ax l7: mov a[0],ax mov ax,b[0] ;a[0],b[0]為奇數(shù),b[0]加一存回原變量 cmp ax,0 jnl l8 neg ax dec ax neg ax jmp l9l8: inc ax l9: mov b[0],ax jmp exitl4: mov ax,a[0] ;a[0]為偶數(shù),b[0]為奇數(shù),互換 mov bx,b[0] mov a[0],bx mov b[0],axexit: movah,4chint21Hmainendps3endsendmain18.寫一段子程序skiplines,完成輸出空行的功能。空行的行數(shù)由用戶在主程序過(guò)鍵盤輸入,并將行數(shù)放在ax寄存器中s1segmentstackdw100hdup()toplabelwords1endss2segmentcrlfdb0dh,0ah,24h,'$'s2endss3segmentassumecs:s3,ds:s2,ss:s3mainprocfarmovax,s1movss,axleasp,topmovax,s2movds,ax mov bx,0l:movah,1 int 21h cmp al,0dh jz next cbwsubax,30h xchg ax,bx mov cx,10 mul cx xchg ax,bx add bx,axjmplnext: mov ax,bx call skiplinesmovah,4chint21Hmainendpskiplinesproc nearmovbx,axrepeat:cmpbx,0 jz exitleadx,crlf mov ah,9 int 21hdecbx jmp repeatexit: retskiplinesendps3endsendmain19.設(shè)有10個(gè)學(xué)生成績(jī)分別是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單元中s1segmentstackdw100hdup()toplabelwords1endss2segmentscoredw76,69,84,90,73,88,99,63,100,80,'$'s6 dw 0,'$'s7 dw 0,'$'s8 dw 0,'$'s9 dw 0,'$'s10 dw 0,'$'s2endss3segmentassumecs:s3,ds:s2,ss:s3mainprocfarmovax,s1movss,axleasp,topmovax,s2movds,ax mov si,0repeat: cmp si,20 jz exit mov ax,score[si] cmp ax,100 jnz l mov bx,s10[0] inc bx mov s10[0],bx jmp l5;必須跳轉(zhuǎn)到si加二那里l: cmp ax,90 jb l2 mov bx,s9[0] inc bx mov s9[0],bx jmp l5l2: cmp ax,80 jb l3 mov bx,s8[0] inc bx mov s8[0],bx jmp l5l3: cmp ax,70 jb l4 mov bx,s7[0] inc bx mov s7[0],bx jmp l5l4: mov bx,s6[0] inc bx mov s6[0],bxl5: add si,2 jmp repeatexit: mov ah,4ch int 21hmain endps3endsendmain20.編寫子程序嵌套結(jié)構(gòu)的程序,把整數(shù)分別用二進(jìn)制和八進(jìn)制顯示出來(lái)s1segmentstackdw100hdup()toplabelwords1endss2segmentdatadw16h,32h,'$';要顯示的兩個(gè)數(shù)字crlf db 0dh,0ah,24h,'$'s2endss3segmentassumecs:s3,ds:s
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(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ì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 湖北省孝感市漢川市2025屆八下英語(yǔ)期中復(fù)習(xí)檢測(cè)試題含答案
- 流程管理培訓(xùn)內(nèi)容
- 2025年法學(xué)專業(yè)課程考試試卷及答案
- 2025年大眾傳媒與傳播研究試題及答案
- 2025年初級(jí)護(hù)師考試題及答案
- 2025年動(dòng)態(tài)數(shù)據(jù)分析師資格考試試題及答案
- 2025上海中考數(shù)學(xué)真題及答案
- 裝配鉗工初級(jí)培訓(xùn)
- 出生日期及全職工作證明文書(5篇)
- 美術(shù)教育體系構(gòu)建與實(shí)踐路徑
- 一二次深度融合成套柱上斷路器匯報(bào)課件
- 解凍記錄表(標(biāo)準(zhǔn)模版)
- 站用電400V系統(tǒng)定期切換試驗(yàn)方案
- 初中數(shù)學(xué)北師大八年級(jí)下冊(cè)(2023年修訂) 因式分解岷陽(yáng)王冬雪提公因式法教學(xué)設(shè)計(jì)
- 金屬非金屬礦山安全規(guī)程
- 生活飲用水游離余氯方法驗(yàn)證報(bào)告
- DB32∕T 186-2015 建筑消防設(shè)施檢測(cè)技術(shù)規(guī)程
- C-TPAT反恐知識(shí)培訓(xùn)ppt課件
- 巡檢培訓(xùn)課件.ppt
- 二代征信系統(tǒng)數(shù)據(jù)采集規(guī)范釋義
- 軸承基礎(chǔ)知識(shí)PPT通用課件
評(píng)論
0/150
提交評(píng)論