Download as pdf or txt
Download as pdf or txt
You are on page 1of 34

8086 MICROPROCESSOR

INSTRUCTION SETS
[CHAPTER 4]

By: Shadab Ahmad


[Microcomputers & Interfacing]
ECEg-4161
4th year Communication, Computer and Control Engineering
SAMARA UNIVERSITY
Instruction
Sets
The complete collection of instructions that are
understood by a CPU.

Shadab A. ECE Department 2


Instruction Set Classification

1. Transfer instructions
 Move

2. Arithmetic instructions
 Add / Subtract
 Multiplication / Division, etc.

3. Logical instructions
 AND
 OR, NOT etc.
Shadab A. ECE Department 3
1. Transfer instruction

 MOV instruction

Shadab A. ECE Department 4


Data transfer : Move

MOV Destination, Source ;


 MOV reg, reg ; reg <- reg
 MOV reg, mem ; reg <- mem
 MOV mem, reg ; mem <- reg
 MOV reg, imm ; reg <- imm
 MOV mem, imm ; mem <- imm

There is no move mem<-mem instruction


 MOV mem, mem ; irrelevant

5
Shadab A. ECE Department
Move limitation

 Here the source and destination needs to be


of the same size, that is both 8 bit or both
16 bit.

 There is no instruction to put immediate value


directly to the segment register. Have to use
accumulator (AX) to accomplish this.

Shadab A. ECE Department 6


Move (MOV) Example

 MOV AX,3F0h ; AX=03F0h


 MOV BX,AX ; BX=03F0h
 MOV DX,BX ; DX=03F0h

 MOV AX,123h ; AX=0123h


 MOV DX,56A8h ; DX=56A8h
 MOV AL,DL ; AL=A8h
 MOV BH,DH ; BH=56h

Shadab A. ECE Department 7


MOV Example

 MOV AX,1020h ; AX=1020h


 MOV [100h],AX ; [100h]=1020h
 MOV BX,[100h] ; BX=1020h
Immediate value can not put directly to segment register.
It has to use Accumulator (AX) to accomplish.

 MOV DS,2300h;X MOV AX,2300h ;


MOV DS,AX ;

8
Shadab A. ECE Department
MOV : 16 / 8 Bit register

 To move value
between
registers, their
size must be
the same.

Shadab A. ECE Department 9


MOV : Memory

Given only offset where to put value, it will be


automatically select DS as the segment register.

Shadab A. ECE Department 10


Byte ordering

The LSB will be placed at lowest


address and MSB will be placed
at highest address. 11
2. Arithmetic instructions

 Add / Subtract
 Multiplication / Division

Shadab A. ECE Department 12


1. ADD Instruction

 ADD Instruction is used to add the current contents of Destination


with Source and store the result in Destination.

ADD Destination, Source ;


Examples:
 ADD AL, 0FH ; – Add the immediate content, 0FH to the
content of AL and store the result in AL
 ADD AX, BX ; – AX <= AX+BX
 ADD AX, 0100H ; – IMMEDIATE Addressing Mode
 ADD AX, BX ; – REGISTER Addressing Mode
 ADD AX, [SI] ; – INDEXED Addressing Mode
 ADD AX, [5000H] ; – DIRECT Addressing Mode
13
Example ADD

 MOV AL, 10h ;AL = 10h


 ADD AL, 20h ;AL = 30h
 MOV BX, 200h ;BX = 0200h
 MOV AH, 89h ;AX = 8930h
 ADD AX, 9876h ;AX = 21A6h
 ADC BX, 01h ;BX = 0202h

 ADC: Add with Carry

14
2. Subtract (SUB)/
Subtract with Borrow (SBB)

 SUB reg, imm ; SBB reg, imm


 SUB reg, mem ; SBB reg, mem
 SUB reg, reg ; SBB reg, reg
 SUB mem, imm ; SBB mem, imm
 SUB mem, reg ; SBB mem, reg

