Addresing Mode
-
Upload
fatta-b-stue -
Category
Documents
-
view
220 -
download
0
Transcript of Addresing Mode
-
7/31/2019 Addresing Mode
1/52
Addressing Modes
A Course in MicroprosessorElectrical Engineering Department
University of Indonesia
-
7/31/2019 Addresing Mode
2/52
Data Addressing Modes
Fig.3.1 illustrates the MOV instruction anddefines the direction of data flow
Fig.3.2 shows all possible data variations of
the data-addressing modes using the MOVinstruction
Register adressing: MOV CX,DX or
MOV ECX,EDX Immediate addressing: MOV AL,22H or
MOV EAX,12345678H
Direct addressing: MOV CX,LIST
-
7/31/2019 Addresing Mode
3/52
Data Addressing Modes (contd)
Base-plus-index adressing:MOV [BX+DI], CL or MOV [EAX+EBX],CL
Register relative addressing:
MOV AX,[BX+4] or MOV AX,ARRAY[BX]
Base relative-plus-index addressing:MOV AX,ARRAY[BX+DI] or
MOV AX,[BX+DI+4]
Scaled-index addressing:MOV EDX,[EAX+4*EBX]
-
7/31/2019 Addresing Mode
4/52
Register Addressing
It is the most common form and is theeasiest to apply
Microprocessor contains 8-bit, 16-bit, 32-bit
registers Never mix an 8-bit register with a 16-bit register,
16-bit register with a 32-bit register, etc.,because this results in an error when assembled
Table 3.1 shows many variations of registermove instructions
Fig.3.3 shows the operation of the MOVBC,CX instruction
-
7/31/2019 Addresing Mode
5/52
Register Addressing
Example 3.1 shows a sequence ofassembled instructions that copy variousdata between 8-, 16-, and 32-bit registers
-
7/31/2019 Addresing Mode
6/52
Immediate Addressing
The term immediate implies that the dataimmediately follow the hexadecimal opcodein the memory
Immediate are constant data The MOV immediate instruction transfers a copy
of the immediate data into a register or a
memory location Fig.3.4 shows the source data (sometimes
preceded by #) overwrite the destination data
The instruction copies the 13456H into registerAX
-
7/31/2019 Addresing Mode
7/52
Register Addressing
Example 3.2 shows various immeidateinstructions in a short program that placess a0000H into the 16-bit registers AX, BX, CX
-
7/31/2019 Addresing Mode
8/52
Direct Data Addressing
There two basic forms of direct dataaddressing:
direct addressing, which applies to a MOV bet-
ween a memory location and AL, AX or EAX displacement addressing, which applies to
almost any instruction in the instruction set
Direct Addressing: MOV AL,DATA (Fig.3.5) Table 3.3 lists the three direct addressed instruc-
tion
A MOV instruction is 3-byte long instruction
-
7/31/2019 Addresing Mode
9/52
Direct Data Addressing
Displacement Addressing: MOV CL,DATA
almost identical with direct addressing exceptthat the instruction is four bytes wide
-
7/31/2019 Addresing Mode
10/52
Register Indirect Addressing
It allows data to be addressed at any memorylocation through an offset address held in any ofthe following register: BP, BX, DI, and SI
MOV AX,[BX] Fig.3.6
Data segment is used by default with registerindirect addressing or any other addressing modethat uses BX, DI, or SI to address memory
If register BP addresses memory, the stack segment isused by default
-
7/31/2019 Addresing Mode
11/52
Register Indirect Addressing
Sometimes, indirect addressing requires spe-cifying the size of the data with the specialassembler directive BYTE PTR, WORD PTR
or DWORD PTR These indicate the size of the memory data
addressed by the memory pointer (PTR)
Indirect addressing allows a program to referto a tabular data located in the memory sys-tem (Fig.3.7 & Example 3.6)
-
7/31/2019 Addresing Mode
12/52
Base-Plus-Index Addressing
It indirectly addresses memory data In 8086 - 80286, this use a base register (BP or
BX, holds the beginning location of a memory
array) and an index register (DI or SI, ) toindirectly addresses memory
In 80386 and above, this type of addressingallows the combination of any two 32-bit
extended registers except #SP MOV DL, [EAX+EBX]
Figure 3.8 shows the sample instruction of
locating data with this scheme
-
7/31/2019 Addresing Mode
13/52
Base-Plus-Index Addressing (contd)
The major use of this type of addressing is toaddress elements in a memory array
Fig.3.9 shows the use of BX (base) and DI
(index) to access an element in an array of data) Study Table 3.6 and Example 3.7 as well
-
7/31/2019 Addresing Mode
14/52
Register Relative Addressing
In its, the data in a segment of memory areaddressed by adding the displacement to thecontents of a base ro and index register (BP,
BX, DI, or SI) Fig.3.10 shows the operation of the MOV AX,[BX+
1000H] instruction
The displacement can be a number added tothe register within the [ ], as in MOV AL,[DI+2], orit can be a displacement substracted fromthe register, as in MOV AL,[SI-1]
-
7/31/2019 Addresing Mode
15/52
Register Relative Addressing (contd)
It is possible to address array data with regis-ter relative addressing such as one does withbase-plus-index addressing
See Fig.3.11 and study the example 3.8
-
7/31/2019 Addresing Mode
16/52
Base Relative-Plus-Index
Addressing
This mode often addresses a two-dimension-al array of memory data
It is the least-used addressing mode (i.e., too complexfor frequent use in a program)
Fig.3.12 shows how the instruction MOV AX,[BX+SI+100H]
Addressing arrays with base relative-plus-
index addressing the displacement addresses the file the base register addresses a record
the index register addresses an element of a record
Study Example 3.9 and Fig.3.13
-
7/31/2019 Addresing Mode
17/52
Scaled-Index Addressing
This type of addressing is unique to the80386 - Pentium Pro
It uses two 32-bit registers (a base register and
an index register) to access the memory The second register (index) is multiplied by a
scaling factor (either 1X, 2X, 4X, or 8X)
MOV AX,[EDI+2*ECX] See Example 3.10 and Table 3.9
-
7/31/2019 Addresing Mode
18/52
Data Structures
A data structure is used to specify howinformation is stored in a memory array; itcan be quite useful with application that use
arrays The start of a structure is identified with the
STRUC directive and ended with the ENDS
See Example 3.11
When data are addressed in a structure, usethe structure name and the field name to se-lect a field from the structure (Example 3.12)
-
7/31/2019 Addresing Mode
19/52
Program Memory Addressing
Program memory-addressing modes (JMPand CALL) consist of three distinct forms:direct, relative, and indirect
Direct Program Memory Addressing The instruction store the address with the op-
code
P M Add i
-
7/31/2019 Addresing Mode
20/52
Program Memory-Addressing
Modes
Program memory-addressing modes (JMPand CALL) consist of three distinct forms:direct, relative, and indirect
Direct Program Memory Addressing The instructions store the address with the op-
code
See Fig.3.14 It is called a far jump because it can jump to any
memory location for the next instruction
-
7/31/2019 Addresing Mode
21/52
Program Memory Addressing Modes (contd)
Relative Program Memory Addressing The term relativemeans relative to the IP
See Fig.3.15
JMP instruction is a one-byte instruction with aone-byte or two-byte displacement that adds tothe instruction pointer
Relative JMP and CALL instructions containeither an 8-bit or a 16-bit signed displacementthat allows a forward memory reference or areverse memory reference
-
7/31/2019 Addresing Mode
22/52
Program Memory Addressing Modes (contd)
Indirect Program Memory Addressing Table 3.10 lists some acceptable indirect
program jump instructions, which can use any
16-bit register, any relative register, and any re-lative register with a displacement
If a 16-bit register holds the address of a JMPinstruction, the jump is near
If a relative register holds the address, the jumpis also considered an indirect jump
Fig.3.16 shows a jump table that is stored begin-
ning at memory location TABLE
St k M Add i
-
7/31/2019 Addresing Mode
23/52
Stack Memory-Addressing
Modes
Stack holds data temporarily and storesreturn addresses for procedures
The stack memory is LIFO memory
Use PUSH instruction to place data onto stack Use POP instruction to remove data from stack
The stack memory is maintained by two
registers: SP or ESP, and SS Study Fig.3.17
The PUSHA and POPA either push or pop all of
the register, except the segment register, on the
-
7/31/2019 Addresing Mode
24/52
-
7/31/2019 Addresing Mode
25/52
-
7/31/2019 Addresing Mode
26/52
-
7/31/2019 Addresing Mode
27/52
-
7/31/2019 Addresing Mode
28/52
-
7/31/2019 Addresing Mode
29/52
-
7/31/2019 Addresing Mode
30/52
-
7/31/2019 Addresing Mode
31/52
-
7/31/2019 Addresing Mode
32/52
-
7/31/2019 Addresing Mode
33/52
-
7/31/2019 Addresing Mode
34/52
-
7/31/2019 Addresing Mode
35/52
-
7/31/2019 Addresing Mode
36/52
-
7/31/2019 Addresing Mode
37/52
-
7/31/2019 Addresing Mode
38/52
-
7/31/2019 Addresing Mode
39/52
-
7/31/2019 Addresing Mode
40/52
-
7/31/2019 Addresing Mode
41/52
-
7/31/2019 Addresing Mode
42/52
-
7/31/2019 Addresing Mode
43/52
-
7/31/2019 Addresing Mode
44/52
-
7/31/2019 Addresing Mode
45/52
-
7/31/2019 Addresing Mode
46/52
-
7/31/2019 Addresing Mode
47/52
-
7/31/2019 Addresing Mode
48/52
-
7/31/2019 Addresing Mode
49/52
-
7/31/2019 Addresing Mode
50/52
-
7/31/2019 Addresing Mode
51/52
-
7/31/2019 Addresing Mode
52/52