0% found this document useful (0 votes)
9 views13 pages

Al - Data Transfer

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views13 pages

Al - Data Transfer

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 13

ASSEMBLY LANGUAGE

DATA TRANSFER INSTRUCTIONS


Introduction

• Syllabus will only cover MOV, XCHG


instructions
MOV Instruction

• In JAVA or C++, assignments are


x = 42;
y = 24;
z = x + y;
• How do we represent in assembly lang?
MOV Instruction

mov x, 42
mov y, 24
add z, x
add z, y

• The mov instruction allows the placing of a number


in a register or a memory location
( a var)
• mov destination, source
• Data is merely copied from the source to the
destination, so the source operand is not changed
MOV Instruction

• Possible combinations of operands:


mov reg, reg
mov reg, immediate
mov reg, memory
mov memory, immediate
mov memory, reg
MOV Instruction

• Example: Store the ASCII code for letter A


in register bx.
mov bx, 65d
mov bx, 41h
mov bx, 01000001b
mov bx, ‘A’

• The binary number representing the ASCII


code of A is copied to the bx register.
MOV Instruction

• The value is copied to the right hand side of


the register ie the low order byte of the
register. The left hand side will contain all
the 0’s……..thus
41H

BX = 0041
MOV Instruction
• The mov instruction also allows us to copy
contents of one register into another register.
• Register operands
– A move involving only registers is the fastest
type.
– Registers should be used when an instruction
must execute quickly.
– Any registers may be used as a source operand,
and any register except CS and IP may be
destination operands,
• Mov ax,bx
• Mov dl, al
• Mov bx,cs
MOV Instruction

• Example:
mov bx, 2
mov cx, bx

• Another example:
mov bx, 4; copy number 4 into register bx
mov ax, bx; copy contents of bx into ax
mov cx, ax; copy contents of ax into cx
Limitations of MOV
• An immediate value cannot be moved into a
segment register directly (ie mov ds, 10)
• Segment registers cannot be copied directly (ie
mov es, ds)
• A memory location cannot be copied into another
memory location
(ie mov aNumber, aDigit).
• CS and IP cannot be destination operands
• The source and destination operands must be the
same size.
• If the source is immediate data, it must not exceed
255(FFh) for an 8-bit destination or 65,535
(FFFFh) for a 16-bit destination.
XCHG Instruction
• Swaps two values . The general form is
xchg operand1, operand2
• Can be in the following form:
xchg reg, mem
xchg reg, reg
• The order of the operand is not important
ie xchg ax, bx == xchg bx, ax
• xchg instruction does not modify any flags
XCHG Instruction

• This instruction provides a speed


advantage (especially in sorting
applications).
• Example:
mov ax, 24h ; copy 24h into ax
mov bx, 23h ; copy 23h into bx
xchg ax, bx ; swaps the value of ax and bx
Exercise

1) Write instructions to:


• Load 26 (decimal) into register cx
• Copy contents of ax to bx and dx
2) What errors are present in the following :
• mov ax 3d
• mov 23, ax
• mov cx, ch
• move ax, 1h

You might also like