资源描述:
《第四章余锡存习题与思考题参考答案》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、第四章习题与思考题参考答案1、若有两个符号数X,Y分别存放在内部存储器50H、51H单元中,试编写一个程序实现X*10+Y,结果存入52H、53H中。1ORG00H000078502MOVR0,#50H0002E63MOVA,@R0000375F00A4MOVB,#0AH0006A45MULAB0007086INCR00008267ADDA,@R00009088INCR0000AA6F09MOV@R0,B000C0810INCR0000DF611MOV@R0,A12END2、在以3000H为首地址的外部RAM中,存放了14个以ASCII码表示的0~9的数,试编写程序将它们转换成BC
2、D码,并以压缩BCD形式存放在以2000H为首地址的外部RAM中。1ORG00H00009030002MOVDPTR,#3000H;原始数据首地址000378073MOVR0,#07;循环次数000579304MOVR1,#30H;转换结果暂存区指针0007E05CH1:MOVXA,@DPTR0008550F6ANLA,#00001111B000AC47SWAPA000BF5F08MOVB,A000DA39INCDPTR000EE010MOVXA,@DPTR000F550F11ANLA,#00001111B001145F012ORLA,B0013F713MOV@R1,A001409
3、14INCR10015A315INCDPTR0016D8EF16DJNZR0,CH1001890200017MOVDPTR,#2000H;转换结果存储区001B7A0718MOVR2,#07H;结果个数001D793019MOVR1,#30H001FE720CH2:MOVA,@R1;3、采样的5个值分别存放在R0、R1、R2、R3、R4中,求出它们的中间值,并存放在R2中。1ORG00H>000078052MOVR0,#5000279063MOVR1,#600047A074MOVR2,#700067B085MOVR3,#800087C096MOVR4,#9000AE47CLRA;0
4、00BC38CLRC;000CE89MOVA,R0;000D2910ADDA,R1;000E2A11ADDA,R2;000F2B12ADDA,R300102C13ADDA,R4001175F00514MOVB,#500148415DIVAB0015FA16MOVR2,A001617END18END4、以BUF1为起始地址的外部数据存储区中存放着16个单字节的无符号数,求其平均值并送入R2中。1ORG00H2BUF1EQU#1000H00009010003MOVDPTRBUF10003AA004MOVR2,0000578165MOVR0,#16H0007E06SUM:MOVXA,@D
5、PTR00082A7ADDA,R20009FA8MOVR2,A000AA39INCDPTR000BD8FA10DJNZR0,SUM000D75F01011MOVB,#10H00108412DIVAB0011FA13MOVR2,A14END5、试编写程序,将内部RAM单元中DATA1开始的20个单字节数依次与DATA2单元为起始地址的20个单字节数据进行交换。>1DATA1EQU#30H2DATA2EQU#50H3LENEQU#164ORG0H000078305MOVR0,DATA1000279506MOVR1,DATA200047A107MOVR2,LEN0006E68EXC:MO
6、VA,@R00007C79XCHA,@R10008F610MOV@R0,A00090811INCR0000A0912INCR1000BDAF913DJNZR2,EXC14END6、某场歌手赛,共有10个评委,试编写一程序,输入10个评分,去掉最高分和最低分,求平均分(均为BCD码)。ORG0HNEQU#5BLOCKEQU#30HISELSORT:MOVR7,NDECR7MOVR1,BLOCKISST1:MOVR0,BLOCKMOVA,R7MOVR6,AMOVA,@R0MOVB,AISST2:INCR1MOVA,@R1CLRCSUBBA,BJCISST3MOVA,@R1MOVR2,A
7、MOVB,@R1ISST3:DJNZR6,ISST2MOVA,BXCHA,@R1MOVB,R2MOV@R1,BMOV@R1,ADJNZR7,ISST1MOVR0,BLOCKMOV@R0,#0;去掉最低分MOVA,BLOCKADDA,#9MOVR0,AMOV@R0,#0;去掉最高分AD:MOVR0,BLOCKINCROMOVR1,#8CLRACLRCMOVB,#0ADL:ADDA,@R0DAAMOVR2,AADDCA,#0MOVB,AMOVA,R2DJNZR1,ADLM