Types of Addressing Modes for 8086 Microprocessor

Addressing modes for 8086 Microprocessor

The 8086 microprocessor, which is the base of the widely used x86 architecture, provides different ways to access data and instructions. These methods are called addressing modes. They are very important because they make the processor flexible and efficient, and they are essential for assembly language programming.

Addressing modes tell the CPU how to find the data needed to perform an operation. The data (called an operand) can be stored directly in the instruction, in a register, or in memory. To find the exact memory location of the data, the processor calculates something called the Effective Address (EA). This is usually done by adding values from a base register (BX or BP), an index register (SI or DI), and sometimes a constant value (displacement) given in the instruction.

Mastery of these modes is essential for writing efficient and compact code, as they directly impact a program’s speed, size, and capability to handle complex data structures.

The addressing modes of the 8086 can be broadly categorised into those for data transfer and those for program transfer. They provide a versatile toolkit for the programmer, ranging from simple constant loading to complex array manipulations.

Understanding these modes is not just an academic exercise but also a practical necessity for low-level programming and for appreciating the design philosophy that has powered personal computing for decades. This article will explain the specifics of these addressing modes, exploring their types, advantages, and disadvantages and concluding with their lasting significance in computer architecture.

What is an Addressing Mode?

An addressing mode is a specific method used by a microprocessor’s instruction set to calculate the physical address of an operand (the data on which an operation is to be performed) or the target address of a branch instruction .

In essence, it is the rule that the CPU follows to find the data it needs. For the 8086, the calculation of an operand’s memory address relies on a segmented memory model. The 20-bit physical address is generated by combining the content of a segment register (like CS, DS, ES, or SS), shifted left by four bits, with a 16-bit offset, often referred to as the Effective Address (EA).

The EA itself can be the sum of up to three components: a base register (BX or BP), an index register (SI or DI), and an optional 8- or 16-bit displacement value provided directly in the instruction . The specific combination of these components defines the addressing mode being used, providing the programmer with a powerful and flexible way to access memory.

Types of Addressing Modes

The 8086 microprocessor supports several addressing modes, which define how operands (data) are accessed during instruction execution. These modes provide flexibility in handling data stored in registers, memory, or embedded within instructions.

1. Immediate Addressing Mode

In this mode, the operand (data) is directly specified within the instruction itself. The CPU does not need to fetch the data from memory or registers—it is already available as part of the instruction.

For example:


MOV AX, 1234H

Here, 1234H is the immediate data, and it is directly loaded into the AX register.

2. Register Addressing Mode

In register addressing mode, the operand is stored in a register. The instruction specifies the register that contains the data.

For example:
MOV AX, BX
Here, the content of register BX is copied into AX.

3. Direct Addressing Mode

In this mode, the instruction contains the direct memory address of the operand. The CPU accesses that specific memory location to fetch or store data.

For example:
MOV AX, [1234H]
Here, the data stored at memory address 1234H is moved into AX.

4. Register Indirect Addressing Mode

The memory address of the operand is stored in a register (like BX, SI, DI, or BP). The instruction refers to that register, and the CPU accesses memory using the address inside the register.

For example:
MOV AX, [BX]
Here, BX contains the memory address, and the data at that address is loaded into AX.

5. Based Addressing Mode

This mode uses a base register (BX or BP) to hold the base address of a memory location. The instruction accesses memory using this base address.

For example:
MOV AX, [BX + 10H]
Here, the effective address is calculated as BX + 10H.

6. Indexed Addressing Mode

In indexed addressing mode, an index register (SI or DI) is used to hold the offset address. This is useful for accessing arrays or lists.

For example:
MOV AX, [SI]
Here, SI contains the offset of the data in memory.

7. Based Indexed Addressing Mode

This mode combines a base register (BX or BP) and an index register (SI or DI). The effective address is the sum of both.

For example:
MOV AX, [BX + SI]
Here, the CPU calculates the address by adding BX and SI.

8. Based Indexed with Displacement

This is an extension of the previous mode. It uses a base register, an index register, and a displacement (constant value).

