Hello!
Microprocessor & Assembly Language
Programming
(CoSc3025)
Kenesa B. (getkennyo@[Link])
Ambo University, Hachalu Hundessa Campus
Computer Science Dept
Sep, 2025
CHAPTER THREE
Addressing Modes
2
Chapter Objectives
Upon completion of this chapter, you will be able to:
Explain the operation of each data-addressing mode.
Use the data-addressing modes to form assembly
language statements.
Select the appropriate addressing mode to accomplish
a given task.
Detail the difference between addressing memory data
and program memory .
Describe sequence of events that place data onto the
stack or remove data from the stack.
3
Introduction
How machine language instruction in that architecture identify operand of
each instruction?
Efficient software development for the microprocessor requires a
complete familiarity with the addressing modes employed by each
instruction.
The job of a microprocessor is to execute a set of instructions stored in
memory to perform a specific task.
• When the microprocessor executes an instruction, it performs the
specified function on data.
Operations require the following:
• The operator or opcode which determines what will be done
• The data to be used in the operation
which is called operands
4
Introduction
These data may be part of the instruction, may reside in one of the internal
registers, may be stored at an address in memory, or may be held at an I/O
port
Addressing modes tell us how to locate these operands.
The different ways in which a source operand is denoted in an instruction are known as
the addressing modes.
• It is a technique to determine which operand to be fetched. (Operand is an
argument for an operator or for machine language instruction)
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.
To access these different types of operands, the 8086/88 provided with various
addressing modes.
5
Addressing Modes
The addressing modes are categorized in to the following types:
1. Data-Addressing Modes
8086 through 80286: register, immediate, direct, register indirect,
base-plus-index, register relative,and base relative-plus-index
80386 and above: scaled-index
• MOV(Move data) instruction –moves byte, word or double word
2. Program Memory-Addressing Modes
program relative, direct, and indirect
• CALL and JUMP instructions
3. Stack Memory-Addressing Modes
• PUSH and POP instructions
6
Data Addressing Modes
Data addressing modes include: register, immediate, direct, register indirect,
base-plus-index, register relative,and base relative-plus-index
These data-addressing modes are found with all versions of the Intel
microprocessor.
• except for the scaled-index-addressing mode, found only in 80386 through
Core2
RIP (instruction pointer register on a 64-bit platform) relative addressing
mode is only available on the Pentium 4 and Core2 in the 64-bit mode
The microprocessor contains these 8-bit register names used with register
addressing: AH, AL, BH, BL, CH, CL, DH, and DL.
• 16-bit register names: AX, BX, CX, DX, SP, BP, SI, and DI.
The following table shows all possible variations of the data-addressing
modes using MOV.
7
8
Register Addressing Mode
The most common form of data addressing.
• once register names learned, easiest to apply
In this mode, the operand to be accessed is specified as residing in an
internal register of the 8086.
• Both source and destination operands are internal registers.
Transfer a copy of a byte or word or double word from the source register to
the destination register.
Important for instructions to use registers that are the same size.
• never mix an 8-bit with a 16-bit register, an 8- or a 16-bit register with a
32-bit register
• this is not allowed by the microprocessor and results in an error when
assembled
9
Register Addressing Mode
Segment to segment register move is not allowed
While using MOV instruction the source register content do not change but
destination changes.
• The content of destination changes for all instruction except the CMP and
TEST instructions
Example: Write an instruction that will move the contents of DX register to
the CX register.
• Solution: The instruction must use register operand addressing for the
source operand and register operand addressing for the destination
operand:
• MOV CX, DX
CX 00 00 CX 12 34
DX 12 34 DX 12 34
10
Register Addressing Mode
Example: The effect of executing the MOV BX, CX instruction at the point
just before the BX register changes.
• Note that only the rightmost 16 bits of register EBX change.
• The MOV BX, CX instruction does not affect the leftmost 16 bits of
register EBX
11
Register Addressing Mode
In this type of addressing mode, the data is stored in the register and it can
be a 8-bit or 16-bit register.
• All the registers, except IP, may be used in this mode.
• Examples:
MOV AX, BX ;Copies the 16-bit contents of BX to AX
MOV AL, BL ;Copies the 8-bit contents of BL to AL
MOV SI, DI ;Copies DI into SI
• The following register to register transfers are not permitted:
MOV BL, AX ;mixed size (not permitted)
MOV CS, AX ;CS cannot be destination
MOV ES, DS ;Segment to Segment is forbidden
12
Immediate Addressing Mode
If an operand is part of the instruction instead of the content of a register or
a memory location, it is called an immediate operand
• and is accessed using the immediate addressing mode
Term immediate implies that data immediately follow the hexadecimal
opcode in the memory.
• immediate data are constant data
• data transferred from a register or memory location are variable data
Immediate addressing operates upon a byte or word of data.
Example: Write an instruction that will move the immediate value 1234H into
the CX register.
• Solution: The instruction must use immediate operand addressing for the source operand
and register operand addressing for the destination operand:
• MOV CX, 1234H
13
Immediate Addressing Mode
The operation of the MOV EAX, 13456H instruction copies the immediate data
(13456H) into EAX.
• the source data overwrites the destination data
In symbolic assembly language, the symbol # precedes immediate data in
some assemblers.
MOV AX, #3456H instruction is an example
• Most assemblers do not use the # symbol, but represent immediate data
as in the MOV AX, 13456H instruction.
14
Immediate Addressing Mode
It can’t be used with segment registers (DS, CS, ES, SS) and flag register
Invalid Example: Load value directly to DS
Source operand
Destination operand
This problem can be overcome by loading 0123H to one general purpose
register and then the register value is copied to segment register as the
following:
• MOV AX, 0123H
• MOV DS, AX
15
Immediate Addressing Mode
Valid examples:
MOV AL, 0AH ;loads 0AH into AL
MOV BX, 1000H ;loads 1000H into BX
MOV CL, ‘A’ ;loads the ASCII code for ‘A’ (65) into CL
Invalid examples:
MOV AL, 2AAH ;Not allowed as the data exceeds the length of the destination
The symbolic assembler portrays immediate data in many ways.
The letter H appends hexadecimal data, letter B for binary data
If hexadecimal data begin with a letter, the assembler requires the data start with a 0.
• to represent a hexadecimal F2, 0F2H is used in assembly language
Decimal data are represented as is and require no special codes or adjustments.
An ASCII-coded character or characters may be depicted in the immediate form if the
ASCII data are enclosed in apostrophes.
16
Direct Data Addressing Mode
This mode is similar to immediate addressing in that information is encoded
directly into the instruction.
However, in this case the instruction opcode is followed by an effective
address, instead of the data.
Moves a byte or word or double word between a memory location and
register.
• Applied to many instructions in a typical program.
Two basic forms of direct data addressing:
direct addressing: which applies to a MOV between a memory location and Accumulator
register (AL, AX, or EAX)
displacement addressing: which applies to almost any instruction in the instruction set
Address is formed by adding the displacement to the default data segment
address or an alternate segment address.
17
Direct Addressing Mode
Direct addressing with a MOV instruction transfers data between a memory
location, located within the data segment, and the AL (8-bit), AX (16-bit), or
EAX (32-bit) register.
• usually a 3-byte long instruction
Example: MOV AL, DATA loads AL from the data segment memory location
DATA (1234H).
• DATA is a symbolic memory location, while 1234H is the actual hexadecimal location
The operation of the MOV AL, [1234H] instruction when DS=1000H 18
Direct Addressing Mode
This instruction transfers a copy contents of memory location 11234H into
AL.
• the effective address is formed by adding 1234H (the offset address) and 10000H (the
data segment address of 1000H times 10H)
Examples of Direct Addressing using AL, AX, and EAX
19
Indirect Addressing Modes
A method of addressing in which the contents of the address specified in the
instruction are themselves an address to be used to provide the desired
memory reference.
• This is the mode of addressing where the instruction contains the address of the location
where the target address is stored.
So in this way, it is indirectly storing the address of the target location in
another memory location.
• instruction specifies the register holding the address
• Address dynamic: depends on contents of register when instruction is executed.
Effective address or Offset: An offset is determined by adding any
combination of three address elements:
• Displacement: It is an 8 bit or 16 bit immediate value given in the instruction.
• Base: Contents of base register, BX or BP.
• Index: Content of index register SI or DI. 20
Register Indirect Addressing
Transfer a byte, word or double word between register and memory location
addressed by index or base register
Allows data to be addressed at any memory location through an offset
address held in any of the following registers: BP, BX, DI, and SI.
In addition, 80386 and above allow register indirect addressing with any
extended register except ESP.
In the 64-bit mode, the segment registers serve no purpose in addressing a
location in the flat model.
E.g.
• MOV AX, [BX]
• MOV AX, [BP] ([ ] – denote indirect addressing)
Look at the operation of the MOV AX, [BX] instruction when BX = 1000H and
DS = 0100H from the next slide.
21
Register Indirect Addressing
Note that this instruction is shown after the contents of memory are
transferred to AX.
22
Register Indirect Addressing
The data segment is used by default with register indirect addressing or any
other mode that uses BX, DI, or SI to address memory.
If the BP register addresses memory, the stack segment is used by default.
• these settings are considered the default for these four index and base
registers
For the 80386 and above, EBP addresses memory in the stack segment by
default.
• EAX, EBX, ECX, EDX, EDI, and ESI address memory in the data segment by
default.
Indirect addressing often allows a program to refer to tabular data located in
memory.
The following figure shows the table and the BX register used to sequentially
address each location in the table.
23
Register Indirect Addressing
To accomplish this task, load the starting location of the table into the BX
register with a MOV immediate instruction.
After initializing the starting address of the table, use register indirect
addressing to store the 50 samples sequentially.
An array (TABLE) containing 50 bytes that are
indirectly addressed through register BX.
24
Base-Plus-Index Addressing
Similar to indirect addressing because it indirectly addresses memory data.
Transfer a byte , word or double word between register and memory location
addressed by base register(BP or BX) plus index register (DI or SI).
• E.g. MOV [BX+DI], CL
The base register often holds the beginning location of a memory array.
• the index register holds the relative position of an element in the array
• whenever BP addresses memory data, both the stack segment register and BP generate
the effective address
The following figure shows how data are addressed by the MOV DX, [BX + DI]
instruction when the microprocessor operates in the real mode.
• The Intel assembler requires this addressing mode appear as [BX][DI] instead of [BX +
DI].
• The MOV DX, [BX + DI] instruction is MOV DX, [BX][DI] for a program written for the Intel
ASM assembler. 25
Locating Data with Base-Plus-Index Addressing
An example showing how the base-plus-index addressing mode functions for the
MOV DX,[BX + DI] instruction.
Notice that memory address 02010H is accessed because DS=0100H, BX=1000H and DI=0010H.
26
Locating Array Data Using Base-Plus-Index Addressing
A major use is to address elements in a memory array.
To accomplish this, load the BX register (base) with the
beginning address of the array and the DI register
(index) with the element number to be accessed.
The following figure shows the use of BX and DI to
access an element in an array of data.
An example of the base-plus-index addressing mode. Here an element
(DI) of an ARRAY (BX) is addressed.
27
Register Relative Addressing
Similar to base-plus-index addressing and displacement
addressing.
• data in a segment of memory are addressed by adding
the displacement to the contents of a base or an index
register (BP, BX, DI, or SI)
The following figure shows the operation of the MOV AX,
[BX+1000H] instruction
DS = 0200H
28
Addressing Array Data with Register Relative
It is possible to address array data with register
relative addressing.
• such as with base-plus-index addressing
From the following figure register relative
addressing is illustrated with the same example
as for base-plus-index addressing.
• this shows how the displacement ARRAY adds
to index register DI to generate a reference
to an array element
Register relative addressing used to address an element of ARRAY. The
displacement addresses the start of ARRAY, and DI accesses an element. 29
Base Relative-Plus-Index Addressing
Similar to base-plus-index addressing.
• adds a displacement
• uses a base register and an index register to form the memory address
This type of addressing mode often addresses a two-dimensional array of
memory data.
Least-used addressing mode.
The following figure shows how data are referenced if the instruction
executed by the microprocessor is MOV AX, [BX + SI + 100H].
• displacement of 100H adds to BX and SI to form the offset address within
the data segment
This addressing mode is too complex for frequent use in programming.
30
Addressing Data with Base Relative-Plus-Index
An example of base relative-plus-index addressing using a MOV AX,[BX+SI+100H] instruction.
Note: DS=1000H
31
Addressing Arrays with Base Relative-Plus-Index
Suppose a file of many records exists in memory,
each record with many elements.
displacement addresses the file, base register
addresses a record, the index register addresses
an element of a record
This figure illustrates this very complex form of
addressing.
Base relative-plus-index addressing used to access a
FILE that contains multiple records (REC).
32
Program Memory-Addressing Modes
The Program Memory Addressing mode is used in branch instructions.
– These branch instructions are instructions which are responsible for
changing the regular flow of the instruction execution and shifting the
control to some other location.
In 8086/88 microprocessor, these instructions are usually JMP and CALL
instructions.
The Program memory Addressing Mode consist of three distinct forms:
direct
relative, and
indirect
We’ll discuss these three addressing forms, using the JMP instruction
33
Direct Program Memory Addressing
In this addressing mode, the offset address where the control is to be shifted
is defined within the instruction.
– In this type of addressing mode, the memory address (contains both segment and offset
set address) represents the address to which the microprocessor has to transfer.
This mode is called direct addressing mode because the required address is
directly present in the instruction rather than being stored in some register.
For example, look at the JMP 10000H
– This JMP instruction loads CS with 1000H and IP with 0000H to jump to memory location
10000H for the next instruction.
The 5-byte machine language version of a JMP [10000H] instruction
34
Direct Program Memory Addressing
An intersegment jump is a jump to any memory location within the entire
memory system
– Often called a far jump because it can jump to any memory location for the next
instruction.
– in 8086/88 mp, any location within the first 1M byte
This implies an inter-segment jump or far jump, as the microprocessor can
jump to any memory location within the memory segment.
The only other instruction using direct program addressing is the
intersegment or far CALL instruction.
Usually, the name of a memory address, called a label, refers to the location
that is called or jumped to instead of the actual numeric address.
– When using a label with the CALL or JMP instruction, most assemblers
select the best form of program addressing.
35
Relative Program Memory Addressing
Not available in all early microprocessors, but it is available to this family of
microprocessors.
The term relative means “relative to the instruction pointer (IP)”.
The JMP instruction is a 1-byte instruction, with a 1-byte or a 2-byte
displacement that adds to the instruction pointer.
In this Addressing mode, the offset address is equal to the content of the
Instruction Pointer (IP) plus the 8- or 16-bit displacement.
Relative JMP and CALL instructions are used to indicate relative addressing.
In this, 8-bit or 16-bit signed displacement is added to the current
instruction pointer (IP) to obtain the address of the next instruction (i.e., CS
× 10H + IP).
– If displacement is negative, IP decrement by the magnitude of displacement.
– If displacement is positive, IP increments by displacement value.
36
Relative Program Memory Addressing
Short jump and call instructions (uses one-byte displacement) and near jump
and call instructions (uses two-byte displacement) are combined called intra-
segment jumps as the program control is transferred within the current code
segment.
SHORT and NEAR PTR are used to indicate short and near jump respectively.
For the 8 bit displacement, SHORT is used and for 16-bit displacement, LONG
is used.
– This type of displacement will only be intra-segment, i.e. within the
segment.
Example: JMP SHORT OVER
– Here, SHORT is used to represent the 8-bit displacement and OVER is the Label defined
for any particular memory location.
Example: JMP NEAR PTR FIND
37
Indirect Program Memory Addressing
The microprocessor allows several forms of program indirect memory
addressing for the JMP and CALL instructions.
In 80386 and above, an extended register can be used to hold the address or
indirect address of a relative JMP or CALL.
– for example, the JMP EAX jumps to the location address by register EAX
In this addressing mode, the offset address is not present directly in the
instruction.
– It is rather stored in any of the CPU registers (Internal Register).
So, the contents of the Instruction Pointer (IP) will be replaced by the
contents of that register.
If a relative register holds the address, the jump is considered to be an
indirect jump.
38
Indirect Program Memory Addressing
For example, JMP [BX] refers to the memory location within the data
segment at the offset address contained in BX.
– at this offset address is a 16-bit number used as the offset address in the
intra-segment jump
– this type of jump is sometimes called an indirect-indirect or double-
indirect jump
Example : JMP [BX]
– Suppose that the content of the BX register is 0003H.
– So, the working of the microprocessor for executing the above instruction
will be as follows
• IP = contents of BX i.e. IP = 0003H
And the required memory address is calculated in a similar way as in Direct
Addressing mode: (Contents of CS) * 10H + (contents of IP)
39
Stack Memory-Addressing Modes
The stack plays an important role in all microprocessors.
– holds data temporarily and stores return addresses used by procedures
Stack memory is LIFO (last-in, first-out) memory
– describes the way data are stored and removed from the stack
Data are placed on the stack with a PUSH instruction; removed with a POP
instruction.
Stack memory is maintained by two registers:
– the stack pointer (SP)
– the stack segment register (SS)
Whenever a word of data is pushed onto the stack, the high-order 8 bits are
placed in the location addressed by SP – 1.
– low-order 8 bits are placed in the location addressed by SP – 2
40
Stack Memory-Addressing Modes
The SP is decremented by 2 so the next word is stored in the next available
stack location.
– the SP register always points to an area of memory located within the
stack segment.
When data are popped from the stack, the low-order 8 bits are removed
from the location addressed by SP.
– high-order 8 bits are removed; the SP register is incremented by 2
Example Swap operation using stack
mov ax, 1000h
mov bx, 2000h
push ax ; 1000h to stack
push bx ; 2000h to stack
pop ax ; 2000h to ax
pop bx ; 1000h to bx
41
Stack Memory-Addressing Modes
The PUSH and POP instructions:
(a) PUSH BX places the
contents of BX onto the stack;
(b) POP CX removes data from
the stack and places them into
CX. Both instructions are shown
after execution.
Note that PUSH and POP store
or retrieve words of data—
never bytes—in 8086 – 80286.
42
THE END
43