微机原理实验1.验收要求(1)对于一个编辑好的任一汇编语言源程序,会进行编译和连接,最终生成一个可执行程序。(DOS环境运行)(2)对三个给定的题目进行验收。(在给出的仿真环境编辑和运行)2.题目(1)排序对输入的多个数字进行排序。要求:(a)所有数字从键盘输入;(b)数字中至少包含一个大于10的数字;(c)排好序的数字以十进制形式在屏幕显示输出。答案:DATASEGMENTSTRING1DB'PleaseInputthenumber:','$';提示输入STRING2DB'Theorderfrommaxtomin:','$';输出排序从大到小SCOREDW100DUP(0);分配存放空间DATAENDSSTACKSEGMENT;堆栈段DW64DUP(0)STACKENDSCODESEGMENT;代码段ASSUMECS:CODE,DS:DATA,SS:STACKSTART:MOVAX,DATAMOVDS,AXMOVAX,STACKMOVSS,AXMOVDX,OFFSETSTRING1;显示提示输入MOVAH,09HINT21HXORBX,BX;寄存器清零XORCX,CXXORSI,SIXORDI,DIINPUT:MOVAH,1;输入一个字符INT21HCMPAL,0DH;是否为回车键JZOVER;是就跳到OVERCMPAL,20H;是否为空格JZSAVE;是就跳到SAVESUBAL,30H;变为真数MOVCL,4SHLBX,CL;左移四位,变为BCD码ADDBL,ALJMPINPUTSAVE:MOVSCORE[SI],BX;保存到SCORE中ADDSI,2INCDIXORBX,BXJMPINPUTOVER:MOVSCORE[SI],BX;保存最后一个数据,并存放到SCORE中INCDIMOVDL,0AHMOVAH,02HINT21HMOVCX,DIDECCXXORBX,BXCOMP1:MOVSI,2;指向下一个数MOVDX,CXCOMP2:MOVAX,SCORE[BX]CMPAX,SCORE[BX+SI];比较前后两个数JNCCOMP3;小于就跳到COMP3XCHGAX,SCORE[BX+SI];交换位置MOVSCORE[BX],AXCOMP3:ADDSI,2;指向下一个数DECDXJNZCOMP2ADDBX,2;指向下一个数LOOPCOMP1MOVDX,OFFSETSTRING2MOVAH,09HINT21HSUBSI,SI;把SI清零OUT_PUT:MOVBX,SCORE[SI];输出百位数MOVDL,BHANDDL,0FHADDDL,30HMOVAH,02HINT21HMOVDL,BL;输出十位数MOVCL,4SHRDL,CLADDDL,30HMOVAH,02HINT21HMOVDL,BL;输出个位数ANDDL,0FHADDDL,30HMOVAH,02HINT21HMOVDL,20H;输出空格MOVAH,02HINT21HADDSI,2DECDIJNZOUT_PUTMOVAH,4CH;返回DOSINT21HCODEENDSENDSTART(2)数制转换将输入的一个数据以不同进制形式输出。要求:(a)所有数字从键盘输入;(b)输入数据为任意一个小于十万的十进制数据;(c)将所输入数据以十六进制在屏幕显示输出(即十进制转十六进制)。答案:DATASEGMENTKEYBUFFERDB100DB?DB100DUP(?)STRING1DBPleaseinputdecimaldata:$DATAENDSCODESEGMENTASSUMECS:CODE,DS:DATA,ES:DATASTART:MOVAX,DATAMOVDS,AXMOVES,AXLEADX,STRING1;显示提示输出MOVAH,09HINT21HMOVAH,0AHLEADX,KEYBUFFERINT21HLEASI,KEYBUFFER+1CALLTRANS10TO16CALLDISPCRCALLDISPAXCALLDISPCRMOVAX,BXCALLDISPAXMOVAH,4CHINT21HDISPALPROCNEARPUSHAXPUSHCXPUSHDXPUSHAXMOVCL,4;处理高位十六进制数SHRAL,CLCALLCHANG;十六进制数变换成ASCII码MOVAH,02MOVDL,ALINT21HPOPAXANDAL,0FH;处理低位十六进制数CALLCHANG;同上解释MOVAH,02MOVDL,ALINT21HPOPDXPOPCXPOPAXRETDISPALENDPCHANGPROCNEAR;数码转换CMPAL,10JNGECHANG1ADDAL,7CHANG1:ADDAL,30HRETCHANGENDPDISPAXPROCNEARXCHGAL,AHCALLDISPALXCHGAH,ALCALLDISPALRETDISPAXENDPDISPCRPROCNEARPUSHAXPUSHDXMOVAH,2MOVDL,0AHINT21HMOVAH,2MOVDL,0DHINT21HPOPDXPOPAXRETDISPCRENDPTRANS10TO16PROCNEARPUSHCXPUSHDXPUSHSIXORAX,AXXORCX,CXMOVCL,[SI]INCSIMOVAL,[SI]INCSISUBAL,30HDECCXJCXZTRANSF2MOVBX,10TRANSF1:MULBXJCTRANSF_ERRMOVDL,[SI]INCSISUBDL,30HADDAL,DLADCAH,0JCTRANSF_ERRLOOPTRANSF1MOVBX,0TRANSF2:JMPTRANSF_OKTRANSF_ERR:MOVBX,-1TRANSF_OK:POPSIPOPDXPOPCXRETTRANS10TO16ENDPCODEENDSENDSTART(3)成绩汇总对输入的一些成绩进行分类汇总。要求:(a)所有数字由键盘输入;(b)输入的成绩个数为任意个(小于100);(c)对成绩进行归类并输出显示在屏幕:·显示最高成绩、最低成绩、平均成绩·显示90-100分人数,80-89分人数,70-79分人数,60-69分人数,低于60分人数,·显示无效数字个数(非数字或大于100数字个数)答案:DATASEGMENTSTRING1DB'PleaseInputScore:','$';提示输入STRMADB'THEMAXSCOREIS:','$'STRMIDB'THEMINSCOREIS:','$'STRAVDB'THEAVERAGESCOREIS:','$'STR1DB'THENUMOF0-59:','$'STR2DB'THENUMOF60-69:','$'STR3DB'THENUMOF70-79:','$'STR4DB'THENUMOF80-89:','$'STR5DB'THENUMOF90-100:','$'STR6DB'THEWRONGNUM:','$';输出排序从大到小SCOREDW60DUP(0);分配存放空间DECIMALDB5DUP(0)S5DW0;定义变量S6DW0S7DW0S8DW0S9DW0S10DW0DATAENDSSTACKSEGMENT;堆栈段DW64DUP(0)TOPLABELWORDSTACKENDSCODESEGMENT;代码段ASSUMECS:CODE,DS:DATA,SS:STACKSTART:MOVAX,DATAMOVDS,AXMOVAX,STACKMOVSS,AXLEASP,TOPMOVDX,OFFSETSTRING1;显示提示输入MOVAH,09HINT21HXORBX,BX;寄存器清零XORCX,CXXORSI,SIXORDI,DIINPUT:MOVAH,1;输入一个字符INT21HCMPAL,0DH;是否为回车键JZOVER;是就跳到OVERCMPAL,39HJGERR_COUNT;判断是否为0-9的数CMPAL,20H;是否为空格JZSAVESUBAL,30H;变为真数MOVCL,4SHLBX,CL;左移四位,变为BCD码ADDBL,ALCMPBX,100HJGERR_COUNTJMPINPUTERR_COUNT:INCS10MOVBX,0JMPINPUTSAVE:MOVSCORE[SI],BX;保存到SCORE中ADDSI,2INCDIXORBX,BXJMPINPUTOVER:MOVSCORE[SI],BX;保存最后一个数据,并存放到SCORE中INCDIMOVDL,0AHMOVAH,02HINT21HMOVCX,DIDECCXPUSHDI;弹出输入个数***********PUSHDIPUSHDIXORBX,BXCOMP1:MOVSI,2;指向下一个数MOVDX,CXCOMP2:MOVAX,SCORE[BX]CMPAX,SCORE[BX+SI];比较前后两个数JNCCOMP3;小于就跳到COMP3XCHGAX,SCORE[BX+SI];交换位置MOVSCORE[BX],AXCOMP3:ADDSI,2;指向下一个数DECDXJNZCOMP2ADDBX,2;指向下一个数LOOPCOMP1SUBSI,SI;把SI清零OUT_PUT:LEADX,STRMA;输出有效最大值MOVAH,9INT21HMOVBX,SCORE;输出百位数MOVDL,BHANDDL,0FHADDDL,30HMOVAH,02HINT21HMOVDL,BL;输出十位数MOVCL,4SHRDL,CLADDDL,30HMOVAH,02HINT21HMOVDL,BL;输出个位数ANDDL,0FHADDDL,30HMOVAH,02HINT21HCALLDISPCRLEADX,STRMI;输出最小有效值MOVAH,9INT21HPOPDIDECDISUBDI,S10SHLDI,1MOVBX,SCORE[DI];输出百位数MOVDL,BHANDDL,0FHADDDL,30HMOVAH,02HINT21HMOVDL,BL;输出十位数MOVCL,4SHRDL,CLADDDL,30HMOVAH,02HINT21HMOVDL,BL;输出个位数ANDDL,0FHADDDL,30HMOVAH,02HINT21H;************输出平均成绩********************CALLDISPCRLEADX,STRAVMOVAH,9INT21HPOPDILEAAX,SCOREPUSHAXCALLCOMPUTMEANPOPAXCALLDISPAX;显示Ax内容;*************************************************POPDIMOVCX,DISUBCX,S10;设置计数器为DILEABX,SCORECOMPARE:MOVAX,[BX]CMPAX,60H;与60比较JLFIVE;小于就跳到FIVECMPAX,70H;与70比较JLSIX;小于就跳到SIXCMPAX,80H;与80比较JLSEVEN;小于就跳到SEVENCMPAX,90H;与90比较JLEIGHT;小于就跳到EIGHTCMPAX,100H;与100比较JLENINE;不为0就是90到100JMPNEWDATA;跳到NEWDATAFIVE:INCS5;小于60时【S5+1】JMPNEWDATA;跳到NEWDATASIX:INCS6;大于等于60小于70时【S6+1】JMPNEWDATA;跳到NEWDATASEVEN:INCS7;大于等于70小于80时【S7+1】JMPNEWDATA;跳到NEWDATAEIGHT:INCS8;大于等于80小于90时【S8+1】JMPNEWDATA;跳到NEWDATANINE:INCS9;大于等于90小于等于100时【S9+1】NEWDATA:ADDBX,2;取下个数LOOPCOMPARE;循环COMPARECALLDISPCRLEADX,STR1MOVAH,09HINT21HMOVAX,S5CALLDISPAXDCALLDISPCRLEADX,ST