For example:
MOV AX, [BX + SI + 20H]
Here, the effective address is BX + SI + 20H.

9. Relative Addressing Mode

This mode is primarily utilised in branch instructions. The address is determined by adding a displacement to the current instruction pointer (IP).

For example:
JNZ LABEL
The processor jumps to LABEL relative to the current IP.

Addressing Mode Description Example Instruction
Immediate Operand is part of instruction MOV AX, 1234H
Register Operand stored in register MOV AX, BX
Direct Memory address given directly MOV AX, [1234H]
Register Indirect Address stored in register MOV AX, [BX]
Based Base register + displacement MOV AX, [BX + 10H]
Indexed Index register used MOV AX, [SI]
Based Indexed Base + index registers MOV AX, [BX + SI]
Based Indexed + Displacement Base + index + constant MOV AX, [BX + SI + 20H]
Relative Offset added to instruction pointer JNZ LABEL

Advantages of Addressing Modes

The variety of addressing modes in the 8086 microprocessor provides numerous benefits that enhance both programming capability and code efficiency. They are not merely a list of options but a carefully designed set of tools that empower the programmer.

  • Flexibility in Data Handling: Addressing modes provide sophisticated ways to access data. They allow for the easy implementation of pointers (via register indirect mode), array manipulation (via indexed mode), and the management of complex data structures like records and two-dimensional arrays (via based indexed modes). This flexibility simplifies the coding of advanced algorithms and data management techniques.

  • Enhanced Program Control: Addressing modes for branch instructions, such as relative addressing, are crucial for implementing loops, conditional jumps, and subroutine calls. These modes make the code more adaptable and easier to manage, as they often calculate target addresses relative to the current program counter.

  • Efficient Memory Usage and Code Size: These modes enable diverse data access methods, resulting in more compact code. For instance, the immediate mode can initialise a register with a constant without requiring a separate memory access for the data, thus reducing the number of instruction fetches . The use of pointers and indices can also reduce the need to hard-code memory addresses, making the program smaller and more dynamic.

  • Support for Program Relocation: Certain modes, like the PC-relative addressing used in branch instructions, allow a program to be relocated in memory and still execute correctly without modification . This is because target addresses are calculated relative to the current instruction’s position, rather than being absolute memory locations.

  • Simplified Programming for Complex Tasks: The availability of these modes offloads the complex calculations for memory addresses from the programmer to the processor. Accessing an element in a two-dimensional array, for example, becomes a single, clear instruction using a base-indexed mode, rather than a sequence of manual arithmetic operations.

Disadvantages of Addressing Modes

Despite their numerous advantages, the diverse addressing modes of the 8086 also come with certain limitations and complexities that a programmer must navigate.

  • Increased CPU Complexity: Implementing multiple addressing modes requires more complex decoding logic within the processor’s control unit. This added complexity can increase the design difficulty and the number of transistors needed, although for the 8086, this was a calculated trade-off for increased functionality.

  • Variable Instruction Length and Execution Time: Instructions using different addressing modes can have varying lengths (from 1 to several bytes) and require a different number of clock cycles to execute. For instance, an instruction using register mode is very fast, while one using a complex based indexed mode with displacement may be slower because it requires additional calculations and potentially multiple memory accesses to fetch the instruction itself and then the operand . This variability can make precise timing in real-time systems more challenging to predict.

  • Limited Operand Range: In immediate addressing, the size of the constant operand is limited by the instruction format (8 or 16 bits). Similarly, in direct addressing, the 16-bit offset restricts data access to a 64KB segment. To access data outside this segment, programmers must employ more complex segment manipulation techniques, which adds overhead.

  • Potential for Programming Errors: The flexibility of these modes can be a double-edged sword. A programmer must have a deep understanding of which registers are allowed in which modes (e.g., BP defaults to the stack segment, while BX defaults to the data segment) and what the default segment registers are. An incorrect assumption or a mistake, such as using an invalid register combination (e.g., BX and BP together), can lead to accessing the wrong memory location and causing subtle, hard-to-debug errors.

Leave a Reply

Your email address will not be published. Required fields are marked *