Lecture 3: Addressing Modes
8086Mp has a group of instructions that are used by the programmer to specify the task
required to be done by the Mp. The language used for programming 8086Mp is called (Assembly
Language).
(MOV) instruction is the most used 8086Mp instruction, and it is used as follows:
MOV AX, BX
In this example: Source
Destination
- AX is the destination
- BX is the source
- The value of BX will be moved (copied) to AX
- The old value of AX will be removed and now AX=BX
- BX will not be changed
In all instructions:
- The source and destination MUST have the same length.
- The destination is called so because the result of the operation performed by the
instruction is always stored in the destination.
- The source is NOT changed by the instruction.
كٌٕ رنك يٍ خاللٚٔ ,)اذٓا خالل انفصم األٔلٛرى ذؼهى اعاعٛ عٙرى انرؼايم يغ انًؼانح يٍ خالل انهغح انخاصح تّ (ٔانرٚ
.اخ يرُٕػحٛاو تؼًهًٛكٍ اعرخذايٓا نهقٚ ٙانُظش انٗ انًؼانح ػهٗ ا َّ يدًٕػح يٍ انغدالخ انر
رىٛ ٔع.)destination() انٗ انـsource(ًح انـٛؼاص َقم أ َغخ قٚ) ْٕٔ اMOV( ْٕ ً ؼاص االتغظ ٔاالكثش اعرخذاياٚاال
.)Addressing Modes( ؼاص نششذ االَٕاع انًخرهفح يٍ انؼَُٕحٚاعرخذاو ْزا اال
Addressing Modes
1) Register Addressing Mode
كَٕا تُفظ انطٕلٚ ٌدة اٚٔ )register( ) ػثاسج ػٍ عدمdestination() ٔانـsource(كٌٕ كم يٍ انـٚ ْزا انُٕعٙف
.)تد66 تد أٔ كالًْا8 (ئيا كالًْا
MOV Register, Register
.ؼاصاخٚ يدًٕػح يٍ االيثهح ػهٗ ْزا انُٕع يٍ االٙ اندذٔل انرانٙف
ُْانك زاالخ ًُٚغ اعرخذايٓا ْٔ ٙانساالخ انرانٛح:
-6أٌ ٚكٌٕ طٕل انـ(ٔ )sourceانـ( )destinationغٛش يرغا ٍٔ( ,كًا ف ٙانًثال قثم االخٛش يٍ اندذٔل انغاتق).
-2أٌ ٚكٌٕ كال انغده( ٍٛأ٘ كم يٍ انـ(ٔ )sourceانـ( ْٕ ))destinationيٍ انـ( )segment registersاالستؼح
ْٔ( )CS, DS, ES, SS( ٙكًا ف ٙانًثال 8يٍ اندذٔل انغاتق )ٔ ,انغثة أَٓا عدالخ خاصح ٔاعرخذايٓا فٙ
االٚؼاصاخ ٚكٌٕ تشكم يسذٔد فقظ .أيا ارا كاٌ أزذ انغده ٍٛفقظ ْٕ يٍ انـ( )segment registersفٓزا يًكٍ يا ػذا
زانح ٔازذج ْٔ ٙأٌ ٚكٌٕ انـ ْٕ CSانـ( )destinationفٓزا ال ٚدٕص (كًا ف ٙانًثال األخٛش يٍ اندذٔل انغاتق)
ٔانغثة أَّ ٚسرٕ٘ قًٛح يًٓح ذًثم ػُٕاٌ انـ segmentانز٘ ٚسرٕ٘ ػهٗ االٚؼاصاخ ف ٙانزاكشج ٔف ٙزانح ذغٛٛش
قًٛرّ ٚرى فقذاٌ انثشايح.
مالحظة :خًٛغ انغدالخ الًٚكٍ ذدضئرٓا ف ٙاالٚؼاصاخ ٔاًَا ٚرى انرؼايم يؼٓا ػهٗ آَا 66تد دائًاً ,يا ػذا ( AX, BX,
)CX, DXزٛث ًٚكٍ ذدضئح كم يُٓى انٗ خضئ ٍٛيٍ 8تد (.)AL, AH, BL, BH, CL, CH, DL, DH
2) Immediate Addressing Mode
MOV Register , NUMBER
ال ٔٚكٌٕ تُفظ طٕل انـ( )destinationئيا 8تد أٔ 66تدٚٔ .ؼطٗ فْ ٙزا انُٕع ٚكٌٕ انـ( )sourceسقًا ً ٔنٛظ عد ً
انشقى ئيا تانُظاو انغادط ػشش٘ (ٔ )Hexadecimalرنك تأٌ ٚكرة ف ٙآخشِ انسشف ( Hكًا ف ٙانًثال 2يٍ اندذٔل ادَاِ),
أٔ تانُظاو انثُائٔ )Binary( ٙرنك تاٌ ٚكرة ف ٙآخشِ انسشف ( Bكًا ف ٙانًثال األخٛش يٍ اندذٔل ادَاِ) ,أٔ تانُظاو انؼشش٘
(ٔ )decimalرنك تاٌ ال ٚكرة ف ٙآخشِ ا٘ شٙء (كًا ف ٙاأليثهح 4ٔ 3ٔ 6يٍ اندذٔل ادَاِ) .أيا ارا كاٌ سيضا ً ٔنٛظ سقًا ً
فٛرى ٔضؼّ داخم ػاليرُْٔ (‘ ‘) ٙا ٚرى اخز قًٛح انـ( ) ASCIIانخاصح تٓزا انشيض (ْٔ ٙػثاسج ػٍ سقى طٕنّ 8تد ٚقاتم
انشيض انًؼطٗ ت ٍٛػالير ٙاالقرثاط) ٔٚرى اػطاؤِ نهـٔ destinationانز٘ ٚدة اٌ ٚكٌٕ عدالً تطٕل 8تد (كًا ف ٙانًثال 5
يٍ اندذٔل ادَاِ)ٔ .ارا ذى ٔضغ سيض ٍٚداخم ػالير ٙاالقرثاط يؼُاِ عٛرى أخز 66تد (8تد نكم سيض) ٔٔضؼٓا فٙ
انـ destinationانز٘ ٚدة اٌ ٚكٌٕ عدالً تطٕل 66تد (كًا ف ٙانًثال 6يٍ اندذٔل أدَاِ).
Examples: MOV AL, 15H (AL=15H)
MOV BX, 6F0AH (BX=6F0AH) or (BL=0AH and BH=6FH)
MOV CX, 1 H (CX=1H) or (CL=01H and CH=00H)
MOV 1FH, AL
MOV 47H, DH NOT ALLOWED (Destination CAN NOT be a number!)
MOV 55, DX
ٔكزنك انسال ارا.حٛش يُطقٛح غٛ ػًهٙٓ ف,ّٛح انُقم ذرى انٛ سقًا ً الٌ ػًهdestinationكٌٕ انـٚ ًٌكٍ اٚ َالزظ أَّ ال
.دٕصٚ ضا ً الٚ ػثاسج ػٍ اسقاو فٓزا اdestination ٔانـsourceكاٌ كم يٍ انـ
MOV DS, 100H NOT ALLOWED
It is NOT allowed to use immediate addressing mode with segment registers (CS, DS, ES,
SS). In order to put 100H in DS, we can do the following:
MOV AX, 100H
MOV DS, AX ALLOWED
ٖ ٔاًَا َقٕو تاعرخذاو ازذ انغدالخ االخش, االستؼحsegment registersؼاصاخ يغ انـًٚكٍ اعرخذاو ْزا انُٕع يٍ االٚ ال
شًٛٛكٍ اعرخذايٓا نرغٚ قحٚ) ْٔزِ انطشregister addressing mode( ًح تاعرخذاو انـُٕع االٔلٛ نُقم انقٙكًخضٌ ٔعط
.ً كًا ركش عاتقاCS يا ػذا انـsegment registersًح ا٘ يٍ انـٛق
3) Direct Addressing Mode
MOV destination , [ NUMBER ]
MOV [ NUMBER ], source
رى اعرخذاو اقٕاط يشتؼح نهٕصٕلٚ ثٛ ز,destination أٔ كـsourceرى انرؼايم يغ انزاكشج ٔاعرخذايٓا كـٚ ْزا انُٕعٙف
.غاػذَا ػهٗ انٕصٕل انٗ انؼُٕاٌ انًطهٕبٍٛ ْزِ االقٕاط نٛرى ٔضغ سقى ياتٚٔ انٗ انزاكشج
Example 1:
MOV AL , [1234H]
In this example, an 8-bit value is taken from a memory location and copied to AL.
How can the Mp calculate the physical address and go to the correct memory location? The
physical address is calculated from (segment : offset). The number given in the instruction
inside square brackets is the offset. When the offset is a number, then the segment is always DS.
The Mp will take the offset from the instruction which is 1234H and adds it with DS value after
multiplying DS by 16 to find the physical
. address. Let DS=1000H, then:
.
.
66H 1000H:1235H
5FH 1000H:1234H
AL B0H 1000H:1233H
.
.
.
(After execution: AL=5FH)
:ّ يٍ انزاكشجٛ انًطهٕب انزْاب انٙائٚضٛح زغاب انؼُٕاٌ انفٛفٛك
ٙ كًا ف,66 ٙ تؼذ ضشتّ فDSًح انـٛ ثى ذدًغ يغ قoffsetث ذًثم انـٍٛ االقٕاط انًشتؼح زًٛح انًٕخٕدج تٛرى اعرخذاو انقٚ
.انًثال انغاتق
Example 2:
MOV AX, [51FFH]
In this example, 16-bits will be moved from the memory to AX. The memory PA will be
calculated in the same way as in example 1. This time two bytes are required to be copied from
the memory to AX, so that: the first byte (lower byte) of AX (which is AL) will be taken from
the specified memory location and the second byte (higher byte) of AX (which is AH) will be
taken from the next memory location. Let DS=2000H, then:
.
.
.
D9H 2000H:5200H
AH 33H 2000H:51FFH
AL 1FH 2000H:51FEH
.
.
.
After execution: AX=D933H.
. انغإالٙ يدشد يثال ٔذؼطٗ فْٙ انزاكشج ُْاٙى انًخضَٔح فٛ انق:مالحظة
Note: in the two previous examples, the memory location was the source so that it is not
changed; only the destination is changed.
Example 3:
MOV [13A9H], DX
In this example, two bytes will be copied from DX to the memory location at offset=13A9H
in DS. Let DS=4000H and DX=8F10H, then:
.
.
.
4000H:13ABH
DH
8FH 4000H:13AAH
DL
10H 4000H:13A9H
.
.
.
(after execution DX is not changed, only two memory locations are changed)
MOV [4F00H], [651BH] NOT ALLOWED (memory to memory is not allowed)
MOV [3A88H], 5H This is allowed BUT: the length of the moved data is not clear (16-bit or
8-bits), therefore we need to specify this length using either (byte ptr) or (word ptr), as follows:
MOV byte ptr[3A88H], 5H One memory location at DS:3A88H will be given the value 05H
MOV word ptr[3A88H],5H Two memory locations will be changed as follows:
DS:3A88H will be given the value (05H)
DS:3A89H will be given the value (00H)
MOV 5H, [3A88H] NOT ALLOWED (destination can NOT be a number)
MOV DS, [3000H] NOT ALLOWED (segment registers can NOT be used with memory)
4) Indirect Addressing Mode
نًٕقغ انزاكشجoffsetًرّ ذًثم انـٛ) قregister( ظ تشكم سقى ٔاًَا تشكم عدمٛ نoffsetرى اػطاء انـٚ ْزا انُٕعٙف
.ٍ اقٕاط يشتؼحٕٛضغ ْزا انغدم تٚ ثٛ ز,انًطهٕب
MOV Destination, [Register ]
MOV [Register ], Source
Examples: MOV AX, [BX]
MOV [DI], AL
MOV [BP], BX
MOV DX, [SI]
)segment-offset combinations( خذٔل انـٙ يٕخٕدج فْٙٔ offsetًكٍ اٌ ذغرخذو كـٚ ُْانك عدالخ يسذدج
ًّكٍ اعرخذايٛ) فSP( أيا,)BP, BX, SI, DI( ْٙ ٔزغة ْزا اندذٔل فاٌ ْزِ انغدالخ.ٗ انًساضشج االٔنٙانًؼطٗ ف
ؼاصاخ التشكم عدم ٔالتشكمٚ االًٙكٍ اعرخذايّ تشكم يثاشش يطهقا ً فٚ الIP ٔعدم انـ,ظ كًإشش انٗ انزاكشجٛكغدم فقظ ٔن
.يإشش
يإششْٙٔ حَٛح ثاًٛ أٔ ُْانك ذغoffsetّ اعى انـٛطهق ػهٚ ش ػهٗ انزاكشجٛ نهرأشregister ػُذ اعرخذاو انغدم:مالحظة
.)pointer(
:ّ يٍ انزاكشجٛ انًطهٕب انزْاب انٙائٚضٛح زغاب انؼُٕاٌ انفٛفٛك
تؼذsegmentًح انـٛ ثى ذدًغ يغ قoffsetث ذًثم انـٍٛ االقٕاط انًشتؼح زًٛح انغدم انًٕخٕد تٛرى اعرخذاو قٚ
ٙ) انًؼطٗ فsegment-offset combinations( يٍ خالل انشخٕع انٗ خذٔل انـsegmentرى يؼشفح انـٚ .66 ٙضشتّ ف
ٔارا كاٌ انًإشش انًغرخذوDS ْٕ segmentكٌٕ انـٛ فغDI ٔ أSI ٔ أBX ْٕ فارا كاٌ انًإشش انًغرخذو,ٗانًساضشج االٔن
.SS ْٕ segmentكٌٕ انـٛ فغBP ْٕ
Example: Let BX=1000H, DS=100H. Find the value of AX after executing the following
instruction (note that the memory is given in the question): MOV AX, [BX]
.
.
.
77H 02003H
A7H 02002H
34H 02001H
12H 02000H
.
.
.
Solution: the Physical Address = DS * 16 + BX
PA = 0 1 0 0 0
1000 +
02000H
⸫ After execution, AX= 3412H
انغإالٙ زال ذى اػطائّ فٙ ٔنكٍ ف,رٛ كالًْا صسٙائٚضٛ أٔ انفٙش انؼُٕاٌ ػهٗ انزاكشج تانشكم انًُطقًٛكٍ ذأشٚ :مالحظة
ٍ نُصم نهًٕقغ أ انًٕاقغ انًطهٕتح يٙ يٍ انؼُٕاٌ انًُطقٙائٚضٛح فُسراج انٗ زغاب انؼُٕاٌ انفٛائٚضٛقح انؼَُٕح انفٚتطش
.انزاكشج
: الحاالت التالية غير مسموح بها:مالحظة
MOV [1000] , [DI]
MOV [BX], [DI] NOT ALLOWED (no memory to memory operation)
MOV [100H], [200H]
MOV DS, [DI] NOT ALLOWED (segment registers can NOT be used with memory)
.Indirect Addressing Mode يدًٕػح يٍ االيثهح انًرُٕػح ػهٗ انـٙ اندذٔل انرانٙف
5) Register Relative Addressing Mode
. داخم االقٕاط انًشتؼحoffsetرى اعرخذاو عدم يغ سقى الػطاء انـٚ ْزا انُٕعٙف
MOV Destination, [Register + Displacement]
MOV [Register + Displacement], Source
where the displacement is any 16-bit number.
:ّ يٍ انزاكشجٛ انًطهٕب انزْاب انٙائٚضٛح زغاب انؼُٕاٌ انفٛفٛك
.66 ٙ تؼذ ضشتّ فsegmentرى خًؼّ يغ انـٚ ٙ ٔتانرانoffsetٍ ْٕ انـٍٛ انًشتؼٍٛ انقٕعٛرى اػرثاس كم يا يٕخٕد تٚ
segment-offset (ٍ يٍ خالل انشخٕع انٗ خذٔل انـٍٛ انقٕعٛ يٍ َٕع انغدم انًغرخذو تsegmentًكٍ يؼشفح انـٚٔ
ٌ ٔارا كاDS ْٕ segment فانـSI ٔ أDI ٔ أBX ْٕ )offset( فارا كاٌ انغدم انًغرخذو كًإشش,)combinations
.SS ْٕ segment فانـBP ْٕ )offset( انغدم انًغرخذو كًإشش
Example: Let BX=100H, DS=200H, find the value of AX after executing the following
instruction (the memory is given in the question): MOV AX, [BX+1000H]
9AH 03102H
70H 03101H
11H 03100H
F5H 030FFH
Solution:
PA= DS * 16 + BX + 1000H
PA = 2 0 0 0
0100
1000 +
03100H
⸫ After execution, AX = 7011 H
: يثال,ٍضا ً يًكٚ خاسج االقٕاط انًشتؼح ْٔزا اdisplacementرى ٔضغ انـٚ تؼض انًصادسٙ ف:مالحظة
MOV [BX]+1234H , AL
:ٙ كانران,تد66 تد أو8 ْٙ ح ْمٛذ طٕل انؼًهٚدة ذسذٛ زانح اعرخذاو ْزا انُٕع يٍ انؼَُٕح يغ سقى فٙ ف:مالحظة
MOV byte ptr[BX+20H], 4AH One memory location at (DS:BX+20H) will be given the
value 4AH.
MOV word ptr[BX+20H],5A12H Two memory locations will be changed as follows:
(DS: BX+20H) will be given the value (12H)
(DS:BX+26H) will be given the value (5AH)
MOV byte ptr[BX+20H],5A12H NOT ALLOWED (can you know why?)
6) Base-Plus-Index Addressing Mode (or Base-Indexed Addressing Mode)
:offset) إلػطاء انـDI ٔ أSI ( خشٜ) ٔاBX ٔ أBP( ٍ أزذًْاٛرى اعرخذاو عدهٚ ْزا انُٕعٙف
MOV destination , [ Base Register + Index Register ]
MOV [ Base Register + Index Register ] , source
where:
Base Registers are: BX and BP
Index Registers are: SI and DI
:ّ يٍ انزاكشجٛ انًطهٕب انزْاب انٙائٚضٛح زغاب انؼُٕاٌ انفٛفٛك
BP ارا ذى اعرخذاو انـْٙٔ يا ػذا زانح ٔازذج, PA ػُذ زغاب انـsegment كـDSرى اعرخذاو انـٚ كم انساالخٙف
. أيثهح ػهٗ ْزا انُٕعٙ اندذٔل انرانٙ ف.PA ػُذ زغاب انـsegment ْٕ انـSSؼرثش انـٚ فؼُذْا
Example: Let BX=AF00H
SI = 1FABH
DS=8000H
SP=F43EH
SS=15FFH
Give the memory locations that will be changed after executing the following instruction:
MOV [BX+SI], SP
Solution:
PA= 8CEABH (can you verify this?)
F4H 8CEACH
3EH 8CEABH
Note: if the instruction is modified to: MOV [BP + SI], SP
then the PA is calculated using SS instead of DS.
7) Base Relative-Plus-Index Addressing Mode
تاإلضافح,offset) إلػطاء انـDI ٔ أSI ( خشٜ) ٔاBX ٔ أBP( ٍ أزذًْاٛرى اعرخذاو عدهٚ ْزا انُٕع يٍ انؼَُٕحٙف
.ٍٍٛ انغاتقٛ أ٘ أٌ ْزا انُٕع ْٕ زاصم ديح انُٕػ,ًٓاٛضاف انٚ انٗ سقى
MOV destination , [ Base Register + Index Register + displacement]
MOV [ Base Register + Index Register + displacement] , source
where:
Base Registers are: BX and BP
Index Registers are: SI and DI
Displacement is any 16-bit number
:ّ يٍ انزاكشجٛ انًطهٕب انزْاب انٙائٚضٛح زغاب انؼُٕاٌ انفٛفٛك
BP ارا ذى اعرخذاو انـْٙٔ يا ػذا زانح ٔازذج, PA ػُذ زغاب انـsegment كـDSرى اعرخذاو انـٚ كم انساالخٙف
ًحٛ قْٙٔ انزاكشجٍٙ قٕعًٛح يا يٕخٕد تٛ قٙٓ فoffsetًح انـٛ أيا ق.PA ػُذ زغاب انـsegment كـSSغرخذو انـٚ فؼُذْا
.)displacement( ًح انشقىٛ صائذا ً قBase Registerًح انـٛ صائذا ً قIndex Registerانـ
Example:
Let DS= 1000H, SS= 50FFH, ES= 9A00H, BX= 20H, SI= 10H, find the value of AX after
executing the following instruction (the memory is given in the question):
MOV AX, [BX + SI + 100H]
67H 10133H
7BH 10132H
ACH 10131H
DH 10130H
81H 1012FH
Solution:
PA= DS * 16 + (BX + SI + 100H) = 10130 H
⸫ AX = AC0DH
Note: if the instruction is modified to: MOV AX, [BP + SI + 100H]
then the PA is calculated using SS instead of DS as the segment.
*****
Notice that all the tables and some examples are from the reference book (The Intel
Microprocessors)- chapter 3.
Best Regards
Dr. Zainab Alomari