Back to the 2025 paper

Module 3: Instruction Set and Programming

20257m

Explain Different Addressing Modes of 8051 Microcontroller.

Worked SolutionAI Assisted

Addressing Modes of 8051 Microcontroller

Definition

An addressing mode specifies how an 8051 instruction identifies the operand or obtains the data on which the instruction operates.

The 8051 supports several addressing modes that provide flexibility for handling constants, registers, memory locations, bits, lookup tables, and branch destinations.

1. Immediate Addressing Mode

In immediate addressing, the constant data is specified directly in the instruction. The # symbol is used before the immediate value.

Example:

MOV A, #55H

Operation: The value 55H is loaded directly into the accumulator A.

Key point: The # symbol indicates immediate data.


2. Register Addressing Mode

In register addressing, the operand is present in one of the registers R0 to R7 of the currently selected register bank.

Example:

MOV A, R3

Operation: The contents of R3 are copied into the accumulator A.

Key point: The register itself contains the operand, not its address.


3. Direct Addressing Mode

In direct addressing, the instruction contains the 8-bit address of the operand directly. It can be used to access internal RAM locations and Special Function Registers (SFRs).

Example 1:

MOV A, 30H

This copies the contents of internal RAM location 30H into A.

Example 2:

MOV A, P1

This accesses the Port 1 SFR directly.


4. Register Indirect Addressing Mode

In register indirect addressing, a register contains the address of the operand rather than the operand itself.

For internal RAM, R0 or R1 can be used as indirect address registers.

Example:

MOV A, @R0

If R0 = 40H, the instruction loads A with the data stored at RAM location 40H.

The @ symbol indicates indirect addressing.

Key point: The register holds the address of the data.


5. Indexed Addressing Mode

Indexed addressing is mainly used for accessing lookup tables stored in program memory.

The effective address is obtained by adding the contents of the accumulator to a base address held in DPTR or the Program Counter.

Example:

MOVC A, @A+DPTR

Operation:

Effective Address=DPTR+A \text{Effective Address} = \text{DPTR} + \text{A}

The byte stored at this code-memory address is then loaded into A.

Application: Lookup tables, code conversion tables, seven-segment codes, etc.


6. Relative Addressing Mode

Relative addressing is used for short conditional and unconditional branches. An 8-bit signed displacement is added to the address of the instruction following the branch instruction.

Examples:

SJMP LABEL
JZ LABEL
JNZ LABEL

The typical relative range is:

−128 bytes  to  +127 bytes -128 \text{ bytes} \; \text{to} \; +127 \text{ bytes}

from the address of the instruction following the branch.

Key point: Relative addressing is useful for nearby branches and loops.


7. Absolute Addressing Mode

Absolute addressing is used by the AJMP and ACALL instructions.

These instructions contain an 11-bit address field. The destination is formed within the same 2 KB page of program memory.

Example:

AJMP LABEL

Key point: AJMP/ACALL can transfer control within the current 2 KB program-memory page.


8. Long Addressing Mode

Long addressing is used by LJMP and LCALL. These instructions contain a complete 16-bit destination address.

Example:

LJMP 2500H

A 16-bit address allows access to the complete 64 KB program-memory address space of the standard 8051 architecture.

Key point: Long addressing provides a much larger program-memory range than absolute addressing.


9. Bit Addressing Mode

Bit addressing allows an instruction to access one individual bit in the bit-addressable internal RAM area or in bit-addressable SFRs.

Examples:

SETB P1.0
CLR C
JB P3.2, LABEL

For example, SETB P1.0 sets bit 0 of Port 1 to 1.

Application: Bit control, flags, digital I/O operations, and decision making.


Summary Table

Addressing Mode Main Purpose Example
Immediate Use constant data MOV A, #55H
Register Use R0–R7 directly MOV A, R3
Direct Access RAM/SFR directly MOV A, 30H
Register Indirect Access data through an address in a register MOV A, @R0
Indexed Access lookup tables in program memory MOVC A, @A+DPTR
Relative Short branch operations SJMP LABEL
Absolute Branch/call within a 2 KB page AJMP LABEL
Long Branch/call anywhere in 64 KB program memory LJMP 2500H
Bit Access individual bits SETB P1.0

Conclusion

The 8051 addressing modes provide efficient ways to access immediate data, registers, RAM, SFRs, individual bits, lookup tables, and program-memory locations. The major modes are immediate, register, direct, register indirect, indexed, relative, absolute, long, and bit addressing. Understanding these modes is essential for writing efficient 8051 assembly programs.

Similar questions

Student FinanceWeb Platform

Pocketly — Personal Finance for Students

Keep your hostel and college expenses under control. Track accounts, log spending in seconds, and stay within your monthly budget.