SECTION II - ACCESSIBILITY OF MEMORY BY USING ADDRESSING MODES IN 8051

SECTION II - ACCESSIBILITY OF MEMORY BY USING ADDRESSING MODES IN 8051

The register direct or indirect addressing modes can be used to access data stored in RAM or registers of the 8051 microcontroller.

  • Direct Addressing Mode:

​RAM in the 8051 has 128 bytes and has addresses 00 to 7FH. RAM locations 00 - 1FH are assigned to the register banks and stack. RAM locations 20 - 2FH are set aside as bit-addressable space to save single bit data. RAM locations 30 - 7FH are available as a place to save byte sized data.

The entire 128 bytes of RAM can be accessed using direct addressing mode. The direct address is most often used to access RAM locations 30 - 7FH. There is no other or alternate name for other RAM locations except the register banks locations are accessed by the register names of R0 - R7, but there is no such name for other RAM locations. The data is in a RAM memory location who address is known, and this address is given as a part of the instruction, in the case of direct address mode. Contrast this with the immediate addressing mode in which the operand itself is provided with the instruction. The "#" sign distinguishes between the two modes.

MOV R0, 10H;Save the contents of RAM location 40H in R0
MOV 55H, A;Save the contents of accumulator ACC in RAM location 55H
MOV R3,7FH;Save the contents of RAM location 7FH to R3

RAM locations 0 to 7H are allocated to Bank 0 registers R0 - R7. These registers can be accessed in 2 ways:

MOV A, 3;is same as the instruction given below
MOV A, R3;Copy value of R3 into accumulator A
MOV A, 6;is same as the instruction given below
MOV A, R6;Copy value of R3 into accumulator A
MOV A, 2;is same as the instruction given below
MOV A, R2;Copy value of R2 into accumulator A
MOV A, 0;is same as the instruction given below
MOV A, R0;Copy value of R0 into accumulator A

The above example can make understand the importance of "#" sign in 8051 instructions.

MOV R3, #2; R3 = 2
MOV A, 3;Copy R3 to accumulator A i.e A=R2=02
MOV B, 3;Copy R3 to accumulator B i.e B=R2=02
MOV 6, 2;Copy R2 to R6, This instruction is invalid, since "MOV R6, R2 is invalid

It is resier to use the names R0 - R7 than their memory addresses, RAM locations 30H to 7FH cannot be accessed in any other way then their addresses, since they have no names.

 

More From Iamtechnical.com

Advertisement: