您好,欢迎访问三七文档
当前位置:首页 > 行业资料 > 其它行业文档 > 微机原理汇编程序设计
微机原理课程设计设计一:从键盘输入十六进制数并显示出二进制值设计二:字符串匹配设计设计三:字符和数据显示的设计设计四:键盘输入小写字母转换成大写字母设计五:计算N!的设计2011-7-6设计一:从键盘输入十六进制数并显示出二进制值实验目的:掌握接收键盘数据的方法,并了解数据显示时须转换为ASCII码的原理。实验内容:将键盘接收到的4位十六进制数据转换为等值的二进制数,再显示在屏幕终端上。流程图:程序源代码:CRLFMACROMOVAH,02HMOVDL,0DHINT21HMOVAH,02HMOVDL,0AHINT21HENDMDATASEGMENTMARKDB?MESSDB'INPUTTHENUMBER!PressEntertoTransition,PressSpacetoExit!',0DH,0AH,'Input:$'ERRORDB0DH,0AH,'InputError!',0DH,0AH,'$'DATAENDSSTACKSEGMENTSTADW32DUP(?)TOPDW?STACKENDSCODESEGMENTASSUMECS:CODE,DS:DATA,ES:DATA,SS:STACKSTART:MOVAX,DATAMOVDS,AXMOVES,AXMOVSP,TOPHEAD:CRLFMOVMARK,0MOVAH,09HLEADX,MESSINT21H;显示提示输入的信息CALLGETNUM;接收键入数值送DXCMPMARK,01HJEHEADMOVCX,0010H;16位MOVBX,DXTTT:ROLBX,1;循环左移1位MOVDL,BLANDDL,01H;屏蔽掉高7位ADDDL,30HMOVAH,02HINT21H;显示二进制位对应的ASCII字符LOOPTTTJMPHEADFINI:MOVAH,4CHINT21H;返回DOSGETNUMPROCNEAR;子程序,接收键入数值送DXPUSHCXXORDX,DXGGG:MOVAH,01HINT21HCMPAL,0DH;输入为回车,则进行转换JEPPPCMPAL,20H;输入为空格,则退回DOSJEFINICMPAL,30HJBKKKSUBAL,30HCMPAL,0AHJBGETSCMPAL,11HJBKKKSUBAL,07HCMPAL,0FHJBEGETSCMPAL,2AHJBKKKCMPAL,2FHJAKKKSUBAL,20HGETS:MOVCL,04SHLDX,CLXORAH,AHADDDX,AXJMPGGGKKK:MOVAH,09HMOVDX,OFFSETERRORINT21HMOVMARK,01HPPP:PUSHDXCRLFPOPDXPOPCXRETGETNUMENDPCODEENDSENDSTART运行结果设计二:字符串匹配设计实验内容:编写程序实现两个字符串比较。如相同,则显示“MATCH”,否则显示“NOMATCH”。源程序:CRLFMACRO;显示回车MOVDL,0DHMOVAH,02HINT21HMOVAH,02HMOVDL,0AHINT21HENDMDATASEGMENTMESS1DB'MATCH',0DH,0AH,'$'MESS2DB'NOMATCH',0DH,0AH,'$'MESS3DB'INPUTSTRING1!',0DH,0AH,'$'MESS4DB'INPUTSTRING2!',0DH,0AH,'$'MAXLEN1DB100STRING1DB100DUP(?)MAXLEN2DB100STRING2DB100DUP(?)DATAENDSCODESEGMENTASSUMECS:CODE,DS:DATA,ES:DATASTART:MOVAX,DATAMOVDS,AXMOVES,AXMOVAH,09HMOVDX,OFFSETMESS3INT21H;显示输入提示信息1MOVAL,MAXLEN1MOVBX,OFFSETSTRING1MOV[BX],AL;最大字符缓冲MOVAH,0AHMOVDX,OFFSETSTRING1INT21H;接收键入的字符串1CRLFMOVAH,09HMOVDX,OFFSETMESS4INT21H;显示输入提示信息2MOVAL,MAXLEN2MOVBX,OFFSETSTRING2MOV[BX],AL;最大字符缓冲设置MOVAH,0AHMOVDX,OFFSETSTRING2INT21H;接收键入的字符串2CRLFCLDLEASI,STRING1;字符串1的地址送给SIMOVCL,[SI+1];字符串1的字符数送给CXMOVCH,0KKK:LEADI,STRING2;字符串2的地址送给DIMOVDL,[DI+1];字符串2的字符数送给DXMOVDH,0ZJ2:MOVAL,[SI+2];字符串1的第一个字符在字符串2中匹配CMP[DI+2],ALJEZJ3;匹配成功则跳转ZJ1:INCDI;指向字符串2下一个字符DECDXJZGGG;字符串2完,不匹配JMPZJ2;字符串2没完,重新匹配ZJ3:DECCXJZMMM;字符串1完,匹配DECDXJZGGG;字符串2完,不匹配INCSI;指向串1下一个字符INCDI;指向串2下一个字符MOVAL,[SI+2]CMP[DI+2],ALJEZJ3;匹配,跳转DECDXJZGGG;字符串2完,不匹配LEASI,STRING1;重新从串1的第一个字符匹配MOVCL,[SI+1]MOVCH,0INCDIJMPZJ2MMM:MOVAH,09H;输出匹配信息MOVDX,OFFSETMESS1INT21HJMPPPPGGG:MOVAH,09H;输出不匹配信息MOVDX,OFFSETMESS2INT21HPPP:MOVAH,4CH;程序终止INT21HCODEENDSENDSTART设计三:字符和数据显示的设计实验内容:编写程序,先显示信息“INPUTSTRINGIS”,在接受字符。如为0-9,则计数器加1,并显示数据,非数字,则直接显示,但不计数。源程序:CRLFMACROMOVAH,02HMOVDL,0DHINT21HMOVAH,02HMOVDL,0AHINT21HENDMDATASEGMENTMESS1DB'INPUTSTRINGIS$'MESS2DB'Char=$'MESS3DB'Notnumber=$'MESS4DB'Num=$'TOTALDW?DATAENDSSTACKSEGMENTSTADW32DUP(?)TOPDW?STACKENDSCODESEGMENTASSUMECS:CODE,DS:DATA,ES:DATA,SS:STACKSTART:MOVAX,DATAMOVDS,AXMOVES,AXMOVSP,TOP;初始化MOVBX,0000H;计数值清0MOVAH,09HMOVDX,OFFSETMESS1INT21HCRLFXXX:MOVAH,01HINT21H;接收键入字符CMPAL,20HJZUUU;是空格键则转UUUCMPAL,0DHJNZIIICRLF;是回车键则转UUUJMPUUUIII:CMPAL,30HJBYYYCMPAL,39HJBEVVV;`0-9`转VVVYYY:INCBX;计数值加1VVV:INCTOTALJMPXXXUUU:CRLFMOVAH,09HLEADX,MESS2;显示字符总数INT21HMOVAX,TOTALCALLDISPMOVAH,02HMOVDL,'H'INT21HCRLF;回车换行MOVAH,09HMOVDX,OFFSETMESS3INT21H;显示非数字字符总数MOVAX,BXCALLDISPMOVAH,02HMOVDL,'H'INT21H;十六进制数标志CRLFMOVAH,09HLEADX,MESS4;显示数字字符总数INT21HMOVAX,BXSUBTOTAL,AXMOVAX,TOTALCALLDISPMOVAH,02HMOVDL,'H'INT21HMOVAH,4CHINT21HDISPPPROCNEAR;显示子程序,显示AL中的数按十六进制数方式MOVBL,AL;AL中数送BLKKK:MOVDL,BLMOVCL,04ROLDL,CLANDDL,0FHCALLDISPL;显示字节高位MOVDL,BLANDDL,0FHCALLDISPL;显示字节低位RETDISPPENDPDISPLPROCNEARADDDL,30H;由数值转为参应字符的ASCII码CMPDL,3AHJBDDD;是0-9转DDDADDDL,07H;是A-FDDD:MOVAH,02HINT21H;显示DL中字符RET;返回DISPLENDP;显示子程序,显示AX中的数按十六进制数方式DISPPROCNEARPUSHBXPUSHCXPUSHDXPUSHAX;入栈保存MOVAL,AHCALLDISPP;显示高字节POPAXCALLDISPPPOPDXPOPCXPOPBXRET;出栈DISPENDPCODEENDSENDSTART设计四:键盘输入小写字母转换成大写字母实验内容:编写程序,接收键盘字符,并将其中的小写字母变为大写字母,然后显示在屏幕上。源程序:DATASEGMENTp1db100P2db0arraydb100dup(?)DATAENDSCODESEGMENTASSUMECS:CODE,DS:DATASTART:MOVAX,DATAMOVDS,AXmovdx,offsetp1MOVAH,0AHINT21Hxorbx,bxmovBL,p2movarray[bx],'$'movdi,0ffffhnext:incdicmparray[di],'$'jeexitcmparray[di],61hjlnextcmparray[di],7ahjgnextsubarray[di],20hjmpnextexit:movp1,0dhmovp2,0ahMOVAH,09HINT21HMOVAH,4CHINT21HCODEENDSENDSTART设计五:计算N!的设计实验内容:编写程序,计算N!的程序。数值N由键盘输入,结果显示在屏幕上。N的范围为0—65535,即刚好能被16的寄存器容纳。源程序:CRLFMACRO;回车,换行MOVAH,02HMOVDL,0DHINT21HMOVAH,02HMOVDL,0AHINT21HENDMDATASEGMENTMESS1DB'INPUTTHENUMBERACCORDINGTOHEXNUM!',0DH,0AH,'$'MESS2DB'THERESULTIS:$'ERRORDB'INPUTERROR!INPUTONCEMORE!',0DH,0AH,'$'LENDW1CYDW?BUFDW256DUP(0)DATAENDSSTACKSSEGMENTSTACK'STACK'DW32DUP(?)STACKSENDSCODESEGMENTASSUMECS:CODE,DS:DATA,ES:DATA,SS:STACKSSTART:MOVAX,DATAMOVDS,AXMOVES,AXMOVAH,09HMOVDX,OFFSETMESS1INT21H;显示输入提示信息CALLGETNUM;读取键入的N值MOVBP,DX;N值送BPCMPBP,0JZEEECMPBP,1JZEEE;N=0或N=1则转EEEMOVSI,OFFSETBUF;缓冲区首址MOV[SI],DX;缓冲区初始化为值NXXX:DECBP;N值减1CMPBP,0001HJZLLL;若为1则转LLLXORBX,BX;偏移指针清0MOVWORDPTRCY,0;进位单元清0MOVCX,LEN;当前结果长度送CXTTT:MOVAX,[SI+BX]MULBP;相乘ADDAX,CY;加低位进位JNCJJJ;结果无进位转JJJINCDX;有进位将高位单元加1JJJ:MOV[SI+BX],AX;结果送缓冲区中MOVCY,DX;高位单元送进位单元INCBXINCBX;一个字长度LOOPTTT;循环CMPDX,0000HJZBBB;最后1次的进位为0则转BBBINCWORDPTRLEN;长度加1MOV[SI+BX],DX;进位送
本文标题:微机原理汇编程序设计
链接地址:https://www.777doc.com/doc-5747459 .html