SUB AX, BX ;
SBB AL, BL ;
15
Ex. SUB/SBB

 MOV AL, 15h ;AL = 15h


 ADD AL, 20h ;AL = 35h
 MOV BX, 200h ;BX = 0200h
 MOV AH, 89h ;AX = 8935h
 SUB AX, 0005h ;AX = 8930h
 SBB AX, 0001h ;AX = 892Eh
 SUB AX, 0001h ;AX = 892Dh

16
3. Increment (INC)/
Decrement (DEC)

 INC / DEC :
INC register ;
DEC register ;

Example:
INC AX ; AX+1=> AX

DEC BL ; BL-1 => BL

17
4. Multiplication (MUL)

 MUL (Multiplication) signed multiplication.

MUL reg ;

 Always perform with accumulator AX.

18
8 bit Multiplication

 AL is multiplicand
 Always accumulator (AX) keeps the result

MUL CL ; AL*CL => AX


MUL BL ; AL*BL => AX

MOV AL,10h ; AL = 10h


MOV CL,13h ; CL = 13h
MUL CL ; AX = 0130h

19
16 bit Multiplication
 AX is multiplicand
 DX:AX keeps the result
MUL CX ; AX*CX = DX:AX

MOV AX,0100h ; AX = 0100h


MOV BX,1234h ; BX = 1234h
MUL BX ; DX = 0012h
; AX = 3400h 0012 3400

MUL BX ; AX*BX = DX:AX DX AX

20
5. Division (DIV)

 DIV (Division) signed division.

DIV reg ;
DIV mem ;

 Always perform with accumulator.

21
8 bit Division

 AL is dividend
 AL keeps the result
 AH keeps the remainder

 Example:
MOV AX, 0017h ; REMINDER RESULT

MOV BX, 0010h ; 07 01


DIV BL ; AX = 0701 AH AL

22
16 bit Division
 DX:AX dividend.
 AX keep the result, DX keep the remainder.

Example:
MOV AX, 4022h ; AX=4022h
MOV DX, 0000h ; DX=0000h
MOV CX, 1000h ; CX=1000h
REMINDER RESULT
DIV CX ; AX = 0004
; DX = 0022 0022 0004
DX AX

23
6. Conversion

 Convert Byte to Word : CBW


Signed convert AL -> AX
covert 8 bit to 16 bit

 Convert Word to Double word : CWD


Signed convert AX -> DX:AX
covert 16 bit to 32 bit

24
Example Conversion

MOV AL,22h
CBW ; AX=0022h

MOV AX, 3422h


CWD ; DX=0000h
; AX=3422h

25
3. Logical Instructions
 AND
 OR
 NOT

Shadab A. ECE Department 26


AND instruction

AND Destination, Source ;

AND CX, AX ; CX <= CX AND AX

Example:
AND BL, AL ; suppose BL=1000 0110 and AL = 1100 1010
then after the operation BL would be BL= 1000 0010

AND CL, 08 ; CL<= CL AND (0000 1000)

27
Shadab A. ECE Department
OR instruction

OR Destination, Source ;

OR CX, AX ; CX <= CX OR AX
Example:
OR BL, AL ; suppose BL=1000 0110 and AL = 1100 1010
then after the operation BL would be BL= 1100 1110

OR CL, 08 ; CL<= CL OR (0000 1000)

Shadab A. ECE Department 28


NOT instruction

NOT Register ;

Example:
NOT AX ;

BEFORE EXECUTION AX= (1011)2= (B)16


AFTER EXECUTION AX= (0100)2= (4)16

Shadab A. ECE Department 29


Assembly
Language
Programs
Shadab A. ECE Department 30
To write an assembly language program
for Addition of two 16 bit numbers.

Shadab A. ECE Department 31


To write an assembly language program
for Subtraction of two 16 bit numbers.

Shadab A. ECE Department 32


To write an assembly language program
for Multiplication of two 16 bit numbers.

Shadab A. ECE Department 33


To write an assembly language program
for Division of two 16 bit numbers.

Shadab A. ECE Department 34

You might also like