0% found this document useful (0 votes)
50 views11 pages

16 Microprocessor Systems Lecture No 16 Indirect Addressing

This document discusses indirect addressing in microprocessor-based systems. It describes how indirect operands hold the address of a variable like an array or string and can be dereferenced like a pointer. It provides examples of using indirect operands to traverse arrays and indexed operands that add a constant to a register to generate an effective address. It also discusses pointers, which contain the offset of another variable, and how they can be used to manipulate arrays and data structures. Finally, it introduces the TYPEDEF operator for creating user-defined pointer types.

Uploaded by

Muhammad Zubair
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)
50 views11 pages

16 Microprocessor Systems Lecture No 16 Indirect Addressing

This document discusses indirect addressing in microprocessor-based systems. It describes how indirect operands hold the address of a variable like an array or string and can be dereferenced like a pointer. It provides examples of using indirect operands to traverse arrays and indexed operands that add a constant to a register to generate an effective address. It also discusses pointers, which contain the offset of another variable, and how they can be used to manipulate arrays and data structures. Finally, it introduces the TYPEDEF operator for creating user-defined pointer types.

Uploaded by

Muhammad Zubair
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/ 11

Microprocessor Based

Systems
Lecture No 16 Indirect Addressing

By Nasir Mahmood
This Lecture
Indirect Addressing
  Indirect Operands

  Arrays

  Indexed Operands

  Pointers

  Book Reading “Assembly Language for x86 Processors” 6th


Edition By Kip R. Irvine
  Section 4.4
Indirect Operands (1 of 2)
An indirect operand holds the address of a variable, usually
an array or string. It can be dereferenced (just like a pointer).
.data
val1 BYTE 10h,20h,30h
.code
mov esi,OFFSET val1
mov al,[esi] ; dereference ESI (AL = 10h)

inc esi
mov al,[esi] ; AL = 20h

inc esi
mov al,[esi] ; AL = 30h

3
Indirect Operands (2 of 2)
Use PTR to clarify the size attribute of a memory operand.

.data
myCount WORD 0

.code
mov esi,OFFSET myCount
inc [esi] ; error: ambiguous
inc WORD PTR [esi] ; ok

Should PTR be used here? yes, because [esi] could point


to a byte, word, or doubleword
add [esi],20

4
Array Sum Example
Indirect operands are ideal for traversing an array. Note that
the register in brackets must be incremented by a value that
matches the array type.
.data
arrayW WORD 1000h,2000h,3000h
.code
mov esi,OFFSET arrayW
mov ax,[esi]
add esi,2 ; or: add esi,TYPE arrayW
add ax,[esi]
add esi,2
add ax,[esi] ; AX = sum of the array

ToDo: Modify this example for an array of doublewords.

5
Indexed Operands
An indexed operand adds a constant to a register to generate
an effective address. There are two notational forms:
[label + reg] label[reg]
.data
arrayW WORD 1000h,2000h,3000h
.code
mov esi,0
mov ax,[arrayW + esi] ; AX = 1000h
mov ax,arrayW[esi] ; alternate format
add esi,2
add ax,[arrayW + esi]
etc.

ToDo: Modify this example for an array of doublewords.

6
Index Scaling*
You can scale an indirect or indexed operand to the offset of
an array element. This is done by multiplying the index by
the array's TYPE:
.data
arrayB BYTE 0,1,2,3,4,5
arrayW WORD 0,1,2,3,4,5
arrayD DWORD 0,1,2,3,4,5

.code
mov esi,4
mov al,arrayB[esi*TYPE arrayB] ; 04
mov bx,arrayW[esi*TYPE arrayW] ; 0004
mov edx,arrayD[esi*TYPE arrayD] ; 00000004

7
Pointers
•  You can declare a pointer variable that contains the offset of
another variable.
•  Pointers are a great tool for manipulating arrays and data
structures, and they make dynamic memory allocation possible

•  X86 programs use two basic types of pointers


•  The 32-bit mode programs in this book use near pointers

8
Pointers : Example
.data
arrayW WORD 1000h,2000h,3000h
ptrW DWORD arrayW
.code
mov esi,ptrW
mov ax,[esi] ; AX = 1000h

Alternate format:

ptrW DWORD OFFSET arrayW

9
Using the TYPEDEF Operator
  The TYPEDEF operator lets you create a user-defined type that has
all the status of a built-in type when defining variables. TYPEDEF is
ideal for creating pointer variables.
  For example, the following declaration creates a new data type
PBYTE that is a pointer to bytes:
PBYTE TYPEDEF PTR BYTE
  This declaration would usually be placed near the beginning of a
program, before the data segment. Then, variables could be defined
using PBYTE:

.data
arrayB BYTE 10h,20h,30h,40h
ptr1 PBYTE ? ; uninitialized
ptr2 PBYTE arrayB ; points to an array
THE END

You might also like