微机原理上机答案(西电)上机作业(三)编写如下程序,并在机器上调试成功。程序采用菜单式选择,可以接收用户从键盘输入的五个命令(1-5),各命令功能分别为:(1)按下“1”键,完成字符串小写字母变成大写字母。用户输入一由英文大小写字母或数字0-9组成的字符串(以回车结束),程序逐个检查字符串中各字符,将原串中小写字母变成大写字母,其他字符不变,并在屏幕上显示。用户按任一键,重做,按ESC键,返回主菜单。(2)按下“2”键,完成找最大值(二选一)。a.接收用户输入的可显示字符串(以回车结束),程序将其中ASCII码值最大的字符显示出来;b.接收用户输入若干个无符号8位数(以空格或逗号为分隔符,以回车结束),程序将其中最大的数显示出来。用户按任一键,重做,按ESC键,返回主菜单。(3)按下“3”键,完成排序(二选一)。a.接收用户输入的可显示字符串,以回车结束。程序按ASCII码值大小由大到小排序并输出显示;b.接收用户输入若干个有符号8位数(以空格或逗号为分隔符,以回车结束),程序将其中最大的数显示出来。用户按任一键,重做,按ESC键,返回主菜单。(4)按下“4”键,显示时间。首先提示用户对时,即用户输入时、分、秒(以空格或逗号为分隔符,以回车结束),然后,在屏幕上不断显示时间,格式为:XX(时):XX(分):XX(秒)最好定点显示。用户按任一键,重新对时,按ESC键,返回主菜单。(5)按下“5”键,结束程序运行,返回系统提示符。程序代码:STACKSEGMENTSTACKDB256DUP(?)TOPLABELWORDSTACKENDSDATASEGMENTTABLEDWG1,G2,G3,G4,G5STRING1DB'1.Changesmalllettersintocapitallettersofstring;',0DH,0AH,'$'STRING2DB'2.Findthemaximumofstring;',0DH,0AH,'$'STRING3DB'3.Sortfordatas;',0DH,0AH,'$'STRING4DB'4.ShowTime;',0DH,0AH,'$'STRING5DB'5.Exit.',0DH,0AH,'$'STRINGNDB'Inputthenumberyouselect(1-5):$'IN_STRDB'Inputthestring(includingletters&numbers,lessthan60letters):',0DH,0AH,'$'PRESTRDB'Originalstring:$'NEWSTRDB'Newstring:$'OUT_STRDB'Thestringis$'MAXCHRDB'Themaximumis$'IN_NUMDB'Inputthenumbers(0-255,nomorethan20numbers):',0DH,0AH,'$'OUT_NUMDB'Sortednumbers:',0DH,0AH,'$'IN_TIMDB'Correctthetime(HH:MM:SS):$'HINTSTRDB'PressESC,gobacktothemenu;orpressanykeytoplayagain!$'KEYBUFDB61DB?DB61DUP(?)NUMBUFDB?DB20DUP(?)DATAENDSCODESEGMENTASSUMECS:CODE,DS:DATA,SS:STACKSTART:MOVAX,DATAMOVDS,AXMOVAX,STACKMOVSS,AXMOVSP,OFFSETTOPMAIN:CALLFARPTRMENU;设置显示器AGAIN:MOVAH,2MOVBH,0;页号MOVDL,41;列号MOVDH,10;行号INT10H;光标位置设置MOVAH,1INT21HCMPAL,'1'JBAGAINCMPAL,'5'JAAGAINSUBAL,'1';N-1SHLAL,1;(N-1)*2CBW;AL-AXLEABX,TABLEADDBX,AXJMPWORDPTR[BX]G1:CALLFARPTRCHGLTRMOVAH,8INT21HCMPAL,1BHJZMAINJMPG1G2:CALLFARPTRMAXLTRMOVAH,8INT21HCMPAL,1BHJZMAINJMPG2G3:CALLFARPTRSORTNUMMOVAH,8INT21HCMPAL,1BHJZMAINJMPG3G4:CALLFARPTRTIMCHKMOVAH,8INT21HCMPAL,1BHJZMAINJMPG4G5:MOVAH,4CHINT21HMENUPROCFAR;显示主界面;设置显示器方式MOVAH,0MOVAL,3;MOVBL,0;INT10H;清屏MOVAH,2MOVBH,0;页号MOVDL,5;列号MOVDH,5;行号INT10H;光标位置设置MOVAH,9LEADX,STRING1INT21HMOVAH,2MOVDL,5;列号MOVDH,6;行号INT10H;光标位置设置MOVAH,9LEADX,STRING2INT21HMOVAH,2MOVDL,5;列号MOVDH,7;行号INT10H;光标位置设置MOVAH,9LEADX,STRING3INT21HMOVAH,2MOVDL,5;列号MOVDH,8;行号INT10H;光标位置设置MOVAH,9LEADX,STRING4INT21HMOVAH,2MOVDL,5;列号MOVDH,9;行号INT10H;光标位置设置MOVAH,9LEADX,STRING5INT21HMOVAH,2MOVDL,5;列号MOVDH,10;行号INT10H;光标位置设置MOVAH,9LEADX,STRINGNINT21HRETMENUENDPCHGLTRPROCFAR;将输入字符串中小写字母便换成大写字母RECHG:;设置显示器方式MOVAH,0MOVAL,3MOVBL,0INT10H;清屏MOVAH,2MOVBH,0;页号MOVDL,5;列号MOVDH,5;行号INT10H;输入提示光标位置设置MOVAH,9LEADX,IN_STRINT21H;输入字符串提示MOVAH,2MOVDL,5;列号MOVDH,6;行号INT10H;输入字符串光标位置设置MOVAH,0AHLEADX,KEYBUFINT21H;输入字符串CMPKEYBUF+1,0JZRECHG;判断输入字符串是否为空串LEABX,KEYBUF+2MOVAL,KEYBUF+1CBWMOVCX,AXADDBX,AXMOVBYTEPTR[BX],'$';在输入字符串尾加结束标志$MOVAH,2MOVBH,0;页号MOVDL,5;列号MOVDH,7;行号INT10H;源字符串提示光标位置设置MOVAH,9LEADX,PRESTRINT21H;输出源字符串提示MOVAH,9LEADX,KEYBUF+2INT21H;输出源字符串LEABX,KEYBUF+2LCHG:CMPBYTEPTR[BX],61HJBNOCHGANDBYTEPTR[BX],0DFHNOCHG:INCBXLOOPLCHG;将字符串中小写字母转换成大写字母MOVAH,2MOVBH,0;页号MOVDL,5;列号MOVDH,8;行号INT10H;新字符串提示光标位置设置MOVAH,9LEADX,NEWSTRINT21H;输出新字符串提示MOVAH,9LEADX,KEYBUF+2INT21H;输出新字符串MOVAH,2MOVBH,0;页号MOVDL,5;列号MOVDH,9;行号INT10H;提示信息光标位置设置MOVAH,9LEADX,HINTSTRINT21H;输出提示信息RETCHGLTRENDPMAXLTRPROCFAR;在输入字符串中找出最大值REMAX:;设置显示器方式MOVAH,0MOVAL,3MOVBL,0INT10H;清屏MOVAH,2MOVBH,0;页号MOVDL,5;列号MOVDH,5;行号INT10H;输入提示光标位置设置MOVAH,9LEADX,IN_STRINT21H;输入字符串提示MOVAH,2MOVDL,5;列号MOVDH,6;行号INT10H;输入字符串光标位置设置MOVAH,0AHLEADX,KEYBUFINT21H;输入字符串CMPKEYBUF+1,0JZREMAX;判断输入字符串是否为空串LEABX,KEYBUF+2MOVAL,KEYBUF+1CBWMOVCX,AXADDBX,AXMOVBYTEPTR[BX],'$';在输入字符串位加结束标志$MOVAH,2MOVBH,0;页号MOVDL,5;列号MOVDH,7;行号INT10H;源字符串提示光标位置设置MOVAH,9LEADX,OUT_STRINT21H;输出字符串提示MOVAH,9LEADX,KEYBUF+2INT21H;输出字符串MOVAH,2MOVBH,0;页号MOVDL,5;列号MOVDH,8;行号INT10H;新字符串提示光标位置设置MOVAH,9LEADX,MAXCHRINT21H;输出字符串中最大值提示MOVDL,0LEABX,KEYBUF+2LCMP:CMP[BX],DLJBNOLCHGMOVDL,[BX]NOLCHG:INCBXLOOPLCMP;找出字符串中最大字符,放入DLMOVAH,2INT21H;输出字符串中最大字符MOVAH,2MOVBH,0;页号MOVDL,5;列号MOVDH,9;行号INT10H;提示信息光标位置设置MOVAH,9LEADX,HINTSTRINT21H;输出提示信息RETMAXLTRENDPSORTNUMPROCFAR;对输入数据组排序RESORT:;设置显示器方式MOVAH,0MOVAL,3MOVBL,0INT10H;清屏MOVAH,2MOVBH,0;页号MOVDL,5;列号MOVDH,5;行号INT10H;输入提示光标位置设置MOVAH,9LEADX,IN_NUMINT21HMOVAH,2MOVDL,5;列号MOVDH,6;行号INT10H;输入数据组光标位置设置MOVAH,0AHLEADX,KEYBUFINT21H;输入数据组字符串CALLCIN_INT;字符串转换成数据串CMPAL,0JZRESORT;判断数据串是否有错CMPNUMBUF,0JZRESORT;判断数据串是否为空MOVAH,2MOVBH,0;页号MOVDL,5;列号MOVDH,7;行号INT10H;输出提示光标位置设置MOVAH,9LEADX,OUT_NUMINT21H;输出数据串提示MOVAH,2MOVBH,0;页号MOVDL,5;列号MOVDH,8;行号INT10H;输出数据组光标位置设置CALLFARPTRMPSORT;数据组排序CALLFARPTRINT_OUT;数据组的输出MOVAH,2MOVBH,0;页号MOVDL,5;列号MOVDH,9;行号INT10H;提示信息光标位置设置MOVAH,9LEADX,HINTSTRINT21H;输出提示信息RETSORTNUMENDPCIN_INTPROCNEAR;读入整型数;入口参数:无;出口参数为:AL(有无错误标志,0为有,1为无)MOVCL,KEYBUF+1LEASI,KEYBUF+2MOVCH,0;数据组数据个数置0MOVDH,10MOVAL,0;当前数据x=0MOVDL,0;有无数据标志置0,即无数据FNDNUM:CMPBYTEPTR[SI],''JZADDNUM;判断当前字符是否为空格CMPBYTEPTR[SI],'0'JBERRNUMCMPBYTEPTR[SI],'9'JAERRNUM;判断当前字符是否在'0'-'9'之间MOVDL,1;有无数据标志置1,即有数据MULDHXORBH,BHMOVBL,[SI]ADDAX,BXSUBAX,'0';计算出当前数据xCMPAH,0JAERRNUM;判断x是否越界JMPNEXTADDNUM:CMPDL,1JNZNEXT;判断是否有数据INCCH;数据组数据个数加1CALLADDNEWMOVDL,0MOVAL,0;清零NEXT:INC