汇编第五章课后题答案

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

1.从屏幕上输入小写字母,转化为大写字母输出(解法1)DATASEGMENTMESSAGEDBENTERASTRING:,0AH,0DH,'$'MAXLENGTHDB50,?,50DUP(?);每次最多可以输入49个字符DATAENDSCODESEGMENTASSUMEDS:DATA,CS:CODESTART:MOVAX,DATAMOVDS,AXLEADX,MESSAGE;输出ENTERASTRINGMOVAH,09HINT21HLEADX,MAXLENGTH;输入字符串MOVAH,0AH;键盘输入到缓冲区,DS:DX=缓冲区首址INT21H;(DS:DX)=缓冲区最大字符数,(DS:DX+1)=实际输入的字符数MOVAH,02H;输出回车换行MOVDL,0AHINT21HMOVAH,02HMOVDL,0DHINT21HMOVCL,MAXLENGTH+1;把字符的实际长度放入寄存器CLMOVCH,0MOVBH,02HLEASI,MAXLENGTH+2;取字符串的基地址放入SIXUN:MOVAL,[SI]CMPAL,'Z'JBES1;小于等于'Z'转移JMPS3S1:CMPAL,'A'JAEDA;大于等于'A'转移JMPOUTPUTDA:ADDAL,20HJMPOUTPUTS3:CMPAL,'z';小于等于小Z转移JBES4S4:CMPAL,'a';大于等于小a转移JAEXIAOJMPOUTPUTXIAO:SUBAL,32JMPOUTPUTOUTPUT:MOVDL,ALMOVAH,02H;显示输出INT21HINCSILOOPXUNMOVAH,4CHINT21HCODEENDSENDSTART(解法2);将输入的小写字母转化为大写字母输出,输入回车结束CODESEGMENTASSUMECS:CODEBEGIN:MOVAH,01HINT21HCMPAL,0DH;ASCIIOFCARRIAGERETURNJEEXITCMPAL,61H;ASCIIOF'a'JBSTOPCMPAL,7AH;ASCIIOF'z'JASTOPSUBAL,20HSTOP:MOVDL,ALMOVAH,2INT21HJMPBEGINEXIT:MOVAH,4CHINT21HRETCODEENDSENDBEGIN2.输入一个字符,找出它的前导字符和后续字符,并按顺序显示这三个字符.(解法1)CODESEGMENTMAINPROCFARASSUMECS:CODESTART:PUSHDSXORAX,AXPUSHAXMOVAH,01HINT21HCMPAL,61HJBEXITCMPAL,7AHJAEXITMOVCL,ALDECALMOVDL,ALMOVAH,02HINT21HMOVDL,CLMOVAH,02HINT21HANDAL,01HINCCLMOVDL,CLMOVAH,02HINT21HEXIT:MOVAX,4C00HINT21HRETMAINENDPCODEENDSENDSTART(解法2).MODELSMALL.STACK200H.DATAimsgdb'Input:$';输入提示信息omsgdb0Dh,0Ah,'Output:$';输出提示信息stringdb3dup(0),'$';存放三个字符.CODESTART:movax,@datamovds,axleadx,imsgmovah,9int21hmovah,1int21hleadi,stringdecalmovcx,3s:mov[di],alincdiincalloopsleadx,omsgmovah,9int21hleadx,stringmovah,9int21hMOVAH,07HINT21HMOVAX,4C00HINT21HENDSTART3.将AX寄存器中的16位数分成4组,每组4位,然后把这四组数分别放在AL,BL,CL,DL中.MODELSMALL,C.CODE.STARTUPMOVAX,3456HMOVBX,AXMOVCL,4ROLAX,CLMOVBX,AXANDAL,0FH;AL中是15,14,13,12ROLBX,CLMOVDX,BXANDBL,0FH;BL中是11,10,9,8ANDAH,0FHMOVCH,AH;CH中是7,6,5,4MOVCL,CHANDDH,0FH;DH中是3,2,1,0MOVDL,DH.EXIT0END4.试编写一程序,要求比较两个字符串STRING1和STRING2所含字符是否相同,若相同则显示'MATCH',若不相同则显示'NOTMATCH'..MODELSMALL.DATASTRING1DBLDSKFJSLDKFLENG1EQU$-STRING1STRING2DBLDSKFJSLDKPLENG2EQU$-STRING2MSG1DBMATCH,24HMSG2DBNOTMATCH,24H.CODEMOVAX,@DATAMOVDS,AXMOVES,AXMOVBX,LENG1MOVCX,LENG2CMPBX,CXJNZNOT_MATCHLEASI,STRING1LEADI,STRING2CLDREPZCMPSBJZ_MATCHNOT_MATCH:LEADX,MSG2MOVAH,09HINT21HJMP_EXIT_MATCH:LEADX,MSG1MOVAH,09HINT21H_EXIT:MOVAH,07HINT21HMOVAX,4C00HINT21HEND5.要求能从键盘接收一个个位数,然后响铃N次(响铃的ASCII码为07).MODELSMALL.DATAMSGDBYOURINPUTISNOT1-9!,24H.CODE.STARTUPMOVAH,0INT16H;接收一个键盘输入CMPAL,31HJBERRORCMPAL,39HJAERRORMOVCL,ALSUBCL,30HCYCLE:MOVDL,7MOVAH,09HINT21HMOVAH,07H;按一下键就响一下铃声INT21HLOOPCYCLEJMP_EXITERROR:LEADX,MSGMOVAH,09HINT21HMOVAH,07HINT21H_EXIT:.EXIT0END6.编写程序,将一个包含有20个数据的数组M分成两个数组,正数数组P和负数数组N,并分别把这两个数组中数据的个数显示出来..MODELSMALL,C.DATAINDEXDB12,-20,4,05H,11H,2AH,-11,2,3,09HDB-3,0,-9,44H,32H,33H,34H,-5,40H,22HPDB0,20DUP(0);存放正数NDB0,20DUP(0);存放负数.CODEDISPLAYPROCNEARUSESAXANDAH,0FH.IFAH=0AH&&AH=0FHADDAH,07H.ENDIFADDAH,30HMOVDL,AHMOVAH,02HINT21HMOVAH,07HINT21HRETDISPLAYENDP.STARTUPLEADI,P+1LEASI,N+1LEABX,INDEXMOVCX,14HCYCLE:CMPBYTEPTR[BX],0JGNOSIGNINCAL;AL中存放负数MOVDL,BYTEPTR[BX]MOVBYTEPTRDS:[DI],DLINCDIINCBXLOOPCYCLENOSIGN:INCAH;AH中存放正数MOVDL,BYTEPTR[BX]MOVBYTEPTRDS:[SI],DLINCSIINCBXLOOPCYCLEMOVP,AHMOVN,ALCALLDISPLAYMOVAH,ALCALLDISPLAY.EXIT0END7.试编制一个汇编语言程序,求出首地址为DATA的100D字数组中的最小偶数,并把它存放在AX中.datareasegmentdatadw10,2,4,8,7,7,69,65,55,89,95dw25,39,77,88,25,1,47,88,8,8,77,88,22count=($-data)/2numdw0ffeehdatareaendscodesegmentmainprocfarassumecs:code,ds:datareapushdsmovax,0pushaxbegin:movax,datareamovds,axmovbl,2movcx,countleasi,dataA:movax,[si]movdx,axdivblcmpah,0jnecirclecmpdx,numjbBcircle:addsi,2lopa:loopAexit:movax,numretB:movnum,dxjmplopamainendpcodeendsend8.把AX中存放的16位二进制数K看作是8个二进制的四分之一字节.试编写一程序,要求数一下值为3(即11B)的四分之一字节数,并将该数在终端上显示出来.MOVCX,8MOVDL,0NEXT3:RORAX,1JNCNEXT1RORAX,1JNCNEXT2INCDLNEXT2:LOOPNEXT3ADDDL,30HMOVAH,2INT21HMOVAH,4CHINT21HNEXT1:RORAX,1JMPNEXT29.试编写一汇编语言程序,求出首地址为DATA的100D字数组中的最小偶数,并把它存放在AX中..MODELSMALL,C.DATA_DATADW100DUP(?).CODE.STARTUPLEASI,_DATAMOVAX,[SI]MOVCX,100CYCLE:ADDSI,2.IFAX[SI]MOVAX,[SI].ENDIFLOOPCYCLE.EXIT010.设有一段英文,其字符变量名为ENG,并以$字符结束,试编写一程序,查对单词SUN在该文中的出现次数,并以格式SUN****显示出次数..MODELSMALL.386.DATAENGDB'SUN','SUNJAVA',24HMESSAGEDB'SUN:','$'.STACK100H.CODEMAINPROCFARSTART:PUSHDSANDAX,0PUSHAXMOVAX,@DATAMOVDS,AXMOVAX,0HMOVSI,1HSUBSI1:SUBSI,1HSUBSI2:SUBSI,1HCOMPARES:ADDSI,1HMOVDL,ENG[SI]CMPDL,24HJEPRINTCMPDL,53HJNECOMPARESCOMPAREU:ADDSI,1HMOVDL,ENG[SI]CMPDL,55HJNESUBSI2COMPAREN:ADDSI,1HMOVDL,ENG[SI]CMPDL,4EHJNESUBSI1INCAXJMPCOMPARESPRINT:LEADX,MESSAGEPUSHAXMOVAH,09HINT21HPOPAXCALLSHOWNUMBEREXIT:RETMAINENDPSHOWNUMBERPROCNEARCOVERNUM:DAAMOVDX,AXMOVCL,4HSHOW:ROLDX,4HPUSHDXANDDX,0FHADDDX,30HMOVAH,02HINT21HPOPDXLOOPSHOWRETSHOWNUMBERENDPENDSTART11.从键盘输入一系列以$为结束符的字符串,然后对其中的非数字字符计数,并显示出计数结果..MODELSMALL.386.CODEMAINPROCFARSTART:PUSHDSMOVAX,0PUSHAXMOVCX,0INPUT:MOVAH,1HINT21HCOMPARE:CMPAL,24HJEPRINTCMPAL,30HJLADDCOUNTCMPAL,39HJGADDCOUNTADDCOUNT:ADDAX,1HJMPINPUTPRINT:CALLSHOWNUMBEREXIT:RETMAINENDPSHOWNUMBERPROCNEARCOVERNUM:DAAMOVDX,AXMOVCL,2HSHOW:ROLDL,4HPUSHDXANDDL,0FHADDDL,30HMOVAH,02HINT21HPOPDXLOOPSHOWRETSHOWNUMBERENDPENDSTART12.有一个首地址为MEM的100D字数组,试编制程序删除数组中所有为零

1 / 38
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功