微机软件实验习题与答案(完整版)

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

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

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

资源描述

1微机原理软件实验实验1两个多位十进制数相加的实验实验内容:将两个多位十进制数相加,要求加数和被加数均以ASCII码形式各自顺序存放以DATA1和DATA2为首的5个内存单元中(低位在前),结果送回DATA1处。完整代码如下:DATASSEGMENT;此处输入数据段代码STRING1DB'inputthefirstnumber:','$'STRING2DB13,10,'inputthesecondnumber:','$'STRING3DB13,10,'theoutputis:','$'DATA1DB6DUP(00H),'$'DATA2DB6DUP(00H),'$'DATASENDSSTACKSSEGMENT;此处输入堆栈段代码STACKSENDSCODESSEGMENT2ASSUMECS:CODES,DS:DATAS,SS:STACKSSTART:MOVAX,DATASMOVDS,AX;此处输入代码段代码LEASI,DATA1LEADI,DATA2L0:LEADX,STRING1;打印字符串STRING1MOVAH,09INT21HINPUT1:;输入第一个数MOVAH,01;输入字符至AL中INT21HCMPAL,'/'JEL1MOV[SI],ALINCSI3JMPINPUT1L1:LEADX,STRING2;打印字符串STRING2MOVAH,09INT21HINPUT2:;输入第二个数MOVAH,01;输入字符至ALINT21HCMPAL,'/'JEL2MOV[DI],ALINCDIJMPINPUT2L2:MOVSI,0CLC;清空进位标志位CFMOVCX,64PLUSE:;相加;SUBDATA1[SI],30H;SUBDATA2[SI],30H;这里不能使用这两条指令,因为如果DATA1[5]=00H,00H-30H需要借位相减,使CF=1MOVAL,DATA1[SI]ADCAL,DATA2[SI]AAA;加法调整指令,可使两个ASCII数直接相加MOVDATA1[SI],AL;和赋给DATA1[SI]INCSILOOPPLUSEL3:LEADX,STRING3;打印字符串STRING3MOVAH,09INT21HMOVCX,6MOVSI,6SHOW:5DECSICMPDATA1[SI],00HJESHOWSHOW2:MOVDL,DATA1[SI]ADDDL,30HMOVAH,02INT21HCMPSI,0JEL4DECSIJMPSHOW2L4:MOVAH,4CHINT21HCODESENDSENDSTART运行结果如下:输入为低位在前,即输入1234和99999相加实际上是4321和99999相加(即:4321+99999=104320)6实验2两个数相乘的实验(无符号数相乘)实验内容:实现十进制数的乘法。要求被乘数和乘数均以ASCII码形式各自顺序存放在内存中,乘积在屏幕上显示出来。完整代码如下:DATASSEGMENT;此处输入数据段代码STRING1DB'theoutputis:','$'DATA1DB31H,32H,33HDATA2DB35H,36HDATASENDSSTACKSSEGMENT7;此处输入堆栈段代码STACKSENDSCODESSEGMENTASSUMECS:CODES,DS:DATAS,SS:STACKSSTART:MOVAX,DATASMOVDS,AX;此处输入代码段代码MOVDL,10MOVAL,DATA1[0];AL=31HSUBAL,30H;AL=01HMULDL;乘10;AL=10ADDAL,DATA1[1];AL=10+32HSUBAL,30H;AL=10+32H-30H=12MULDL;AL=120ADDAL,DATA1[2];AL=120+33HSUBAL,30H;AL=120+33H-30H=1238MOVBL,AL;BL=AL;MOVAL,DATA2[0];AL=35HSUBAL,30H;AL=5MULDL;乘10;AL=50ADDAL,DATA2[1];AL=50+36HSUBAL,30H;AL=50+36H-30H=56MULBL;AX=123x56=6888SUBDX,DX;DX清零MOVBX,1000DIVBX;(DX,AX)/1000,商6在AX中,余数888在DX中PUSHDXMOVDL,ALADDDL,30HMOVAH,02;打印最高位6INT21HPOPDX9MOVBL,100MOVAX,DX;888赋给AXDIVBL;AX/100,商放在AL中,余数88放在AH中MOVDL,ALMOVCL,AH;!!!这里千万不能把AH直接赋给AL,因为经过INT21H指令后AL,AH会改变ADDDL,30HMOVAH,02;打印第二位INT21HMOVBL,10MOVAL,CLSUBAH,AH;清空AHDIVBL;AX/10,商放在AL中,余数8放在AH中MOVDL,ALMOVCL,AHADDDL,30HMOVAH,02;打印第三位INT21H10MOVDL,CLADDDL,30HMOVAH,02;打印第四位INT21HCODESENDSENDSTART运行结果为:实验3字符串匹配实验实验内容:编写程序实现两个字符串比较。如果相同,则屏幕显示“match”,否则屏幕显示”nomatch”,完整代码如下:DATASSEGMENT;此处输入数据段代码PRINT1DB'inputthefirststring:','$'PRINT2DB13,10,'inputthesecondstring:','$'PRINT3DB'match','$'11PRINT4DB'nomatch','$'PRINT5DB13,10,'output:','$'STRING1DB30DUP(00H),13,10,'$'STRING2DB30DUP(00H),13,10,'$'DATASENDSSTACKSSEGMENT;此处输入堆栈段代码STACKSENDSCODESSEGMENTASSUMECS:CODES,DS:DATAS,SS:STACKS,ES:DATASSTART:MOVAX,DATASMOVDS,AX;此处输入代码段代码LEADX,PRINT1;打印字符串PRINT1MOVAH,09INT21H12LEASI,STRING1;STRING1地址赋给SILEADI,STRING2;STRING2地址赋给DIINPUT1:MOVAH,01;输入字符至ALINT21HCMPAL,'/';输入字符串以‘/’结束,转L0JEL0MOV[SI],ALINCSIJMPINPUT1L0:LEADX,PRINT2;打印字符串PRINT2MOVAH,09INT21HINPUT2:13MOVAH,01;输入字符至ALINT21HCMPAL,'/'JEL1MOV[DI],ALINCDIJMPINPUT2L1:MOVCX,30;CX=30代表比较30次MOVSI,00HCOMPARE:;字符串一个一个比较MOVAL,STRING1[SI];取STRING1存储单位中的第SI个字符赋给ALCMPAL,STRING2[SI];AL与STRING2存储单位中的第SI个字符比较JNENOMATCHINCSILOOPCOMPAREJMPMATCH14NOMATCH:;打印output:nomatchLEADX,PRINT5MOVAH,09INT21HLEADX,PRINT4MOVAH,09INT21HJMPL2MATCH:;打印output:matchLEADX,PRINT5MOVAH,09INT21HLEADX,PRINT3MOVAH,09INT21HL2:MOVAH,4CHINT21HCODESENDS15ENDSTART运行结果:16实验4从键盘输入数据并显示的实验实验内容:将键盘输入的2位十六进制数转换为等值的二进制数,并在屏幕上显示。列如:键入f2,则显示11110010.完整代码如下:DATASSEGMENT;此处输入数据段代码STRING1DB'pleaseinputastring:','$'STRING2DB13,10,'theoutputis:','$'STRING3DB13,10,'inputerror',13,10,'$'DATASENDSSTACKSSEGMENT;此处输入堆栈段代码STACKSENDSCODESSEGMENTASSUMECS:CODES,DS:DATAS,SS:STACKSSTART:MOVAX,DATASMOVDS,AX17;此处输入代码段代码L0:LEADX,STRING1;打印字符串STRING1MOVAH,09INT21HMOVAH,01;输入第一个字符至AL中INT21HCMPAL,'0'JBERROR1CMPAL,'9'JBEENTER1CMPAL,'A'JBERROR1CMPAL,'F'JBEENTER1CMPAL,'a'JBERROR1CMPAL,'f'JBEENTER118ERROR1:LEADX,STRING3;打印字符串STRING3MOVAH,09INT21HJMPL0ENTER1:CALLASC2BCD;把ASCII码转化成十进制数BCD码MOVCL,4ROLAL,CLMOVBL,AL;把高四位放到BL寄存器中;输入第二个字符MOVAH,01;输入第二个字符至AL中INT21HCMPAL,'0'JBERROR1CMPAL,'9'JBEENTER2CMPAL,'A'JBERROR119CMPAL,'F'JBEENTER2CMPAL,'a'JBERROR1CMPAL,'f'JBEENTER2ENTER2:CALLASC2BCD;把ASCII码转化成十进制数BCD码ADDBL,ALLEADX,STRING2;打印字符串STRING2MOVAH,09INT21HMOVCX,9CLC;清空标志位SHOW:;显示BL中的二进制数DECCXCMPCX,020JENEXT;输出完八位之后返回DOSROLBL,1;循环左移一位,若溢出为1,则CF=1JCM1JMPM2M1:MOVDL,'1';若CF=1,转至M1打印‘1’MOVAH,02INT21HJMPSHOWM2:MOVDL,'0';若CF=0,转至M1打印‘0’MOVAH,02INT21HJMPSHOWNEXT:MOVAH,4CHINT21HASC2BCDPROCCMPAL,'9'21JBEL1;若AL≤9,转L1SUBAL,07H;若输入的数为A~F,或者a~f,则减7,A接在39H后面,A~F=3AH~3FH,a~f=5AH~5FHL1:SUBAL,30H;减30HANDAL,0FH;滤除高位,保留低位,因为a~f恰好比A~F大20H,这样a~f就和A~F的数值一样了RETASC2BCDENDPCODESENDSENDSTART输出结果为:(若输出不在0~9,A~F,a~f内,则重新输入)22实验5字符和数据计算的实验实验内容:先在屏幕上显示“inputstring,”,输入字符串;再显示“result=”。如为0~9的数字,则计数器加1,如为非数字,则直接显示,但不计数。完整代码如下:DATASSEGMENT;此处输入数据段代码STRING1DB'inputstring:','$'STRING2DB13,10,'result=','$'STRING3DB13,10,'zifu:','$'DATASENDSSTACKSSEGMENT;此处输入堆栈段代码STACKSENDSCODESSEGMENTASSUMECS:CODES,DS:DATAS,SS:STACKSSTART:MOVAX,DATASMOVDS,AX;此处输入代码段代码LEADX,STRING1;打印字符串123MOVAH,09INT21HMOVCX,0MOVBX,0INPUT:MOVAH,01;输入字符至ALINT21HCMPAL,'/';输入/后转L0JEL0CMPAL,'0';下溢出转RUZHANJBRUZHANCMPAL,'9';

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

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

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

×
保存成功