SECTION V - REGISTER INDIRECT ADDRESSING MODE AND ITS ADVANTAGES IN 8051

SECTION V - REGISTER INDIRECT ADDRESSING MODE AND ITS ADVANTAGES IN 8051

The main  register indirect addressing mode makes accessing data dynamic rather than static. The static data accessing is in direct addressing mode. When using direct addressing we have to repeat the instructions numerous times. Instead of repeating the instructions we can create a loop with the instructions as demonstrated in previous example of Section IV. Creating a loop is the most efficient way of programming in 8051 and is possible only because of register indirect addressing mode. Looping is not possible in direct addressing mode. This is the main difference between the direct and register indirect addressing modes.

Example # 1:

Lets write a program to clear 16 RAM locations starting at RAM address 50H

CLR A;Clear accumulator A=0
MOV R1, #50H;Load pointer with value 50H
MOV R6, #16;Load counter, R6=16, 10H in hex
AGAIN: MOV @R1, A;Clear RAM location R1 points to
INC R1;Increment R1 pointer
DJNZ R6, AGAIN;Decrement R6 and jump to AGAIN loop until counter zero

Example # 2:

Lets write a program to copy a block of 20 bytes of data from RAM locations starting at 45H to RAM locations 70H.

MOV R0, #45HLoad source pointer R0=45H
MOV R1, #70H;Load destnation pointer R1=70H
MOV R2, #20;Load counter for 20 bytes od data to be copied
BACK: MOV A, @R0;Get byte from the source pointer ,RAM location pointed by R0
MOV @R1, A;Copy byte to the destination, RAM location pointed by R1
INC R0;Increment source pointer
INC R1;Increment destination pointer
DJNZ R2,BACK;Keep doinf it repeatedly for all 20 bytes

Limitations of Register Indirect Addressing Mode in the 8051:

The R0 and R1 are the only registers that can be used for pointers in register indirect addressing mode. R0 and R1 are 8 bits wide only. The limitations to accessing any information in the internal RAM memory of 30H to 7FH or special function registers only. When accessing externally connected RAM or on-chip ROM, we need a 16 bit pointer. In this case DPTR is used.

More From Iamtechnical.com

Advertisement: