您好,欢迎访问三七文档
当前位置:首页 > 行业资料 > 畜牧/养殖 > 华南农业大学8086汇编实验答案
1-1DATASSEGMENTSTRINGDBBASEDADDRESSING,13,10,'$'LENEQU$-STRINGDATASENDSSTACKSSEGMENTSTACKSENDSCODESSEGMENTASSUMECS:CODES,DS:DATAS,SS:STACKSSTART:MOVAX,DATASMOVDS,AXLEADX,STRINGMOVAH,9INT21HLEASI,STRINGADDSI,LENSUBSI,03HMOVCX,LENSUBCX,02HLOP1:MOVAH,02HMOVDL,[SI]INT21HDECSILOOPLOP1MOVAH,4CHINT21HCODESENDSENDSTART1-2DATASSEGMENTXDBX=$YDB13,10,Y=$ZDB13,10,X+Y=$DATASENDSSTACKSSEGMENTSTACKSENDSCODESSEGMENTASSUMECS:CODES,DS:DATAS,SS:STACKSSTART:MOVAX,DATASMOVDS,AXMOVAH,9;输出“X=”LEADX,XINT21HMOVAH,1;输入并回显X,X放在CLINT21HSUBAL,30HMOVCL,ALMOVAH,9;输出“Y=”LEADX,YINT21HMOVAH,1;输入并回显Y,Y放在DL,X+Y的值放在CLINT21HSUBAL,30HADDCL,ALMOVAH,9;输出“X+Y=”LEADX,ZINT21HMOVAH,2;输出X+Y的值MOVDL,CLADDDL,30HINT21HMOVAH,4CHINT21HCODESENDSENDSTART1-3DATASSEGMENTARRAYDB64DUP(25H,43H,41H,78h)UPDW0DOWNDW0DATASENDSSTACKSSEGMENTSTACKSENDSCODESSEGMENTASSUMECS:CODES,DS:DATAS,SS:STACKSSTART:MOVAX,DATASMOVDS,AXLEASI,ARRAYMOVCX,100HC0:MOVAL,[SI]CMPAL,42HJBC1JNBC2C1:INCDOWNJMPC3C2:INCUPJMPC3C3:INCSILOOPC0MOVAH,4CHINT21HCODESENDSENDSTART2-1DATASSEGMENTCAPITALDB13,10,'$'SDB13,10,Pleaseenteralowercaseletter:,'$'DATASENDSSTACKSSEGMENTSTACKSENDSCODESSEGMENTASSUMECS:CODES,DS:DATAS,SS:STACKSSTART:MOVAX,DATASMOVDS,AXMOVCX,5L:MOVAH,1INT21HMOVBL,ALCMPBL,61HJBEXCEPTIONCMPBL,7AHJNBEXCEPTIONPUSHAXLEADX,CAPITALMOVAH,9INT21HPOPDXSUBDL,20HMOVAH,2INT21HJMPFINALEXCEPTION:LEASI,SMOVDX,SIMOVAH,9INT21HLOOPLFINAL:MOVAH,4CHINT21HCODESENDSENDSTART2-2DATASSEGMENTSTRINGDBzabcdefghijklmnopqrstuvwxyzaSPACEDB13,10,'$'DATASENDSSTACKSSEGMENTSTACKSENDSCODESSEGMENTASSUMECS:CODES,DS:DATAS,SS:STACKSSTART:MOVAX,DATASMOVDS,AXMOVAH,1;输入并回显测试的一个小写字母INT21HLEADX,SPACEMOVAH,9INT21HLEASI,STRING;在字符串string中查找输入的字母L:INCSICMPAL,[SI]JNZLDECSI;显示前导字母、输入字母和后续字母MOVCX,3L1:MOVDL,[SI]MOVAH,2INT21HINCSILOOPL1MOVAH,4CHINT21HCODESENDSENDSTART2-3DATASSEGMENTSTRING1DBASTRINGCOUNT1DW$-STRING1STRING2DBSTRINGCOUNT2DW$-STRING2ANSWER1DB'MATCH','$'ANSWER2DB'NOMATCH','$'DATASENDSSTACKSSEGMENTSTACKSENDSCODESSEGMENTASSUMECS:CODES,DS:DATAS,SS:STACKSSTART:MOVAX,DATASMOVDS,AXMOVAX,COUNT1;比较字符串长度是否相同MOVBX,COUNT2CMPAX,BXJNZNEXTMOVCX,COUNT1;循环比较字符串的每个字符LEASI,STRING1LEADI,STRING2L:MOVAL,[SI]CMPAL,[DI]JNZNEXT;如果不相同就jmp到next段执行INCSIINCDILOOPLLEADX,ANSWER1;两个字符串匹配MOVAH,9INT21HJMPFINALNEXT:LEADX,ANSWER2;两个字符串不匹配MOVAH,9INT21HFINAL:MOVAH,4CHINT21HCODESENDSENDSTART2-4DATASSEGMENTMDB4DUP(8,-2,2,-3,-5)PDW0NDW0S1DBThenumberofpositivenumbers:,'$'S2DB13,10,Thenumberofnegativenumbers:,'$'DATASENDSSTACKSSEGMENTSTACKSENDSCODESSEGMENTASSUMECS:CODES,DS:DATAS,SS:STACKSSTART:MOVAX,DATASMOVDS,AXLEASI,MMOVCX,20L:MOVAL,[SI]CMPAL,0;每个数跟0比较JLL1;负数jmp到L1JGL2;正数jmp到L2L1:INCNJMPL3L2:INCPJMPL3L3:INCSILOOPLLEADX,S1MOVAH,9INT21HLEADI,PMOVAX,[DI];输出正数的个数MOVBL,10dDIVBLMOVDL,ALMOVBH,AHADDDL,30HMOVAH,2INT21HMOVDL,BHADDDL,30HMOVAH,2INT21HLEADX,S2MOVAH,9INT21HLEADI,NMOVAX,[DI];输出负数的个数MOVBL,10dDIVBLMOVDL,ALMOVBH,AHADDDL,30HMOVAH,2INT21HMOVDL,BHADDDL,30HMOVAH,2INT21HMOVAH,4CHINT21HCODESENDSENDSTART3-1DATASSEGMENTDATADW10DUP(5,6,-4,-5,8,9,10,188,-178,-255)COUNTDW($-DATA)/2COUNT1DW0DATASENDSSTACKSSEGMENTSTACKSENDSCODESSEGMENTASSUMECS:CODES,DS:DATAS,SS:STACKSSTART:MOVAX,DATASMOVDS,AXMOVCX,COUNTLEASI,DATA-2L1:ADDSI,2;寻找第一个偶数放在AXMOVAX,[SI]DECCXTESTAL,01HJNZL1L2:ADDSI,2;寻找第二个偶数放在BXMOVBX,[SI]CMPCX,0;如果到达数组的末尾则退出JZL4DECCXTESTBL,01HJNZL2CMPAX,BXJGL3JMPL2L3:MOVAX,BX;AXBX,两者交换寄存器内容JMPL2L4:MOVAH,4CH;程序退出INT21HCODESENDSENDSTART3-2DATASSEGMENTNUMDW0CRLFDB13,10,'$'DATASENDSSTACKSSEGMENTSTACKSENDSCODESSEGMENTASSUMECS:CODES,DS:DATAS,SS:STACKSSTART:MOVAX,DATASMOVDS,AXMOVDX,0MOVCX,4L:MOVAH,1INT21HCMPAL,40HJGL1JLL2L1:SUBAL,07H;大写字母多减7L2:SUBAL,30HPUSHAXMOVAX,NUMMOVBX,16MULBXPOPBXADCAL,BLMOVNUM,AXLOOPL;循环4次,使输入的16进制数变成10进制数LEADX,CRLFMOVAH,9INT21H;换行MOVCX,16MOVBX,NUML3:MOVDL,31HSALBX,1;左移1位,改变CFJCL4;CF为1,输出1SUBDL,1;CF为0,所以DL减去1,输出0L4:MOVAH,2INT21HLOOPL3MOVAH,4CHINT21HCODESENDSENDSTART3-3DATASSEGMENTSTRINGDB128,?,128DUP('$')CRLFDB13,10,24HCOUNTDW0NUMDW0DATASENDSSTACKSSEGMENTSTACKSENDSCODESSEGMENTASSUMECS:CODES,DS:DATAS,SS:STACKSSTART:MOVAX,DATASMOVDS,AXLEADX,STRING;键盘输入字符串MOVAH,0AHINT21HLEADX,CRLFMOVAH,9INT21HLEASI,STRING+1;CX存放着字符串个数MOVCL,[SI]MOVCH,0LEADI,STRING+2;从实际字符串开始L1:MOVAL,[DI]INCDICMPAL,30HJLL2CMPAL,39HJGL2DECNUM;如果是数字,先减NUM后加NUML2:INCNUMLOOPL1MOVCX,0MOVAX,NUML3:MOVBL,10DIVBLPUSHAXINCCXMOVAH,0CMPAL,0JNZL3L4:POPDXMOVDL,DHADDDL,30HMOVAH,2INT21HLOOPL4MOVAH,4CHINT21HCODESENDSENDSTART3-4DATASSEGMENTmemDW0,12,2,0,0,4,5,6,0,0,9COUNTDW($-mem)/2DATASENDSSTACKSSEGMENTSTACKSENDSCODESSEGMENTASSUMECS:CODES,DS:DATAS,SS:STACKSSTART:MOVAX,DATASMOVDS,AXLEADI,mem-2MOVCX,COUNTL:CMPCX,0;找到0JZNEXTADDDI,2MOVAX,[DI]DECCXCMPAX,0JNZLMOVSI,DIPUSHCXL2:CMPCX,0;找到非0JZNEXTADDSI,2MOVAX,[SI]DECCXCMPAX,0JZL2MOV[DI],AX;非0数放到0的位置MOVWORDPTR[SI],0;原先非0的位置变成0POPCXJMPLNEXT:MOVAH,4CHINT21HCODESENDSENDSTART4-1DATASSEGMENTSTRINGDB128,?,128DUP('$')DATASENDSSTACKSSEGMENTSTACKSENDSCODESSEGMENTASSUMECS:CODES,DS:DATAS,SS:STACKSSTART:MOVAX,DATASMOVDS,AXLEADX,STRINGMOVAH,0AHINT21HLEASI,STRING+1MOVCL,[SI];循环次数=实际字符数MOVCH,0INCSIL:MOVAL,[SI];判断是否有字符是数字CMPAL,30HJLL1CMPAL,39HJGL1ORCL,00100000B;有数字则CL第五位置零JMPNEXTL1:INCSILOOPLL2:ANDCL,110111
本文标题:华南农业大学8086汇编实验答案
链接地址:https://www.777doc.com/doc-4726911 .html