You are on page 1of 16

Lecture 2

BASIC INSTRUCTIONS

1 CAP221 10/23/2010
MOV instruction

• Is used to transfer data :


– between registers,
– between a register & a memory location.
Or
– To move a number directly into a register or
memory location.
• Syntax
MOV destination , source

2 CAP221 10/23/2010
Examples:
MOV AX , WORD1
MOV AX , BX
MOV AH , ‘A’

3 CAP221 10/23/2010
XCHG instruction

• (Exchange) operation is used to exchange

the contents of

– two registers, or
– a register and a memory location
– Syntax
XCHG destination , source

4 CAP221 10/23/2010
Examples:
XCHG AH , BL
XCHG AX , WORD1

5 CAP221 10/23/2010
Restrictions on MOV & XCHG
MOV Destination Operand
Source General Segment Memory Constant
Operand Register Register Location
General
Register yes yes yes no
Segment
Register yes no yes no
Memory
Location yes yes no no
Constant yes no yes no

6 CAP221 10/23/2010
Restrictions on MOV & XCHG
XCHG Destination Operand
Source General Memory
Operand Register Location

General
Register yes yes

Memory
Location yes no

7 CAP221 10/23/2010
ADD & SUB

• Are used to add & subtract the contents of

– two registers,
– a register & memory location , or
– add ( subtract ) a number to ( from ) a register or a
memory location.
– Syntax
ADD destination , source

SUB destination , source

8 CAP221 10/23/2010
Example

Examples
ADD WORD1 , AX
SUB AX , DX
ADD BL , 5

9 CAP221 10/23/2010
Legal combinations of operands for
ADD & SUB

Destination operand
Source Operand General Register Memory location

General Register yes yes

Memory location yes no

Constant yes yes

10 CAP221 10/23/2010
INC ( increment )
&DEC ( decrement )

INC: Is used to add 1 to the contents of


a
• Register or
• Memory location
DEC: Is used to subtract 1 from the
contents of a
• Register or
• Memory location
11 CAP221 10/23/2010
Syntax
INC destination
DEC destination

Examples:
INC WORD1
DEC BYTE1

12 CAP221 10/23/2010
NEG

• Is used to negate the contents of the destination.

The destination may be a


register or
memory location.

• It does this by replacing the contents by its


two’s complement.

• Syntax
NEG destination

13 CAP221 10/23/2010
Translation of HLL to
Assembly Language

Statement Translation

A = 5–A MOV AX , 5 ; put 5 in AX


SUB AX , A ; AX…. 5 – A
MOV A , AX ; put it in A

There is another shorter way :

14 CAP221 10/23/2010
NEG A ; A = -A

ADD A , 5 ;A = 5 - A

15 CAP221 10/23/2010
Translation of HLL to
Assembly Language

Statement Translation

A= B–2*A MOV AX , B ; AX has B


SUB AX , A ; AX has B – A
SUB AX , A ; AX has B – 2 * A
MOV A , AX ; move results to B

16 CAP221 10/23/2010

You might also like