Chapter 3 Adressing Modes
Chapter 3 Adressing Modes
Addressing Modes
What Is an Addressing Mode?
For example, if we wanted to add the numbers 1 and 2 and get a result, mathematically we would
likely write this as 1 + 2. In this case, our operator is (+), or the addition, and our operands are the
numbers 1 and 2.
In a microprocessor, the machine needs to be told how to get the operands to perform the operation.
The effective address is a term that describes the address of an operand that is stored in memory.
There are several methods to designate the effective address of those operands or get them directly
from the register. These methods are known as addressing modes.
The 8086 memory addressing modes provide flexible access to memory, allowing you to easily
access variables, arrays, records, pointers, and other complex data types. The key to good
assembly language programming is the proper use of memory addressing modes.
MOV AL, BL
The above two instructions copy the data of BL register to AX and AL.
1
2. Immediate Addressing Mode
In this mode, there are two operands. One is a register and the other is a constant value. The register
comes quickly after the op code.
For example:
The instruction MOV AX, 30H copies hexadecimal value 30H to register AX.
The instructions MOV BX, 255 copies decimal value 255 to register BX.
You cannot use the immediate addressing mode to load immediate value into segment registers. To
move any value into segment registers, first load that value into a general-purpose register then add
this value into segment register.
The register indirect addressing mode uses the offset address which resides in one of these three
registers i.e., BX, SI, DI. The sum of offset address and the DS value shifted by one position
generates a physical address.
For example: MOV AL, [SI]
This instruction will calculate the physical address by shifting DS to the left by one position and
adding it to the offset address residing in SI. The brackets around SI indicates that the SI contain the
offset address of memory location whose data needs to be accessed. If brackets are absent, then the
instruction will copy the contents of SI register to AL. Therefore, brackets are necessary.
2
5. Based Relative Addressing Mode
This addressing mode uses a base register either BX or BP and a displacement value to calculate
physical address.
The effective address is the sum of offset register and displacement value. The default segments for
BX and BP are DS and SS.
In this example, the effective address is BX + 5 and the physical address is DS (shifted left) +
BX+5. The instruction on execution will copy the value of DX to memory location of physical
address= DS (shifted left) +BX+5.
This addressing mode is same as the based relative addressing mode. The only difference is it uses
DI and SI registers instead of BX and BP registers.
The based indexed addressing mode is actually a combination of based relative addressing mode
and indexed relative addressing mode. It uses one base register (BX, BP) and one index register (SI,
DI).
The above instruction can also be written as MOV AX, [SI+BX+20] or MOV AX, [SI] [BX] +20
In this case, the physical address will be DS (Shifted left) + SI + BX + 20. Now, if we replace BX
with BP then the physical address is equal to SS (Shifted left) + SI + BX + 20.
3
8. Data memory addressing modes
In these types of addressing modes, the offset address of the operands is mentioned in the
instructions. So, in the Data Memory Addressing mode, first the offset address is calculated after
that memory location is calculated, and then the data stored at that location is fetched.
These types of addressing modes are used in branch instructions like JMP or CALL instruction.
Note: The Data memory-addressing mode and the Program Memory Addressing mode are further
categorized into various types about which we will discuss in the upcoming articles.
The stack memory-addressing mode is used whenever you perform a push or pop operation.
Always a word will be entered or popped from the stack in this addressing mode, and the value of
the Stack Pointer (SP) will be incremented or decremented accordingly. The higher byte of data will
be stored at SP-1 location and the lower byte of data will be stored at the SP-2 memory location.
Example: PUSH BX
So, the byte 34H will be stored at 1999H and byte 12H will be stored at 1998H location
Memory
Program, data and stack memories occupy the same memory space. As the most of the processor
instructions use 16-bit pointers the processor can effectively address only 64 KB of memory. To
access memory outside of 64 KB the CPU uses special segment registers to specify where the code,
stack and data 64 KB segments are positioned within 1 MB of memory (see the “Registers” section
below).
4
1. Program memory
program can be located anywhere in memory. Jump and call instructions can be
used for short jumps within currently selected 64 KB code segment, as well as for far
jumps anywhere within 1 MB of memory. All conditional jump instructions can be
used to jump within approximately +127 to – 127 bytes from current instruction.
2. Data memory
the processor can access data in any one out of 4 available segments, which limits
the size of accessible memory to 256 KB (if all four segments point to different 64
KB blocks). Accessing data from the Data, Code, Stack or Extra segments can be
usually done by prefixing instructions with the DS:, CS:, SS: or ES: (some registers
and instructions by default may use the ES or SS segments instead of DS segment).
Word data can be located at odd or even byte boundaries. The processor uses two
memory accesses to read 16-bit word located at odd byte boundaries. Reading word
data from even byte boundaries requires only one memory access.
3. Stack memory
It can be placed anywhere in memory. The stack can be located at odd memory
addresses, but it is not recommended for performance reasons.