You are on page 1of 3

Chapter Overview

Assembly Language for Intel-Based


Computers, 4th Edition
Kip R. Irvine • Data Transfer Instructions
• Addition and Subtraction
Chapter 4: Data Transfers, • Data-Related Operators and Directives
• Indirect Addressing
Addressing, and Arithmetic
• JMP and LOOP Instructions

(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

Data Transfer Instructions Operand Types

• Operand Types • Three basic types of operands:


• Instruction Operand Notation • Immediate – a constant integer (8, 16, or 32 bits)
• value is encoded within the instruction
• Direct Memory Operands
• Register – the name of a register
• MOV Instruction
• register name is converted to a number and encoded
• Zero & Sign Extension within the instruction
• XCHG Instruction • Memory – reference to a location in memory
• Direct-Offset Instructions • memory address is encoded within the instruction, or a
register holds the address of a memory location

Irvine, Kip R. Assembly Language for Intel-Based Computers, 2003. 3 Irvine, Kip R. Assembly Language for Intel-Based Computers, 2003. 4

Instruction Operand Notation Direct Memory Operands


• A direct memory operand is a named reference to
storage in memory
• The named reference (label) is automatically
dereferenced by the assembler
.data
var1 BYTE 10h
.code
mov al,var1 ; AL = 10h
mov al,[var1] ; AL = 10h

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

mov al,wVal ; error


mov ax,count ; error
mov eax,count ; error

Irvine, Kip R. Assembly Language for Intel-Based Computers, 2003. 7 Irvine, Kip R. Assembly Language for Intel-Based Computers, 2003. 8

Zero Extension Sign Extension


When you copy a smaller value into a larger destination, the The MOVSX instruction fills the upper half of the destination
MOVZX instruction fills (extends) the upper half of the destination with a copy of the source operand's sign bit.
with zeros.
0 10001111 Source 10001111 Source

00000000 10001111 Destination 11111111 10001111 Destination

mov bl,10001111b mov bl,10001111b


movzx ax,bl ; zero-extension movsx ax,bl ; sign extension

The destination must be a register. The destination must be a register.

Irvine, Kip R. Assembly Language for Intel-Based Computers, 2003. 9 Irvine, Kip R. Assembly Language for Intel-Based Computers, 2003. 10

XCHG Instruction Direct-Offset Operands


XCHG exchanges the values of two operands. At least one A constant offset is added to a data label to produce an
operand must be a register. No immediate operands are effective address (EA). The address is dereferenced to get the
permitted. value inside its memory location.
.data
var1 WORD 1000h .data
arrayB BYTE 10h,20h,30h,40h
var2 WORD 2000h
.code
.code
mov al,arrayB+1 ; AL = 20h
xchg ax,bx ; exchange 16-bit regs mov al,[arrayB+1] ; alternative notation
xchg ah,al ; exchange 8-bit regs
xchg var1,bx ; exchange mem, reg
xchg eax,ebx ; exchange 32-bit regs

Q: Why doesn't arrayB+1 produce 11h?


xchg var1,var2 ; error: two memory operands

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

Irvine, Kip R. Assembly Language for Intel-Based Computers, 2003. 15

You might also like