CHAPTER # 4 - ADDRESSING MODES IN 8051

CHAPTER # 4 - ADDRESSING MODES IN 8051

Upon Completion of this chapter:

  • Sort out the 5 addressing modes of the 8051 microcontroller
  • Compare the addressing modes of the 8051 microcontroller
  • Code the 8051 Assembly Language instructions using each addressing mode
  • Access RAM using various addressing modes
  • Accessing the Special Function Registers
  • Manipulate the stack using direct addressing mode
  • Code 8051 instructions to manipulate a look-up table 

​There are various ways of addressing the data are called 'Addressing Modes'. The CPU access data in various ways. The data could be in register or in memory. The data can be provided as an immediate value. The 8051 provides a total of five addressing modes.

  1. Immediate Addressing
  2. Register Addressing
  3. Direct Addressing
  4. Register Indirect Addressing
  5. Indexed Addressing

SECTION - I REGISTER AND IMMEDIATE ADDRESSING MODES:

  • Register Addressing Mode:

 Register addressing mode involves the use of registers to hold the data to be manipulated.

MOV A,R1;Copy the contents of R1 into accumulator register A
MOV R3,A;Copy the contents of accumulator A into register R3
ADD A,R4;Add the contents of R4 to contents of accumulator A
ADD, A,R6;Add the contents of R6 to contents of accumulator A
MOV R5,A;Add the contents of accumulator A in R6

The source and the destination registers must match in size. If using 8 bit source, the destination must be also an 8 bit. Using 8 bit source and 16 bit destination will give an error. The instruction "MOV DPTR,A" will give an error, as the source is an 8 bit and the destination is a 16 bit register.

MOV DPTR,#36E4H
MOV R2,DPL
MOV R3,DPH

Data can be moved between the accumulator register and registers R0, R1, R2, R3, R4, R5, R6, R7 or Rn [n=0 to 7]. The movement of data between register to register is not allowed. The instruction "MOV R2,R3" is invalid.

  • Immediate Addressing Mode:

The source operand is constant in this addressing mode. The operand come immediately after the opcode, in immediate addressing modes when the instruction is assembled. The immediate data must be preceded by the pound sign '#'. This addressing mode can be used to load information into any of the registers, including the Data Pointer [DPTR] register.

MOV A,#24H;Load 24H into accumulator register A
MOV R3,#255;Load the decimal value 255 into R3
MOV B,#55H;Load 55H into B register
MOV DPTR,#1234H;Load data pointer DPTR with decimal value 1234

The data pointer 'DPTR' register is a 16 bit register. The DPTR register can also be accessed as two 8 bit registers, DPH and DPL. 'DPH' stands for data pointer high byte and 'DPL' stands for data pointer low byte.

MOV DPTR, #1234H

The above instruction is the same as:

MOV DPL, #34H
MOV DPH, #12H

The maximum value that the data pointer DPTR holds is 65535 or FFFFH. If value loaded above 65535 will give an error.

MOV DPTR, #67000;This is illegal value as 67000 > 65535 [FFFFH]

EQU Directive:

The Equate [EQU] directive is used to access immediate data:

COUNT EQU 20 
......        ...... 
MOV R3, #COUNT;Load R3 register with 20 or R3=20, 20=14H in hex
MOV DPTR, #OUR_DATA;DPTR = 200H
ORG 200H 
DATA: DB "Canada" 

The immediate addressing mode can be used to send data to 8051 ports:

MOV P2, #AAH;This is a valid instruction

 

More From Iamtechnical.com

Advertisement: