0% found this document useful (0 votes)
0 views

Addressing Mode

The document outlines various addressing modes in assembly language, including register mode, immediate addressing mode, direct addressing mode, register indirect addressing mode, based-plus-index addressing mode, register relative addressing mode, and base relative-plus-index addressing. Each mode is explained with examples and illegal instruction cases, emphasizing the rules for operand sizes and memory addressing. It also includes common exam questions related to identifying addressing modes and correcting invalid instructions.

Uploaded by

hiarhiarkhaork
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views

Addressing Mode

The document outlines various addressing modes in assembly language, including register mode, immediate addressing mode, direct addressing mode, register indirect addressing mode, based-plus-index addressing mode, register relative addressing mode, and base relative-plus-index addressing. Each mode is explained with examples and illegal instruction cases, emphasizing the rules for operand sizes and memory addressing. It also includes common exam questions related to identifying addressing modes and correcting invalid instructions.

Uploaded by

hiarhiarkhaork
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

Addressing modes

It is the way of fetching operand for operation

Mov AX,DX where AX is destination , DX is source


Both are called operand
Also “mov” is opcode or operation code

1-Register mode
EX: mov AL,DH it mean copy the content of DH which is 1 byte to AL .
in other words [AL=DH]
EX: mov CX,AX it mean copy the content of BX which is 2 byte to AX .
in other words [CX=AX]
EX : mov CX,CS it mean copy the content of CS which is 2 byte to CX.
in other words [CX=CS]

Illegal instructions for register addressing mode


‫عندما صيغه االيعاز تكون خاطئه‬
EX1: mov CL,DX Illegal instruction because different size registers
,it is not allowed to copies data in 16-bit register to 8-bit register
EX2: Mov DX,CL Illegal instruction because different size registers ,it
is not allowed to copies data in 8-bit register to 16-bit register
EX3:mov CS,AX Illegal instruction because DS is destination ,it is not
allowed CS to be in the destination
EX4:mov ES,DS Illegal instruction because it is not allowed to address 2
memory segment register directly
it should be like this mov AX,DS
mov ES,AX

2-Immediate addressing mode


Directly put a value in a register
EX: mov DL,5A it mean load 5A to 8 bit register DL
EX:mov CX,4AE0 it mean Load 4AE0 to 16-bit register CX
EX:mov CS,6000 it mean load 6000 to code segment register (CS)

Illegal instructions for immediate addressing mode


‫عندما صيغه االيعاز تكون خاطئه‬
EX1:mov 50,AL Illegal instruction since destination is immediate (50)
EX2:mov AH,3F80 Illegal instruction because the source is 16- bit
(3F80)and the destination 8-bit(AH) are different in size

EX3:mov DS,6000 Illegal instruction since Data Segment register can’t


be addressed immediately Also all memory segments register can’t
address Immediately except code segment register
To fix it it should be like this
Mov AX,6000
Mov DS,AX

3-direct addressing mode


When one of the operand is memory

DS:3009 4E
3008 77
3007 6A
3006 5B
3005 2B
3004 F5
3003 67
3002 03
3001 CD
3000 80

Piece of memory segment and its content (suppose DS=4A50)


Ex:mov AH,[3009] it mean load AH with the contained of memory at
logical address DS:3009 which is 4E, in other Word [AH=4E]
EX:mov BX,[3002] it mean load BX with the contained of memory at
logical address DS:3002 and DS:3003 ,in other word [BX=6703]
in other word DS:3002 BL
DS:3003 BH

EX:
mov CX,6A5B
Mov [3006],CX

it mean load CL =5B  DS:3006


Which is 5B and load CH =6A DS:3007 which is 6A

EX: mov AL,ES:[200] segment override


Note: for Intel and Microsoft microprocessor system When data
written in memory location the Lower byte or the first byte will Written
first then the higher byte or the second byte will written and that is call
Little Indian Convention
Illegal instructions for direct addressing mode
‫عندما صيغه االيعاز تكون خاطئه‬
EX1:mov [3006],[3000] Illegal instruction because
Source and destination are both memory to To fix it
mov AX,[3000]
Mov [3006],AX
EX2:mov AL,[3005] Illegal instruction it should determine the
size of data that been transfer or copied
To fix it mov AL, BYTE PTR [3005]

Example: if DS=4A50h and this instruction is


Executed mov AH, [3000]
What is the physical address and the logical address of the byte
that will be loaded to
AH?
Solution:
Logical address is DS: offset
4A50:3000
AH =80 according to our example
Physical address=4A50h *10h+3000h
=4A500h+3000h
=4D500h 20 bit physical address
of byte 80 in the memory
4-Register indirect addressing mode
This addressing mode use these register only
(BX, SI, DI, BP) to address memory where the
Registers (BX,SI,DI)deals with data memory segment (DS)
While (BP) deals with stack memory segment only (SS)
EX:
Mov BX,3005
mov CL, [BX]
it means load 8-bit CL register with
1byte located in the logical address DS: BX
If BX=3005, DS=4A50 it mean the byte will be
Located in the logical address 4D50:3005 is 2Bh
And CL=2B we Can easily calculate the physical
Address.
EX:mov [SI],2000 copy immediate data 2000 to memory location
with logical address DS:SI
Where 00DS:SI
20DS:SI+1

