1
2
A FEW BASICA FEW BASIC
INSTRUCTIONSINSTRUCTIONS
Presented By
Contents
There are over a hundred instructions in
the instruction set for the 8086 CPU.
Here we discuss 7 of the most useful
instructions for transferring data and
doing arithmetic.
The discussed instructions are……..
MOV,XCHG,ADD,SUB,INC,DEC,NEG.
5
IntroductionIntroduction
MOVMOV
 Transfer data
◦ Between registers
◦ Between register and a memory location
◦ Move a no. directly to a register or a
memory location
 Syntax
MOV destination, source
 Example
MOV AX, WORD1
6
How?
XCHG
 Exchange the contents of
◦ Two registers
◦ Register and a memory location
 Syntax
XCHG destination, source
 Example
XCHG AH, BL
7
AL
BL
00 1A
05 00
AH AL
BH BL
How?
Legal Combinations of Operands forLegal Combinations of Operands for
MOV And XCHGMOV And XCHG
Destina
tion
Operan
d
Source
Opera
nd
Legal
General
Register
General
Register
YES
General
Register
Memory
Locatio
n
YES
Memory
Location
General
Register
YES
Memory
Location
Memory
Locatio
n
NO
Destination
Operand
Source
Operand
Legal
General
Register
General
Register
YES
General
Register
Memory
Location
YES
General
Register
Segment
Register
YES
General
Register
Constant YES
Memory
Location
General
Register
YES
Memory
Location
Memory
Location
NO
Memory
Location
Segment
Register
YES
Memory Constant YES
MOV
XCHG
ADD InstructionADD Instruction
To add contents of:
◦ Two registers
◦ A register and a memory location
◦ A number to a register
◦ A number to a memory location
Example
ADD WORD1, AX
9
How?
SUB InstructionSUB Instruction
To subtract the contents of:
◦ Two registers
◦ A register and a memory location
◦ A number from a register
◦ A number from a memory location
 Example
SUB AX, DX
10
How?
Legal Combinations of Operands forLegal Combinations of Operands for
ADD & SUB instructionsADD & SUB instructions
11
Destination Operand Source Operand Legal
General Register General Register YES
General Register Memory Location YES
General Register Constant YES
Memory Location General Register YES
Memory Location Memory Location NO
Memory Location Constant YES
INC & DECINC & DEC
 INC (increment) instruction is used to add 1 to
the contents of a register or memory location.
◦ Syntax: INC destination
◦ Example: INC WORD1
 DEC (decrement) instruction is used to subtract 1
from the contents of a register or memory
location.
◦ Syntax: DEC destination
◦ Example: DEC BYTE1
12
Destination can be 8-bit or 16-bits wide.
Destination can be a register or a memory
location.
13
INC WORD1
DEC BYTE1
INC & DECINC & DEC
How?
How?
NEGNEG
 Used to negate the contents of destination.
 Replace the contents by its 2’s complement.
 Syntax:
NEG destination
 Example:
NEG BX
14How?
ExamplesExamples
 Consider instructions: MOV, ADD, SUB,
INC, DEC, NEG
 A and B are two word variables
 Translate statements into assembly language:
15
Statement Translation
A =-( A+1)
MOV AX,A
INC AX
NEG AX
MOV A,AX
B= 3B-7
MOV AX,B
ADD AX,B
ADD AX,B
SUB AX,7
MOV B,AX
Example:1
Example:2
Statem
ent
Translation
A = B –
A-1
MOV AX,B
SUB AX,A
DEC AX
MOV A,AX
Example:3
16
ApplicationApplication
.data
msg1 DB 'Input Any number From
1 To 9:$' ; Data segment
msg2 DB 'The Series Summation
Is:$'
.code
main proc
mov AX,@DATA ; Data
segment
mov DS,AX
lea dx,msg1 ;showing
msg1
mov ah,9
int 21h
mov ah,1 ;taking input
int 21h
xor ah,ah
sub al,30h
XOR CX,CX ;loop same as
input
mov cx,ax
XOR bx,bx
## A series
summation
of n numbers
where
1<=n<=9
17
sub bx,0Ah
add ax,1 ;counter=ax=3
CMP bx ,39h ;bx<39h
JL DISPLAY
sub bx,0Ah
add ax,1 ;counter=ax=4
CMP bx ,39h ;bx<39h
JL DISPLAY
DISPLAY:
add al,30h
mov cl,al
lea dx,msg2 ;showing msg2
mov ah,9
int 21h
mov ah,2
mov dl,cl
int 21h
mov dl,bl
int 21h
ApplicationApplication
TOP:
add bx,cx ;adding
LOOP TOP
mov ah,2
mov dl,0Dh
int 21h ;printing new
line
mov dl,0Ah
int 21h
xor ax,ax
add bx,30h
CMP bx ,39h ;bx<39h
JL DISPLAY
sub bx,0Ah
add ax,1 ;counter=ax=1
CMP bx ,39h ;bx<39h
JL DISPLAY
sub bx,0Ah
add ax,1 ;counter=ax=2
CMP bx ,39h ;bx<39h
JL DISPLAY
18
? ?
<
Assembly

