Uploaded by Subhasish Panda

8051

advertisement
LAB 1
ADDRESSING MODES
OBJECTIVES:
To Study the different addressing modes: Immediate, Register, Direct, Register Indirect
and Indexed.
REFERENCE:
¾ Mazidi and McKinlay, “The 8051 Microcontroller and Embedded Systems,” Chapter 4.
Tools:
¾ Keil 8051 assembler, simulator and Trainer board
ACTIVITY 1
Write a program to illustrate (i) Immediate, (ii) Register, and (iii) Direct addressing modes.
For the immediate data must be preceded by the pound sign “#”. Load immediate value 52H to
A, 26H to R0, 32 to R2 and 1234H to DPTR. (DPTR is 16 bit, DPH is upper 8-bit and DPL is
lower 8-bit.
For Register mode, use Register to hold the data to be manipulated. Copy contents of R0 into A,
Add contents of R2 to A and save the accumulator value in R6.Move DPH and DPL value to R3
and R4 respectively.
Note: 8051 Registers-A,B,R0,R1,R2,R3,R4,R5,R6,R7(8-bit each).Data transfer between Rn
registers are not allowed. Register size must be matched to data transfer.
Using the simulator, single-step through the program and examine the data transfer and registers.
ACTIVITY 2
Write a program to copy 44H to RAM location 40H to 43H (a) Direct addressing mode
and (b) Register Indirect addressing mode(with loop)(Additional Instr.-INC,DJNZ)
Note: Direct addressing mode used to access RAM locations 30 – 7FH in 8051.
E.g.: MOV R0,40H
MOV 56H, A
; save the content of 40H in R0.
; save the content of accumulator in 56H
Special Function registers (SFR) can also be accessed by 80H to FFH. (List of all SFRs in book)
MOV 0E0H,#55H ; is same as
MOV A, #55H
; copy 55 H to Accumulator.(Address of A is 0E0H)
In Register Indirect addressing modes, register is used as a pointer. Only R0 and R1 can be used
for this purpose and they must be preceded by @ sign.
E.g: MOV A,@R0 ; move the contents of RAM whose address is held by R0 into A
MOV @R1, B ; move the contents of B into RAM whose address is held by R1
LAB 1
LAB 1
WORKSHEET
ACTIVITY 3
Assume that the word “NIT” is burned into ROM locations starting at 200H. And that the
program is burned into ROM locations starting at 0. Write a program using Indexed
addressing modes and store the N, I, T in R1,R2 & R3 respectively.
Indexed addressing mode is widely used in accessing data elements of look-up table entries
located in the program ROM
e.g.: MOVC A,@A+DPTR ; MOVC:C stands for Code
Note: External memory space is accessed by the MOVX instruction
1. Explain the difference between the following two instructions:
MOVC A,@A+DPTR
MOV A,@R0
2. Circle the invalid instructions.
MOV A,@R1
MOV A,@R2
MOVC A,@R0+DPTR
MOV @R3,A
3. Explain the difference between the following two instructions:
MOV A,40H
MOV A,#40H
4. Explain the difference between the following two instructions:
MOV 40H,A
MOV 40H,#0A
5. Give the RAM address for the following registers.
A=
B=
R0=
R2=
PSW=
SP=
DPL=
DPH=
LAB 1
Download