EX: mov DX,CD80


Mov SI ,3000
Mov [SI],DX
What is the result which is located in the memory location which
is addressed by SI ?
When DS=4A50
It means
DL=80 will be copied to DS:SI which is 4A50:3000
[3000]=80 or [SI=3000]=80
DH=CD will be copied to DS: SI+1 which is 4A50:3001
[3001]=CD or [SI+1=3001]=CD

Illegal instructions for Register indirect addressing mode


‫عندما صيغه االيعاز تكون خاطئه‬
EX:mov [AX],BX Illegal instruction because it is not allowed to use
AX register to address memory

5-based-pluses- index addressing mode


Copies byte or word of memory location where these memory
addressed by Based register (BP or BX) plus and index register (SI or DI)
Mov AL,[Based register BX or BP+ Indexed register SI or DI]
EX:mov AL,[BX+SI]
EX:mov [DI+BX],CX
EX:mov [BP-SI],DH
EX:mov AX,[DI+BP]

Illegal instructions for Based-plus- index addressing mode


‫عندما صيغه االيعاز تكون خاطئه‬

EX: mov AL,[BX+BP+SI] Illegal instruction it is not allowed to address


memory using both BX and BP in the same time
EX: mov [DI+SI+BX] Illegal instruction it is not allowed to address
memory using both DI and SI in the same time

6-Register relative addressing mode


Which include both Based relative Addressing mode and Indexed
relative addressing mode
Mov AL,[Based register BX or BP+ displacement] or
Mov AL,[Based register SI or DI+ displacement]

Note: use only BX or BP to address memory but not in the same time
EX:mov DL,[BX+6] it means copies byte from DS:BX+6
EX:mov DL,6[BX]
EX:mov DL,[BX]+6
All of them have the same meaning
EX:mov 4[BP],CX
It means copies the content of 16-bit register CX to stack segment
memory with offset BP+4

CLss:BP+4 lower byte or the first byte


CHSS:BP+1+4 higher byte or the second byte

Illegal instructions for Register relative addressing


‫عندما صيغه االيعاز تكون خاطئه‬

EX:mov DX,[BX+BP+5] it is not allowed to address memory with both


BX and BP in the same time

EXAMPLE
An instruction get executed mov AL,9[BX] if DS=6000h and BX=4000H
find the effective address of the byte that will copied to AL
Solution: effective address is the same like physical address
Effective address =DS*10h+ offset 6000*10+9+4000
Effective address =60000+9+4000=64009h
Note: also use only DI or SI to address memory but not in the same
time
Mov AL,[Index register SI or DI+ displacement]
EX:mov AL,[SI+8]
ALDS:SI+8

EX:mov [DI+3],BX
BLDS:DI+3
BHDS:DI+4

Illegal instructions for Index relative addressing mode


‫عندما صيغه االيعاز تكون خاطئه‬
EX:mov [SI+DI+3],AX
It is not allowed to address memory with both SI and DI in the
same time only one of them SI or DI
7- .Base Relative-plus-Index Addressing
Copies byte or word of memory location where these memory
addressed by Based register (BP or BX) plus and index register (SI or DI)
Mov AL,[Based register BX or BP+ Indexed register SI or
DI+displacement]
EX:
Mov DL,[BX+SI+6]
DLDS:BX+SI+6
Mov [BP+DI+4],CX
CLSS:BP+DI+4
CHSS:BP+DI+5

Mov AL,5[SI+BX]
ALDS:SI+BX+5
Illegal instructions for Based indexed relative addressing mode

EX:mov CL,[BX+BP+SI+5] it is not allowed to address memory with


both BX and BP in the same time

EX:mov [SI+DI+8+BP+BX] ,DL it is not allowed to address memory with


both BX and BP in the same time and DI and SI in the same time
EXAMPLE
IF
DS=6000h,SS=8000h,SI=200h,DI=400h,BX=1000h,BP=2000h,CX=A1B1h
Q1) What will be the effective address of the byte copied in DL when
this instruction get executed
Mov DL,[BX+SI+6]
Effective address = DS*10h+BX+SI+6
Effective address =6000h*10h+1000h+200h+6
Effective address =61206h
Q2) what will be the effective address of the word of CX register in the
memory when this instruction get executed mov [BP+DI+4],CX
Or specify where the content of CX= {CL and CH} will be store in the
memory when this instruction get executed mov [BP+DI+4],CX

Solution:
Effective address =SS*10h+DI+4+BP
Effective address =8000h*10h+400h+2000h+4
Effective address =80000+2404h
Effective address =82404h the effective address of for CL
82405 the effective address of for CH
Common Questions in the exams:
1. What is the addressing mode of each of the following instructions:
a-mov [400],DL
b-mov [DI+BX+2],AH

2. Explain which of the following instructions are invalid? State the


invalidation reason and give the correct form for invalid
instructions

a-mov AL,BX
b-mov DL,3[BX+SI+DI]

3. Let say BX = 1000H, SI = 2000H, DISP = 1234H, DS =1200H.


Determine the effective address of the Word that will be
transferred to DX when executing this instruction:
MOV DX,[BX+SI+1234]

You might also like