Professional Documents
Culture Documents
(c) Pearson Education, 2003. All rights reserved. You may modify and copy this slide show for your personal use, or for
use in the classroom, as long as this copyright statement, the author's name, and the title are not changed. Irvine, Kip R. Assembly Language for Intel-Based Computers, 2003. 2
Irvine, Kip R. Assembly Language for Intel-Based Computers, 2003. 3 Irvine, Kip R. Assembly Language for Intel-Based Computers, 2003. 4
alternate format
Irvine, Kip R. Assembly Language for Intel-Based Computers, 2003. 5 Irvine, Kip R. Assembly Language for Intel-Based Computers, 2003. 6
1
MOV Instruction Your turn . . .
• Move from source to destination. Syntax: Explain why each of the following MOV statements are invalid:
MOV destination,source
• No more than one memory operand permitted .data
• CS, EIP, and IP cannot be the destination bVal BYTE 100
bVal2 BYTE ?
• No immediate to segment moves wVal WORD 2
dVal DWORD 5
.data .code
count BYTE 100 mov ds,45 immediate move to DS not permitted
wVal WORD 2 mov esi,wVal size mismatch
.code mov eip,dVal EIP cannot be the destination
mov bl,count immediate value cannot be destination
mov 25,bVal
mov ax,wVal
mov count,al mov bVal2,bVal memory-to-memory move not permitted
Irvine, Kip R. Assembly Language for Intel-Based Computers, 2003. 7 Irvine, Kip R. Assembly Language for Intel-Based Computers, 2003. 8
Irvine, Kip R. Assembly Language for Intel-Based Computers, 2003. 9 Irvine, Kip R. Assembly Language for Intel-Based Computers, 2003. 10
Irvine, Kip R. Assembly Language for Intel-Based Computers, 2003. 11 Irvine, Kip R. Assembly Language for Intel-Based Computers, 2003. 12
2
Direct-Offset Operands (cont) INCLUDE irvine32.inc
.data
A constant offset is added to a data label to produce an arrayW WORD 1000h,2000h,3000h
effective address (EA). The address is dereferenced to get the arrayD DWORD 1,2,3,4
value inside its memory location. .code
main PROC
.data mov esi,OFFSET arrayW-2 ; display some memory
arrayW WORD 1000h,2000h,3000h
mov ecx,LENGTHOF arrayW+1
arrayD DWORD 1,2,3,4
.code mov ebx,TYPE arrayW
mov ax,[arrayW+2] ; AX = 2000h call DumpMem
mov ax,[arrayW+4] ; AX = 3000h mov esi,OFFSET arrayD ; display some memory
mov eax,[arrayD+4] ; EAX = 00000002h mov ecx,LENGTHOF arrayD+1
mov ebx,TYPE arrayD
; Will the following statements assemble?
call DumpMem
mov ax,[arrayW-2] ; ??
mov eax,[arrayD+16] ; ?? exit
main ENDP
What will happen when they run?
END main
Irvine, Kip R. Assembly Language for Intel-Based Computers, 2003. 13 Irvine, Kip R. Assembly Language for Intel-Based Computers, 2003. 14
Your turn. . .
Write a program that rearranges the values of three doubleword
values in the following array as: 3, 1, 2.
.data
arrayD DWORD 1,2,3
• Step1: copy the first value into EAX and exchange it with the
value in the second position.
mov eax,arrayD
xchg eax,[arrayD+4]
• Step 2: Exchange EAX with the third array value and copy the
value in EAX to the first array position.
xchg eax,[arrayD+8]
mov arrayD,eax