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

Lecture 4 mciroprocessor

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views

Lecture 4 mciroprocessor

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 30

ADDRESSING MODES

Lecture 4
LECTURE OUTLINE
 Data-addressing modes
o Register Addressing
o Immediate Addressing
o Direct Addressing
o Register indirect Addressing
o Base-plus-index Addressing
o Register Relative Addressing
o Relative-plus-index Addressing
o Scaled index Addressing
FIGURE 3–2 8086–Core2 data-addressing modes.
3- DIRECT ADDRESSING
 Applied to many instructions in a typical program.
Address is formed by adding the displacement to the default data
segment address or an alternate segment address.
The MOV AL,[1234H] instruction, loads AL from the data segment
memory location (1234H) .
The MOV AL,DATA instruction, as represented by most assemblers,
loads AL from the data segment memory location DATA (1234H).
- Memory location DATA is a symbolic memory location, while the
1234H is the actual hexadecimal location.
FIGURE 3–5 The operation of the MOV AL,[1234H] instruction when DS = 1000H.

 This instruction transfers a copy of the byte-sized 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) in a system operating in the real mode.
TABLE 3–4 EXAMPLES OF DIRECT DATA ADDRESSING.
4- REGISTER INDIRECT ADDRESSING

 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.
FIGURE 3–6 The operation of the MOV AX,[BX] instruction when BX = 1000H and DS = 0100H.
Note that this instruction is shown after the contents of memory are transferred to AX.

*After DS is appended with a 0.


The data segment is used by default with register indirect addressing or any other
addressing 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.
When using a 32-bit register to address memory in the real mode, the contents of the
32-bit register must never exceed 0000FFFFH.
 In the protected mode, any value can be used in a 32-bit register that is used to
indirectly address memory
- as long as it does not access a location outside of the segment, as dictated by the
access rights byte.
 In the 64-bit mode, the segment registers are not used in the address calculation
because the register contains the actual linear memory address.
TABLE 3–5 EXAMPLES OF REGISTER INDIRECT ADDRESSING.
5- BASE-PLUS-INDEX ADDRESSING
 Similar to indirect addressing because it indirectly addresses memory
data.
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.
Locating Data with Base-Plus-Index Addressing.

 Figure 3–8 shows how data are addressed by the MOV DX,[BX+DI]
instruction when the microprocessor operates in the real mode.
FIGURE 3–8 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 =
100H, and DI = 0010H.
Locating Array Data with Base-Plus-Index Addressing.

A major use of the base-plus-index addressing mode 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.
 Figure 3–9 shows the use of BX and DI to access an element in an array of
data.
FIGURE 3–9 An example of the base-plus-index addressing mode. Here an element (DI) of an
ARRAY (BX) is addressed.
TABLE 3–6 EXAMPLES OF BASE-PLUS-INDEX ADDRESSING.
6- REGISTER RELATIVE ADDRESSING
The data in a segment of memory are addressed adding the
displacement to the contents of a base or an index register (BP, BX, DI,
or SI).
Figure 3–10 shows the operation of the MOV AX,[BX+1000H]
instruction.
Remember that BX, DI, or SI addresses the data segment and BP
addresses the stack segment.
In the 80386 and above, the displacement can be a 32-bit number
and the register can be any 32-bit register except the ESP register.
Remember that the size of a real mode segment is 64K bytes long.
FIGURE 3–10 The operation of the MOV AX, [BX+1000H] instruction, when and DS =
0200H. BX = 0100H BX+1000H
The displacement is a number added to the register within the [ ], as in
the MOV AL,[DI+2 ] instruction, or it can be a displacement is subtracted
from the register, as in MOV AL,[SI–l].
A displacement also can be an offset address appended to the front
of the [ ], as in MOV AL,DATA[DI].
Both forms of displacements also can appear simultaneously, as in the
MOV AL,DATA[DI+3] instruction. Both forms of the displacement add to
the base or base plus index register within the [ ] symbols
TABLE 3–7 EXAMPLES OF REGISTER RELATIVE ADDRESSING.
Addressing Array Data with Register Relative.

It is possible to address array data with register relative addressing


- such as with base-plus-index addressing.
 In Figure 3–11, 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.
FIGURE 3–11 Register relative addressing used to address an element of ARRAY. The displacement
addresses the start of ARRAY, and DI accesses an element.
7- BASE RELATIVE-PLUS-INDEX ADDRESSING

 Similar to base-plus-index addressing, but it adds a displacement,


besides using 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
Addressing Data with Base Relative-Plus-Index.

least-used addressing mode.


Figure 3–12 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.
FIGURE 3–12 An example of base relative-plus-index addressing using a MOV AX,[BX+SI+100H]
instruction. Note: DS = 1000H.
Addressing Arrays with Base Relative-Plus-Index

Suppose that a file of many records exists in memory and each record
contains many elements.
- The displacement addresses the file, the base register addresses a
record, and the index register addresses an element of a record.
 Figure 3–13 illustrates this very complex form of addressing.
FIGURE 3–13 Base relative plus-index addressing used to access a FILE that contains
multiple records (REC).
TABLE 3–8 EXAMPLE BASE RELATIVE-PLUS-INDEX INSTRUCTIONS.
8- SCALED-INDEX ADDRESSING
Unique to the 80386 through the Core2 microprocessors.
- 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.
- The scaling factor can be 1x, 2x, 4x, or 8x.
 A scaling factor of 1x is implied and need not be included in the
assembly language instruction (MOV AL,[EBX+ECX]).
TABLE 3–9 EXAMPLES OF SCALED-INDEX ADDRESSING.

You might also like