LAB 1: Intel 8051 CPU PROGRAMMING DATA TRANSFER INSTRUCTIONS OBJECTIVES At the end of the laboratory works, you should be able to write simple assembly language programs for the Intel 8051 CPU using data transfer instructions and execute the programs on the Intel 8051 trainer board. INTRODUCTION The Intel 8051 Central Processing Unit has 8-bit data bus and a 16-bit address bus which is capable of accessing a linear address space of 64K Byte. The Intel 8051 microcontroller/microprocessor consists of two types of internal memory; 4K ROM and 128 RAM. The Intel 8051 Trainer Board consists of 256K External ROM and 256K External RAM. The start address for ROM is 0000H and starting address for RAM is 2000H. User programs are written into the External ROM. This memory starts at address 0000H up to 1FFFH. Therefore, user programs should be started at address 0000H. In order to write assembly language programs for the Intel 8051 CPU, it is important to understand the programming model of the CPU, or also known as the register set. 7 0 A B R0 R1 R2 R3 R4 R5 R6 R7 7 0 PSW SP 15 8 7 0 DPH DPL DPTR PC Figure 1 68000 Programming model The Intel 8051 CPU have Accumulator A and B, 8 data registers, R0 to R7, Program Status Word (PSW), status register (SR), Program Counter and Data Pointer as shown in Figure 1. All registers are 8 bit except for the Program Counter and Data Pointer are 16 bit in length. The data registers are used to store information (data) within the Intel 8051 CPU itself. Accumulator A is used for all Arithmetic and
logic instructions. There are three types of data transfer instructions provided by Intel 8051 microprocessor: a) MOV, MOVC, MOVX c) XCH and XCHD b) PUSH and POP Data transfer instructions involve instructions such as MOV, MOVC, MOVX to copy or move data between the various locations. EQUIPMENTS 1. A Personal computer installed with the MCU 8051 IDE Editor/Assembler/Simulator 2. Intel 8051 Trainer Board. PROCEDURE All the programs in the exercises have to be written and assembled using the MCU8051IDE Assemble/simulator. To observe the results, the programs have to be compiled and executed in the Simulator. The contents of the affected registers and memory locations have to be examined through single stepping or breakpoints setting. EXERCISES 1. Analyze this program. Show and discuss the output of each instruction. MOV 40H, #50H MOV 50H, #40H MOV R0, #30H MOV 30H, 40H MOV R1, #40H 2. Analyze this program. Show and discuss the output of the program. SETB PSW.4 MOV R3, #30H MOV R4, #40H MOV R5, #50H SETB PSW.3
MOV R0, #30H MOV R1, #40H MOV R2, #50H 3. Write the instructions that will load the following data into the respective registers of Bank 2. Show and discuss the output obtained. R0 = 29H R1 = 24H R6 = ABH R7 = F2H 4. Write the instructions that will load the following data into the respective registers of Bank 0 by using direct addressing mode. Show and discuss the output obtained. R5 = ADH R4 = AFH R3 = AAH R2 = 03H 5. Write the instructions to add 2FH and 13H. Compare the results obtained from the program and results calculated manually. Show and discuss the status of the CY, AC and P flag after the addition. 6. Write the instructions to add F0H and 15H. Compare the results obtained from the program and results calculated manually. Show and discuss the status of the CY, AC and P flag after the addition.
7. Show and discuss the stack and stack pointer for the following program. Assume the default stack area. MOV R6, #38H MOV R1, #36H MOV R4, #08H MOV R0, #06H MOV R2, #04H PUSH 6 PUSH 1 PUSH 4 PUSH 0 PUSH 2 8. Write the program shown in question 7 with the 1 st data to be pushed into the stack at location 50H. Show and discuss the stack and stack pointer for the program. 9. Load the contents of the stack in question 7 back into a CPU registers as follows: 04H into R1 06H into R2 08H into R3 Show the output and discuss the value of SP at the end of the program.
10. Load the contents of the stack in question 8 back into a CPU registers as follows: 04H into R0 06H into R5 08H into R7 Show the output and discuss the value of SP at the end of the program. 11. Analyze this program. Show and discuss the output of each instruction. Discuss the contents of DPH and DPL of the DPTR. MOV A,#79H MOV DPTR,#1000H MOVX @DPTR,A 12. Write a program that will load a value of 77H into accumulator and 1006H into DPTR. Show and discuss the output of each instruction. Discuss the contents of DPH and DPL of the DPTR. END OF LAB 1