Assembly

  • 1.
  • 2.
    2 A FEW BASICAFEW BASIC INSTRUCTIONSINSTRUCTIONS
  • 3.
  • 4.
  • 5.
    There are overa hundred instructions in the instruction set for the 8086 CPU. Here we discuss 7 of the most useful instructions for transferring data and doing arithmetic. The discussed instructions are…….. MOV,XCHG,ADD,SUB,INC,DEC,NEG. 5 IntroductionIntroduction
  • 6.
    MOVMOV  Transfer data ◦Between registers ◦ Between register and a memory location ◦ Move a no. directly to a register or a memory location  Syntax MOV destination, source  Example MOV AX, WORD1 6 How?
  • 7.
    XCHG  Exchange thecontents of ◦ Two registers ◦ Register and a memory location  Syntax XCHG destination, source  Example XCHG AH, BL 7 AL BL 00 1A 05 00 AH AL BH BL How?
  • 8.
    Legal Combinations ofOperands forLegal Combinations of Operands for MOV And XCHGMOV And XCHG Destina tion Operan d Source Opera nd Legal General Register General Register YES General Register Memory Locatio n YES Memory Location General Register YES Memory Location Memory Locatio n NO Destination Operand Source Operand Legal General Register General Register YES General Register Memory Location YES General Register Segment Register YES General Register Constant YES Memory Location General Register YES Memory Location Memory Location NO Memory Location Segment Register YES Memory Constant YES MOV XCHG
  • 9.
    ADD InstructionADD Instruction Toadd contents of: ◦ Two registers ◦ A register and a memory location ◦ A number to a register ◦ A number to a memory location Example ADD WORD1, AX 9 How?
  • 10.
    SUB InstructionSUB Instruction Tosubtract the contents of: ◦ Two registers ◦ A register and a memory location ◦ A number from a register ◦ A number from a memory location  Example SUB AX, DX 10 How?
  • 11.
    Legal Combinations ofOperands forLegal Combinations of Operands for ADD & SUB instructionsADD & SUB instructions 11 Destination Operand Source Operand Legal General Register General Register YES General Register Memory Location YES General Register Constant YES Memory Location General Register YES Memory Location Memory Location NO Memory Location Constant YES
  • 12.
    INC & DECINC& DEC  INC (increment) instruction is used to add 1 to the contents of a register or memory location. ◦ Syntax: INC destination ◦ Example: INC WORD1  DEC (decrement) instruction is used to subtract 1 from the contents of a register or memory location. ◦ Syntax: DEC destination ◦ Example: DEC BYTE1 12 Destination can be 8-bit or 16-bits wide. Destination can be a register or a memory location.
  • 13.
    13 INC WORD1 DEC BYTE1 INC& DECINC & DEC How? How?
  • 14.
    NEGNEG  Used tonegate the contents of destination.  Replace the contents by its 2’s complement.  Syntax: NEG destination  Example: NEG BX 14How?
  • 15.
    ExamplesExamples  Consider instructions:MOV, ADD, SUB, INC, DEC, NEG  A and B are two word variables  Translate statements into assembly language: 15 Statement Translation A =-( A+1) MOV AX,A INC AX NEG AX MOV A,AX B= 3B-7 MOV AX,B ADD AX,B ADD AX,B SUB AX,7 MOV B,AX Example:1 Example:2 Statem ent Translation A = B – A-1 MOV AX,B SUB AX,A DEC AX MOV A,AX Example:3
  • 16.
    16 ApplicationApplication .data msg1 DB 'InputAny number From 1 To 9:$' ; Data segment msg2 DB 'The Series Summation Is:$' .code main proc mov AX,@DATA ; Data segment mov DS,AX lea dx,msg1 ;showing msg1 mov ah,9 int 21h mov ah,1 ;taking input int 21h xor ah,ah sub al,30h XOR CX,CX ;loop same as input mov cx,ax XOR bx,bx ## A series summation of n numbers where 1<=n<=9
  • 17.
    17 sub bx,0Ah add ax,1;counter=ax=3 CMP bx ,39h ;bx<39h JL DISPLAY sub bx,0Ah add ax,1 ;counter=ax=4 CMP bx ,39h ;bx<39h JL DISPLAY DISPLAY: add al,30h mov cl,al lea dx,msg2 ;showing msg2 mov ah,9 int 21h mov ah,2 mov dl,cl int 21h mov dl,bl int 21h ApplicationApplication TOP: add bx,cx ;adding LOOP TOP mov ah,2 mov dl,0Dh int 21h ;printing new line mov dl,0Ah int 21h xor ax,ax add bx,30h CMP bx ,39h ;bx<39h JL DISPLAY sub bx,0Ah add ax,1 ;counter=ax=1 CMP bx ,39h ;bx<39h JL DISPLAY sub bx,0Ah add ax,1 ;counter=ax=2 CMP bx ,39h ;bx<39h JL DISPLAY
  • 18.
  • 19.

Editor's Notes

  • #8 Other e.g. XCHG AX, WORD1
  • #10 Source contents remain unchanged!