单片机原理及应用技术苏家建曹柏荣汪志锋课后习题参考答案 下载本文

单片机原理及应用技术 苏家建

课后习题参考答案

第三章MCS-51指令系统

3-1 MCS-51指令系统有哪几种寻址方式?按功能分类有哪几种指令?

3-2 设A=0FH,R0=30H,片内RAM的(30H)=0AH, (31H)=0BH, (32H)=0CH,下列程序段运行后的结果? MOV A,@R0 ;A=0AH MOV @R0,32H ;(30H)=0CH MOV 32H,A ;(32H)=0AH MOV R0,#31H ;R0=31H MOV A,@R0;A=(31H)=0BH 3-3 (1)R0的内容传送到R1 MOV A,R0 MOV R1,A (2)内部RAM 20H单元的内容传送到A MOV A,20H (3)外部RAM 30H单元的内容传送到R0 MOV R1,#30H MOVX A,@R1 MOV R0,A (4) 外部RAM 30H单元的内容传送到内部RAM 20H单元 MOV R1,#30H MOVX A,@R1 MOV 20H,A (5) 外部RAM 1000H单元的内容传送到内部RAM 20H单元 MOV DPTR,#1000H MOVX A,@DPTR MOV 20H,A (6)程序存储器ROM 2000H单元的内容传送到R1 MOV DPTR,#2000H CLR A MOVC A,@A+DPTR MOV R1,A

(7) RAM 2000H单元的内容传送到内部RAM 20H单元

MOV DPTR,#2000H MOVX A,@DPTR MOV 20H,A

(8) RAM 2000H单元的内容传送到外部RAM 30H单元

MOV DPTR,#2000H MOVX A,@DPTR MOV R0,#30H MOVX @R0,A

(9) RAM 2000H单元的内容传送到外部RAM 1000H单元

MOV DPTR,#2000H MOVX A,@DPTR MOV DPTR,#1000H MOVX @DPTR,A

3-4 设内部RAM 30H=5AH,5AH=40H,40H=00H, P1=7FH, 下面程序执行后的结果如何? MOV R0,#30H ;R0=30H MOV A,@R0 ;A=(30H)=5AH MOV R1,A ;R1=5AH MOV @R1,P1; (5AH)=7FH MOV A,P1 ;A=7FH MOV 40H,#20H ;(40H)=20H MOV 30H,40H ;(30H)=00H 3-5 编程,将内部RAM 20H-2FH共16个连续单元清零 ORG 0100H MOV R0,#20H MOV R2,#16 LOOP: MOV @R0,#00H INC R0 DJNZ R2,LOOP END 3-6编程,求出内部RAM 20H单元中的数据含“1”的个数,并将结果存入21H单元中。 ORG 0100H MOV 21H,#0 MOV R2,#8 MOV A,20H CLR C LOOP: RLC A JC COUNT DJNZ R2, LOOP SJMP STOP COUNT: INC 21H DJNZ R2,LOOP STOP:SJMP $ END 3-7编程,找出内部RAM 30H-50H单元中出现FFH的次数,并将结果存入51H单元中。

ORG 0100H MOV 51H,#0 MOV R0,#30H MOV R2,#20H LOOP:MOV A,@R0 CJNE A,#0FFH,AGAIN INC 51H AGAIN:INC R0 DJNZ R2,LOOP

SJMP $

END

3-8编程,计算?2i,并将结果存入内部的30H单元

10i?0ORG 0100H MOV 30H,#0

MOV 31H,#0 ; i的初值 MOV R0,#30H MOV R2,#11 MOV A,31H LOOP:INC 31H

ADD A,@R0 MOV @R0,A MOV A,31H RL A DJNZ R2,LOOP SJMP $ END 3-9 已知片内RAM(30H)=38H,(38H)=40H,(40H)=48H,(48H)=90H.说明下列指令源操作数的寻址方式,及指令执行的结果 MOV A,40H ;A=48H 直接寻址 MOV R0,A ;R0=48H 寄存器寻址 MOV P1,#0F0H ;P1=0F0H直接寻址 MOV @R0,30H ;(48H)=38H 寄存器间接寻址 MOV DPTR,#3848H ;DPTR=3848H 直接寻址 MOV 40H,38H ;(40H)=(38H)=40H 直接寻址 MOV R0,30H ;R0=(30H)=38H 寄存器寻址 MOV P0,R0 ;P0=38H 直接寻址 MOV 18H,#30H ; (18H)=30H 直接寻址 MOV A,@R0 ;A=(38H)=40H 直接寻址 MOV P2,P1 ;P2=0F0H直接寻址 3-10设R0=32H,A=48H,片内RAM (32H)=80H,(40H)=08H.求指令运行的结果 MOV A,@R0 ;A=(32H)=80H MOV @R0,40H ; (32H)=(40H)=08H MOV 40H,A ; (40H)=80H MOV R0,#35H ; R0= 35H

3-11设A=83H,R0=17H,片内RAM (17H)=34H, 求指令运行的结果

ANL A,#17H ;A=03H ORL A,17H ; (17H)=(37H

XRL A ,@R0 ; A=37H CPL A ;A=C8H

3-12编程实现片内RAM 20H-2FH与30H-3FH中数据的对换 ORG 0100H MOV R0,#20H MOV R1,#40H MOV R2,#0FH

LOOP: MOV A,@R0 MOV @R1,A INC R0 INC R1 DJNZ R2,LOOP MOV R0,#30H MOV R1,#20H MOV R2,#0FH LOOP1: MOV A,@R0 MOV @R1,A INC R0 INC R1 DJNZ R2,LOOP1 MOV R0,#30H MOV R1,#40H MOV R2,#0FH LOOP1: MOV A,@R1 MOV @R0,A INC R0 INC R1 DJNZ R2,LOOP1 SJMP $ END 3-13 A=34H,(30H)=4FH,ADD A,30H执行后的结果 A=83H,PSW=41H 3-14 SP=25H,PC=2345H,(24H)=12H,(25H)=34H,(26)=56H,执行RET后SP=?PC=? SP=23H,PC=3412H 3-15 SP=25H,PC=2345H,标号LABEL所在的地址3456H,执行LCALL LABEL后SP=?PC=?,堆栈中的数据有何变化? SP=27H (26H)=48H (27H)=23H PC=3456H