Indirect Addressing

16-bit World

Consider the following assembly program segment:

.data
msga BYTE "hi there",0
msgal WORD msgal-msga
msgb BYTE 10 dup(?)

.code
  mov ax,@data
  mov ds,ax
  mov es,ax
Q#1: What would be the results of executing each of the following statements and what addressing modes are being used?

  mov al,msga
  inc msga
  mov di, OFFSET msga
  mov si, OFFSET msgb
  mov [si],msga
  inc di
  inc si
  mov dx, WORD PTR[di]
Associated with each indirect operand is an offset value from a specified segment. In most cases, the offset is from the DS segment. Let's take a look at the following example:

mov si,bp
add dl,[si]
add bl,[bp]
si specifies an offset from the DS whereas bp specifies an offset from the SP.

We can override the default segment as follows:

add dl,es:[bp]
add ecx,ss:[si]
We can specify a statement of the following form:

mov dl,[bx+1]
Q#2: If bx contains the offset of msg2, what does the statement mov dl,[bx+1] mean?

A huge mistake in the assembly world is the following:

.data
msg BYTE "abc"
num BYTE 1

.code
  mov ax,@data
  mov ds,ax
  mov bx,OFFSET msg
  mov dx,[bx+num]
Q#3: What is the meaning of mov dx,[bx+num]?

32-bit World

.data
v1 BYTE 5
.code
mov esi, OFFSET v1
mov ah,[esi]
Indirect operands are useful when accessing arrays as follow:

.data
arry BYTE 2,4,6,8,10
.code
mov esi, OFFSET arry
mov ah,[esi]
inc esi
mov ah,[esi]
inc esi
mov ah,[esi]
Q#3: How would the above example change if we had arrays of two words?


©Douglas J. Ryan / ryandj@pacificu.edu