《单片机习题参考答案.docx》由会员分享,可在线阅读,更多相关《单片机习题参考答案.docx(20页珍藏版)》请在第壹文秘上搜索。
1、单片机习题参考答案第四章P976,7,9,10,12,16,17,18,19,23,27,28,296 .在80051片内RAM中,已知(30H)=38H,(38H)=40H,(40H)=48H,(48H)=90H,请分析下段程序中各指令的作用,并翻译成相应的机器码;说明源操作数的寻址方式及顺序执行每条指令后的结果。机器码(三)指令结果源操作数的寻址方式E540MOVA,40H;A=(40H)=48H直接寻址F8MOVR0,A;R0=48H寄存器寻址7590F0MOVP1,#OFOH;P1=OFOH立即寻址A630MOVR0,30H;(48H)=38H直接寻址901246MOVDPTR,#12
2、46H;DPTR=1246H立即寻址853840MOV40H,38H;(40H)=40H直接寻址A830MOVR0,30H;R0=38H直接寻址8890MOV90H,RO;(90H)=38H寄存器寻址754830MOV4H,#30H;(48H)=30H立即寻址E6MOVA,Ro;A=40H寄存器间接寻址8590A0MOVP2,P1;P2=P1=38H直接寻址7 .试说明下列指令的作用,并将其翻译成机器码,执行最后一条指令对PSW有何影响?A的终值为多少?机器码(三)指令结果7872MOVR0,#72H;R0=72HE8MOVA,RO;A=72H,P=O2448ADDA,#4BH;A=BDH,C
3、Y=O,0V=1,AC=O,P=O7402MOVA,#02H;A=02H,P=1F5F0MOVByA;B=02H740AMOVA,#OAH;A=OAHfP=O25F0ADDA,B;A=OCH,CY=O,0V=0,AC=O,P=OA4MULAB;A=18H,B=0,CY=O,0V=0,AC=O,P=O74如MOVA,#20H;A=20H,P=1F5F0MOVB,A;B=20H25F0ADDA,B;A=40H,CY=O,0V=0,AC=O,P=19410SUBBA,#10H;A=30H,CY=O,0V=0,AC=O,P=O84DIVAB;A=01H,B=10H,CY=O,0V=0,AC=O,P=1
4、9 .试编程将片外数据存储器60H中的内容传送到片内RAM54H单元中。MOVDPTR,#006OHMOVXA,0DPTRMOV54H,A(MOVP2,#0MOVRO,#60HMOVXA,R0MOV54H,A)10 .试编程将寄存器R7内容传送到Rl中去。MOVA,R7MOVR1,A12 .试说明下段程序中每条指令的作用,并分析当执行完指令后,Ro中的内容是什么?MOVRO,#0A7H;R0=A7HXCHA,RO;A=A7H,A的内容暂存ROSWAPA;A=7AHXCHA,RO;R0=7AH,A的内容恢复16.试编程将片外RAM中30H和31H单元的内容相乘,结果存放在32H和33H单元中,高
5、位存放在33H单元中。MOVP2.#0MOVDPTR,#30HMOVRO,#30HMOVXA,DPTRMOVXA,R0MOVB,AMOVB,AINCDPTRINCROMOVXA,0DPTRMOVXA,R0MULABMULABINCDPTRINCROMOVXQPTR,AMOVX9R0,AINCDPTRINCROMOVA,BMOVMOVXA,B龈),A17.试用三种方法将累加器A中无符号数乘2。(1) CLRCRLCA(2) MOVR0,AADDA,RO或ADDA,ACC(3) MOVB,#2MULABMOVXQPTR,A18 .请分析依次执行下面指令的结果:MOV30H,#0MH;(30H)=A
6、4HMOVA,#0D6H;A=D6H,P=1MOVR0,#30H;R0=30HMOVR2,#47H;R2=47HANLA,R2;A=46H,P=1ORLA,RO;A=E6H,P=1SWAPA;A=6EH,P=1CPLA;A=91H,P=1XRLA,#OFFH;A=6EH,P=1ORL30H,A;(30H)=EEH19 .求执行下列指令后,累加器A及PSW中进位位CY、奇偶位P和溢出位OV的值。(1)当A=5BH时;ADDA1#8CH01011011+)I(XX)IIoO11100111结果:A=E7H,CY=O,0V=0,P=0,AC=I(2)当A=5BH时;ANLA1#7AH01011011
7、2OlllIoIO01011010结果:A=5AH,P=O(3)当A=5BH时;XRLA1#7FH01011011)0111111100100100结果:A=24H,P=O(4)当A=5BH,CY=I时;SUBBA1#0E8H01011011或将减法转换成补码加法0101101111101000-E8H的补码00011000一)1-1的补码+)1111111101110010101110010结果:A=72H.CY=1.OV=O1P=O1AC=O23.执行下述程序后,SP=? A=? B=?码。地址(H)机器码(H)ORG200H0200758140MOVSP1 #40H02037430MOV
8、A1 #30H0205120250LCALL250H02082410ADDA1 #10H020AF5F0MOVB1 A020C80FE L1:SJMPL1ORG0250H025090020AMOVDPTRf #20AH;02530082PUSHDPL0255C083PUSHDPH025722RET解释每一条指令的作用,并将其翻译成机器;SP=40H;A=30H;调用250H开始的子程序SP=42H,;(42H)=02H, (41H)=08H;此句没有执行;B=30HDPTR=020AH;DPL 进栈,SP=43H, (43H)=0AH;DPH 进栈,SP=44H, (44H)=02H;返回,此
9、处是利用RET将栈顶内容弹出 PC=020AH, SP=42H27 .试编一程序将外部数据存储器210OH单元中的高4位置m1m,其余位清0”。MOVDPTR,#21OOHMOVXA,DPTRANLA1#0F0HMOVA,#0F0HORLA,#0F0HMOVX0DPTR,A28 .试编程将内部数据存储器40H单元的第0位和第7位置1,其余位变反。MOVA,40HCPLASETB(或ORLA1#81H)SETBMOV40H,A29 .请用位操作指令,求下面逻辑方程:(I)Pl.7=ACC.0A(ROVP2.1)vP32MOVC,ORLC1ANLC1ORLC1/MOV,C(2)PSW.5=P1.3
10、ACC.2vB.5P11MOVC1ANLC1ORLC1ANLC,/MOV,C(3)P2.3=PL5aBAvACC.7APl.0MOVC,ANLC,/ORLC,/ANLC1MOV,C第五章P1121,3,6,7,11,201.编程将片内40H60H单元中内容送到以3000H为首的片外RAM存储区中方法1:MOVR0,#40HMOVDPTR,#3000HMOVR2f#21HLP:MOVA10R0MOVXQPTR,AINCROINCDPTRDJNZIR2,LOOP方法2:MOVR0,#40HMOVDPTR,#3000HMOVR2,#0LOOP:MOVA,R0MOVX0DPTR,AINCROINCDP
11、TRINCR2CJNEIR2f#21H.LOOP方法3:MOVR0,#40HMOVDPTR,#3000HLOOP:MOVA,叙0MOVXDPTR,AINCROINCDPTRCJNEIR0,#61H,LOOP补充:编程将ROi中3000H-3020H单元的内容送片内RAM40H60H单元中去MOVR0,*(40HMOVDPTR1#3000HMOVR2,*t21HLOOP:CLRAMOVCA,A+DPTRMOVR0,AINCROINCDPTRDJNZR2,L.OOP3.编程计算片内RAM区50H57H8个单元中数的算术平均值,结果存放在5AH中。解:ORG2000HMOVRO1#50HCLRAMO
12、VR2,ALP:ADDA1eR0JNCDOWNINCR2DOWN:INCROCJNERO,#58H,LOOPMOVR7,#3SHIFT:XCHA,R2CLRCRRCAXCHA,R2RRCADJNZR7,SHIFTMOV5AH,A6.设有100个有符号数,连续存放在以200OH为首地址的片外RAM存储区中,试编程统计其中正数、负数、零的个数。方法1:CLRAMOVR5,A;存零的个数MOVR6,A;存负数的个数MOVR7,A;存正数的个数MOVR2,#100MOVDPTR,#2000HLOOP:MOVXA1WPTRJNZNZEROINCR5SJMPDOWNNZERO:JNB,PLUSINCR6SJMPDOWNPLUS:INCR7DOWN:INCDPTRDJNZIR2,LOOP方法2:ICLRAMOVR5,A;存零的个数MOVR6,A;存负数的个数MOVR7,A;存正数的个数MOVR2,#100MOV