Answers: Indirect and Indexed Operands

Use the following data declarations. Assume that the offset of byteVal is 0000:

.data
byteVal  db 1,2,3,4
wordVal  dw 1000h,2000h,3000h,4000h
dwordVal dd 12345678h,34567890h
aString  db "ABCDEFG",0
pntr     dw wordVal

 

1. Indicate whether or not each of the following instructions is valid:

(notate: V = valid, I = invalid)

  
a.
mov  ax,byteVal[si]
  
I (operand size mismatch) 
b.
add  dx,[cx+wordVal]
  
I (CX is not a base 
or index register)
c.
mov  ecx,[edi+dwordVal]
  
V
d.
xchg al,[bx]
  
V
e.
mov  ax,[bx+4]
  
V
f.
mov  [bx],[si]
  
I (memory to memory 
   not permitted)
g.
xchg al,byteVal[dx]
I (DX is not a base 
or index register)

 

2. Indicate the hexadecimal value of the final destination operand after each of the following code fragments has executed:

(If any instruction is invalid, indicate "I" as the answer.)

  
a.
mov si,offset byteVal
mov al,[si+1]
  
2 
b.
mov di,6
mov dx,wordVal[di]
  
4000h
c.
mov bx,4
mov ecx,[bx+dwordVal]
  
34567890h
d.
mov si,offset aString
mov al,byteVal+1
mov [si],al
  
2
e.
mov si,offset aString+2
inc byte ptr [si]
  
44h('D')
f.
mov bx,pntr
add word ptr [bx],2
  
1002h
g.
mov di,offset pntr
mov si,[di]
mov ax,[si+2]
2000h

 

3. Indicate the hexadecimal value of the final destination operand after each of the following code fragments has executed:

(If any instruction is invalid, indicate "I" as the answer.)

  
a.
xchg si,pntr
xchg [si],wordVal
  
I (memory to memory 
not permitted)
b.
mov  ax,pntr
xchg ax,si
mov  dx,[si+4]
  
dx = 3000h
c.
mov edi,0
mov di,pntr
add edi,8
mov eax,[edi]
  
12345678h 
d.
mov esi,offset aString
xchg esi,pntr
mov  dl,[esi]
  
I (esi and pntr 
have different 
sizes)
e.
mov esi,offset aString
mov dl,[esi+2]
  
43h ('C')