资源描述:
《mcs_8086习题4_答案》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、习题4答案:1.从屏幕上输入大写字母,转换为小写字母并输出(生成.COM文件)要求:程序具有可读性、容错性codesegmentparaassumecs:code,ss:ss_seg,ds:dataorg0100Hmainprocfarmain1:leadx,str1;显示提示信息movah,9int21hmovah,1;输入小写字母int21hcmpal,‘A’;判断输入字符是否为’a’~’z’jberrorcmpal,‘Z’jaerrorjmpnexterror:leadx,str2;显示错误提示信息movah,9int21hjmpmain1;跳转,重新输入next:suba
2、l,20hpushaxleadx,str3;显示输出提示信息movah,9int21hpopaxmovdl,al;显示转换后的大写字母movah,219int21hmovax,4c00h;返回操作系统int21hmainendpstr1db0dh,0ah,‘Pleaseinput(a-z):$’str2db0dh,0ah,‘Theinputiserror!$’str3db0dh,0ah,‘Theresultis:$’codeendsendmain1.编写一子程序asc2bin,将ASCII转换为二进制数要求:输入参数:AL中存放需要转换的ASCII输出参数:AL中存放转换后的二进
3、制数并返回;功能:将ASCII转换为二进制数;输入参数:AL中存放需要转换的ASCII;输出参数:AL中存放转换后得到的二进制数asc2binprocsubal,30hcmpal,9jbeasc2bin_1subal,7asc2bin_1:retasc2binendp2.内存中存放8个16位有符号数,求8个数值之和,并将结果存放在内存变量SUM中注:程序中应用到字扩展为双字的指令CWDdatasegmentparabufdw-1,30000,35000,36000,37000,20000,10000,-2sumdd0dataends19ss_segsegmentstackdw10
4、0dup(0)ss_segendscodesegmentparaassumecs:code,ds:data,ss:ss_segmainprocfarmovax,datamovds,axleabx,buf;bx指向buf首地址movcx,8main1:movax,[bx]cwd;有符号数字扩展为双字addwordptrsum,ax;32位数相加adcwordptrsum+2,dxincbxincbxloopmain1;循环8次movax,4c00hint21hmainendpcodeendsendmain1.内存中存放8个8位有符号数,请按从大到小顺序排列datasegmentpa
5、rabufdb-1,30,35,36,37,20,100,-2dataendsss_segsegmentstackdw100dup(0)ss_segends19codesegmentparaassumecs:code,ds:data,ss:ss_segmainprocfarmovax,datamovds,axmovcx,8main1:movbx,0;外循环movdi,0pushcxmain2:moval,buf[bx];内循环cmpal,buf[bx+1]jgenextxchgal,buf[bx+1];不符合规则,则交换数据movbuf[bx],almovdi,1next:inc
6、bxloopmain2popcxcmpdi,0;判断内循环是否发生数据交换jzexitloopmain1exit:movax,4c00hint21hmainendpcodeendsendmain1.内存中有8个16位数,请编写程序将8个数倒序排放例:定义内存中8个数bufdw100,3,1,20,40,-2,7,10程序运行后,buf开始应为:bufdw10,7,-2,40,20,1,3,10019datasegmentparabufdw-1,30000,35000,36000,37000,20000,10000,-2dataendsss_segsegmentstackdw100
7、dup(0)ss_segendscodesegmentparaassumecs:code,ds:data,ss:ss_segmainprocfarmovax,datamovds,axmovbx,0movcx,8main1:pushbuf[bx]incbxincbxloopmain1;8个数依次入堆栈leabx,bufmovcx,8main2:pop[bx]incbxincbxloopmain2;8个数依次出栈movax,4c00hint21hmainendpcodeendsend