Microprocessors and Microcontrollers: Unit III: (b) 8051 Instruction Set and Programming

8051 Addressing Modes

8051 Instruction Set and Programming

The way, using which the data sources or destination addresses are specified in the instruction mnemonic for moving the data, is called 'addressing mode'. This section explains addressing modes used in 8051 with examples.

8051 Addressing Modes

AU : June-08,11, Dec.-07,08,09,ll,13,14, May-13,14,16,17

The way, using which the data sources or destination addresses are specified in the instruction mnemonic for moving the data, is called 'addressing mode'. This section explains addressing modes used in 8051 with examples.

 

1. Register Addressing

The 8051 can access eight "working registers" (R0-R7). Three bit code within the instruction selects one of the eight registers from the selected register bank. The programmer can select a register bank by modifying bits 4 and 3 in the PSW.


Example : Add the contents of register R3 and R4 from bank 2

Step 1 : Select register bank.

MOV PSW, # 00001000B ; select register Bank 2

Step 2 : Add the contents of R3 and R4

MOV A, R3

ADD A, R4

 

2. Direct Byte addressing


Direct addressing can access any on-chip variable or hardware register i.e. on-chip RAM and special function register. The most significant bit of the address decides whether it is a location within on-chip RAM (MSB = 0) or in special function register (MSB = 1).

Example : Add the contents of locations 50H and 51H

MOV A, 50H ; load byte from address 50H into A

ADD A, 51H ; Add the contents of A and the contents at memory location 51H.

 

3. Register Indirect Addressing

In this addressing mode R0 and R1 of each register bank can be used as an index or pointer register. RO and RI point to the contents in the RAM. The instruction with indirect addressing uses the ‘@’ sign.

Indirect addressing accesses data in dynamic manner rather than static manner. Looping is not possible in direct addressing mode. In indirect addressing we can increment the index or pointer register to access successive locations.


R0 and R1 are the only registers that can be used for pointers in register indirect addressing mode.

Example : ADD the contents of memory location addressed by register 1 to the contents of RAM location pointed by register 0.

MOV A, @R0 ; load the contents pointed by R0 in A

ADD A, @R1 ; Add the contents of A and the contents pointed by R1

 

 4. Immediate Addressing

In this addressing mode source operand is a constant rather than a variable. So the constant can be incorporated in the instruction. Sign “#” indicates it is a immediate addressing mode.


Example : Add the constant 52 decimal in accumulator.

MOV A, #52

 

5. Register Specific

Inherent in the instruction, these refer to a specific register such as accumulator or DPTR.

Example :

SWAP A ; Swap nibbles within the Accumulator

 

6. Index

Only program memory can be accessed in the index addressing. Either the DPTR or PC can be used as an index register.


Example : Read data from the program memory.

MOVC A, @A+DPTR ; This instruction adds the unsigned 8-bit and accumulator contents into

; sixteen bit Data pointer, and uses the sum as an address from which

; byte to be moved into accumulator

 

7. Stack Addressing Mode

It is subtype of direct addressing mode in which stack instructions (PUSH and POP) are used. Instruction such as 'PUSH A' is invalid. Here, we have to specify the address of register A. Thus, PUSH OEOH is a valid instruction; it pushes/stores the contents of accumulator on the stack.

Examples :

PUSH 04 ; Push R4 onto stack

PUSH 06 ; Push R6 onto stack

POP 02 ; Pop top of stack into R2

POP 0F0H ; Pop top of stack into register B

Review Questions

1. Classify the addressing modes of 8051 microcontroller. AU : May-17, Marks 2

2. Explain the different addressing modes in 8051 in detail. AU : June-08, Dec, -07, 08, 11 Marks 8

3. What are the addressing modes cf 8051 microcontroller ? AU : Dec.-11, May-13, Marks 2

4. What is register indirect addressing mode of microcontroller 8051 ? Give example. AU : June-11, Marks 2

5. Explain the different addressing modes of8051 microcontroller. AU : May-13,14, Dec.-13, Marks 16

6. What are the addressing modes followed in 8051 Micro controller ? AU : Dec.-14, Marks 2

7. Explain the different addressing modes of 8051 microcontroller. AU : May-16, Marks 8

Microprocessors and Microcontrollers: Unit III: (b) 8051 Instruction Set and Programming : Tag: : 8051 Instruction Set and Programming - 8051 Addressing Modes