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

l3 Data Addressing

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

l3 Data Addressing

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

Lecture #3,4

Data Addressing Modes

Dr. Gouda Ismail


Data-Addressing Modes
Data-Addressing Modes: Variations in the way
instructions are used. There are 8 different data-
addressing modes:
1. Register Addressing
2. Immediate Addressing
3. Direct Addressing
4. Register Indirect Addressing
5. Base-Plus-Index Addressing
6. Register Relative Addressing
7. Base Relative-Plus-Index Addressing
8. Scaled-Index Addressing
Dr. Gouda Ismail
1- Register Addressing
 Uses the 8-bit general registers: ah, al, bh, bl, ch, cl, dh, and
dl
 The 16-bit general registers: ax, bx, cs, dx, sp, bp, si, and di
 The 32-bit registers: eax, ebx, ecx, edx, esp, ebp, edi, and
esi
 And the 16-bit segment registers: cs, ds, ss, and es
 Cannot do segment-to-segment register mov's
 Also cannot change cs (code segment) register with a mov
 Example:

mov cx,dx ; Copies the word-sized contents of register


; dx into register cx
AH AL

Dr. Gouda Ismail


2- Immediate Addressing
 Operates upon a byte or word of data (or dword in
386/486)
 Transfers a copy of the immediate data into a
register or a memory location.
 Use hex and binary number conventions (H or h for
hex, B or Y for binary numbers), otherwise the
number is interpreted as decimal.

Example:
mov al,22h ; Copies the byte-size data value
22h into
; register al

Dr. Gouda Ismail


3- Direct Data Addressing
 Uses symbolic memory locations (variables) or absolute memory
locations.
 Note that with the mov instruction, transfers must involve
memory within the data segment and the al, ax, or eax register.
 Examples:

mov al,number ;copies the byte contents of memory


;address number located
; in the data segment into a
mov there,ax ; copies ax into memory location there in the
;data segment
mov ch,[1000H] ; copies the contents of memory location
;1000H from the data segment into register
;ch.

Dr. Gouda Ismail


4- Register Indirect Addressing
 Allows data to be addressed at any memory location through the
bp,bx,di, and si registers.
 bx, di, or si registers used to address memory in the data
segment
 bp register used to address memory in the stack segment
 The [] symbols denote indirect addressing.
 offset directive tells the assembler to load a register or memory
location with the offset address of a memory location and not the
contents of the memory location.
 byte ptr, word ptr, dword ptr directives specify the size of the
data
 Examples
mov ax,[bx] ; Copies the word-sized data from the data
; segment offset address pointed to by bx
; into register ax.
mov byte ptr [di],10h ; specifies that the location
; addressed by di is a byte-sized
; memory location
Dr. Gouda Ismail
5- Register Indirect Addressing, cont.

 Example ProgramThis program reads in 50 bytes


of data from DATA_PORT and stores the data in
TABLE
 mov bx,offset table ; address table
mov cx,50 ; load counter
again:
in al,data_port ; read voltmeter
mov [bx],al ; save data
inc bx ; address next
loop again ; repeat 50 times

Dr. Gouda Ismail


5- Base-Plus-Index Addressing

 Uses one base register (bp or bx) and one index register (di or si) to
indirectly address memory.
 Used often with arrays: base register holds the beginning location of a
memory array and the index register holds the relative position of an
array element.
 Examples: Loading data with Base-Plus-Index Addressing

mov cx,[bx+di] ; The word contents of the memory


; location address by bx plus di
; within the data segment are copied
; into register cx.
mov ch,[bp+si] ; The byte contents of the memory
; location addressed by bp plus si
; within the stack segment are copied
; into register ch.
mov [bx+si],sp ; The word contents of sp are stored
; in the data segment at the location
; addressed by bx plus si.

Dr. Gouda Ismail


Base-Plus-Index Addressing Cont.
 Locating array data using Base-Plus-Index AddressingLoad bx
with the beginning address of the array and di with the element
number to be accessed.
 Example

mov bx,offset array ; load bx with the starting address of array


mov dl,10H ; load di with 10H which is the element
; number of array
mov al,[bx+di] ; transfer word contents of memory
; location bx + di into register al
mov di,20H ; load di with element 20H
mov [bx+di],al ; load contents of register al into memory
; location address bx + di

Dr. Gouda Ismail


Base-Plus-Index Addressing Cont.
 Effective address computed as:
seg_base + base + index.
 Base registers: Holds starting location of an array.
 ebp (stack)
 ebx (data)
 Any 32-bit register except esp.
 Index registers: Holds offset location.
 edi
 esi
 Any 32-bit register except esp .

Dr. Gouda Ismail


Base-Plus-Index Addressing Cont.

Dr. Gouda Ismail


6- Register Relative 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).
 Displacement can be an number added or subtracted to the register
within the [].
 It can also be an offset address appended to the front of the [].
 Examples
mov al,[di+2] ; displacement is a number added to the register
mov al,[si-2] ; displacement is a number subtracted to the register
mov al,data[di] ; displacement is an offset address
mov al,data[di+3] ; displacement offset address and a number added
; to the register
mov array[si]bl ; byte contents of bl is copied into the location
; addressed by array plus si
mov list[si+2],cl ; byte contents of cl is copied into the location
; addressed by si plus 2

Dr. Gouda Ismail


Register Relative addressing Cont.
 Effective address computed as:
 seg_base + base + constant.
 Same default segment rules apply with respect to ebp ,
ebx , edi and esi .
 Displacement constant is any 32-bit signed value.

Dr. Gouda Ismail


7- Base Relative-Plus-Index
addressing
 Effective address computed as:
 seg_base + base + index + constant.
 Designed to be used as a mechanism to address a
two-dimensional array.

Dr. Gouda Ismail


Base Relative-Plus-Index addressing
cont.

Dr. Gouda Ismail


8- Scaled-Index addressing
 Effective address computed as:
 seg_base + base + constant*index.

Dr. Gouda Ismail


Question

 Suppose that DS=1100H, EAX=00001000H,


EBX=00002000H, LIST=0250H, and
SI=0500H, determine the address accessed
and state the used addressing mode by each
of the following instructions:
EAX
 MOV CL, LIST[BX+SI] 12 34 56 78
 MOV CH, [BX+SI] AX
12 34
 MOV AL, [1234H]
AH AL

Dr. Gouda Ismail


Solution
 MOV CL,LIST[BX+SI]
Addressing Mode : base relative-plus-Index addressing mode

Effective address=DS*10+LIST+BX+SI
= 11000 +2000+ 0250 + 0500=13750

1374D 78 CH CL
1374E 78
12
1374F 34
13750 12

Dr. Gouda Ismail


 MOV CL,LIST[BX+SI]
 Addressing Mode : base plus-Index addressing mode
 Effective address=DS*10+LIST+BX+SI
 = 11000 +2000+ 0500=13500

134FD CH CL
134FE
33
134FF
13500 33

Dr. Gouda Ismail


 MOV AL, [15500H]
 Addressing Mode : direct addressing mode

155FD AH AL
155FE
55
155FF
15500 55

Dr. Gouda Ismail

You might also like