1第五章循环与分支程序设计1、试编写一个汇编语言程序,要求对键盘输入的小写字母用大写字母显示出来。答案:.MODELSMALL.DATAMESS1DB13,10,'PUTERROR!(A-Z)',13,10,'$'MESS2DB'PLEASEPUT(A-Z):','$'MESS3DB?.STACK.CODESTART:MOVAX,@DATAMOVDS,AXMOVDX,OFFSETMESS2MOVAH,9HINT21HMOVSI,OFFSETMESS3MOVCX,0BEGIN:MOVAH,01HINT21HCMPAL,20HJEEXITCMPAL,61HJBMS1CMPAL,7AHJAMS1SUBAL,20HMOV[SI],ALINCSIINCCXJMPBEGINMS1:MOVDX,OFFSETMESS1MOVAH,9HINT21HJMPBEGINEXIT:MOVDL,0DHMOVAH,2HINT21HMOVDL,0AHMOVAH,2HINT21HMOVSI,OFFSETMESS3OUTPUT:MOVDL,[SI]MOVAH,2HINT21HINCSILOOPOUTPUTMOVAX,4C00HINT21HENDSTART2、编写一个程序,从键盘接受一个小写字母,然后找出它的前导字符和后续字符,再按顺序显示这三个字符。答案:.MODELSMALL.DATAMESS1DB13,10,'PUTERROR!(A-Z)',13,10,'$'MESS2DB'PLEASEPUT(A-Z):','$'.STACK.CODESTART:MOVAX,@DATAMOVDS,AXMOVDX,OFFSETMESS2MOVAH,9HINT21HMOVAX,0BEGIN:MOVAH,01HINT21HCMPAL,61H2JBMS1CMPAL,7AHJAMS1MOVBL,ALJMPEXITMS1:MOVDX,OFFSETMESS1MOVAH,9HINT21HJMPBEGINEXIT:MOVDL,0DHMOVAH,2HINT21HMOVDL,0AHMOVAH,2HINT21HMOVAL,BLDECALMOVDL,ALMOVAH,2HINT21HINCALMOVDL,ALMOVAH,2HINT21HINCALMOVDL,ALMOVAH,2HINT21HMOVAX,4C00HINT21HENDSTART3、将AX寄存器中的16位数分成4组,每组4位,然后把这四组数分别放在AL、BL、CL、DL中答案:.MODELSMALL.DATAXDB4DUP(?).STACK100H.CODEMAINPROCFARSTART:MOVAX,@DATAMOVDS,AXANDAX,00HPUSHAXMOVAX,1234HMOVCX,04HMOVSI,00HLOP:PUSHCXMOVCL,04HROLAX,CLPUSHAXANDAL,0FHMOVX[SI],ALPOPAXPOPCXADDSI,2LOOPLOPMOVAL,[X]MOVBL,[X+2]MOVCL,[X+4]MOVDL,[X+6]PRINT:ADDDL,30HMOVAH,02HINT21HMOVAL,[X]ADDAL,30HMOVDL,ALMOVAH,02HINT21HADDBL,30HMOVDL,BLMOVAH,02HINT21HADDCL,30HMOVDL,CLMOVAH,02HINT21HEXIT:MOVAX,4C00HINT21HMAINENDP3ENDSTART5、编写一个程序,要求能从键盘接收一个个位数N,然后响铃N次,(响铃的ASCII为07)。答案:.MODELSMALL.DATAMESS1DB13,10,'PUTERROR!(1-9)',13,10,'$'MESS2DB'PLEASEPUT(1-9):','$'.STACK.CODESTART:MOVAX,@DATAMOVDS,AXMOVDX,OFFSETMESS2MOVAH,9HINT21HMOVAX,0BEGIN:MOVAH,01HINT21HCMPAL,31HJBMS1CMPAL,39HJAMS1SUBAL,30HMOVCL,ALMOVCH,0JMPEXITMS1:MOVDX,OFFSETMESS1MOVAH,9HINT21HJMPBEGINEXIT:MOVDL,0DHMOVAH,2HINT21HMOVDL,0AHMOVAH,2HINT21HBELL:MOVDL,07HMOVAH,2HINT21HMOVAX,65000MOVBX,65000DELAY:NOPNOPDECBXJNZDELAYMOVBX,65000DECAXJNZDELAYLOOPBELLMOVAX,4C00HINT21HENDSTART6、编写程序,将一个包含有20个数据的数组M分成两个数组:正数数组和负数数组N,并分别把这两个数组中的数据个数显示出来。答案:.MODELSMALL.386.DATAMDB1,2,3,4,5,6,7,8,9,10,-1,-2,-3,-4,-5,-6,-7,-8,-9,-10PDB20DUP(?)NDB20DUP(?).CODEMAINPROCFARSTART:PUSHDSANDAX,0PUSHAXMOVAX,@DATAMOVDS,AXMOVBX,0MOVSI,0MOVDI,0MOVCX,20DCMPE:CMPM[BX],0JLIFLOWHIGHT:MOVAL,BYTEPTRM[BX]4MOVBYTEPTRP[SI],ALINCSIJMPCOMMONCONTRLIFLOW:MOVAL,BYTEPTRM[BX]MOVBYTEPTRN[DI],ALINCDICOMMONCONTRL:INCBXLOOPCMPEMOVAX,SICALLSHOWNUMBERCALLPRINTCRMOVAX,DICALLSHOWNUMBEREXIT:RETMAINENDPSHOWNUMBERPROCNEARCOVERNUM:DAAMOVDX,AXMOVCL,2HSHOW:ROLDL,4HPUSHDXANDDL,0FHADDDL,30HMOVAH,02HINT21HPOPDXLOOPSHOWRETSHOWNUMBERENDPPRINTCRPROCNEARMOVDL,0AHMOVAH,02HINT21HMOVDL,0DHMOVAH,02HINT21HRETPRINTCRENDPENDSTART7、编制一个汇编语言程序,求出首地址为DATA的100D字数组中的最小偶数,并把它放在AX中。答案:此题根据题意要求应该使用完整汇编格式,因为精简格式也使用DATA....DATAARESEGMENTDATADW3322H,4555H,200H,3544H,1245HNUMDB($-DATA)/2DATAAREENDSCODESEGMENTASSUMECS:CODE,DS:DATAAREMAINPROCFARSTART:PUSHDSMOVAX,0HPUSHAXMOVAX,DATAAREMOVDS,AXMOVDX,0H;偶数数量计数MOVCX,WORDPTR[NUM]MOVSI,0HISO:MOVBX,WORDPTRDATA[SI]SHRBX,1HJNCADDDXJMPCOMMONCONTROLADDDX:ADDDX,1HCMPDX,1HJEFIRSTAXVALUECOMPARE:MOVBX,WORDPTRDATA[SI]CMPBX,AXJGECOMMONCONTROLMOVAX,BXCOMMONCONTROL:ADDSI,2HLOOPISOJMPEXITFIRSTAXVALUE:MOVAX,WORDPTRDATA[SI]JMPCOMPAREEXIT:RETMAINENDPCODEENDSENDSTART8、把AX中存放得16位二进制数K看作是8个二进制的“四分子一字节”。试编写一程序,要求数一下值为3(即11B)的四分之一字节数,并将该数在终端上显示出来。.MODELSMALL.STACK.CODESTART:5MOVAX,2B03HMOVCX,8MOVBL,0BEGIN:ROLAX,1ROLAX,1MOVDX,AXANDDX,3HCMPDX,3HJNENEXTINCBLNEXT:LOOPBEGINADDBL,30HMOVDL,BLMOVAH,02INT21HMOVAX,4C00HINT21HENDSTART9、编写一个汇编语言程序,要求从键盘上接收一个思维的十六位进制数,并在终端上显示与它等值的二进制数。答案:.MODELSMALL.DATAMESS1DB13,10,'PUTERROR(0~9,A~F)',13,10,'$'.STACK.CODESTART:MOVAX,@DATAMOVDS,AXMOVAX,0MOVCX,4MOVBX,0PUT:MOVAH,1HINT21HCMPAL,30HJBSUGGESTCMPAL,39HJANEXTSUBAL,30HJMPSAVENEXT:CMPAL,41HJBSUGGESTCMPAL,46HJASUGGESTSUBAL,37HSAVE:MOVDX,CXMOVCL,4SHLBX,CLMOVAH,0ADDBX,AXMOVCX,DXLOOPPUTJMPOUTPUTSUGGEST:MOVDX,OFFSETMESS1MOVAH,09HINT21HJMPPUTOUTPUT:MOVDL,13MOVAH,2INT21HMOVDL,10MOVAH,2INT21HMOVCX,16BEGIN:ROLBX,1MOVDX,BXANDDX,1HADDDL,30HMOVAH,2INT21HLOOPBEGINMOVAX,4C00HINT21HENDSTAR11、从键盘输入一系列以$为结束符的字符串,然后对其中的非数字字符计数,并显示出计数结果。答案:6.modelsmall.data.codestart:movax,@datamovds,axmovbl,0next:movah,01hint21hCMPal,24HJEexitCMPAL,30HJLcharCMPAL,39HJGcharjmpnextchar:incbljmpnextexit:movcx,4rolbl,clmoval,blandal,0fhaddal,30hmovah,2movdl,alint21hrolbl,clmoval,blandal,0fhaddal,30hmovah,2movdl,alint21hmovax,4c00hint21hendstart第六章子程序结构6、写一段子程序SKIPLINES,完成输出空行的功能。空行的行数在AX寄存器中。答案:SKIPLINESPROCNEARPUSHCXPUSHDXMOVCX,AXNEXT:MOVAH,2MOVDL,0AHINT21HMOVAH,2MOVDL,0DHINT21HLOOPNEXT7POPDXPOPCXRETSKIPLINESENDP7、设有10个学生的成绩分别是76,69,84,90,73,88,99,63,100和80分。试编制一个子程序统计60—69分,70—79分,80—89分,90-99分和100分的人数并分别存放到S6,S7,S8,S9和S10单元中。答案:DSEGSEGMENTNUMDW76,69,84,90,73,88,99,63,100,80NDW10S6DW0S7DW0S8DW0S9DW0S10DW0DSEGENDSCODESEGMENTMAINPROCFARASSUMECS:CODE,DS:DSEGSTART:PUSHDSSUBAX,AXPUSHAXMOVAX,DSEGMOVDS,AXCALLSUB1RETMAINENDPSUB1PROCNEARPUSHAXPUSHBXPUSHCXPUSHSIMOVSI,0MOVCX,NNEXT:MOVAX,NUM[SI]MOVBX,10DIVBLMOVBL,ALCBWSUBBX,6SALBX,1INCS6[BX]ADDSI,2LOOPNEXTPOPSIPOPCXPOPBXPOPAXRETSUB