Вы находитесь на странице: 1из 81

Microprocessor,

Interfacing and System


design

Prof. Dr. Md. Shahidul Islam


Contact: 01750 194739

19 February 2019 North Bengal International 1


University
19 February 2019 North Bengal International 2
University
19 February 2019 North Bengal International 3
University
19 February 2019 North Bengal International 4
University
19 February 2019 North Bengal International 5
University
19 February 2019 North Bengal International 6
University
19 February 2019 North Bengal International 7
University
19 February 2019 North Bengal International 8
University
Instruction Set of
8086

19 February 2019 North Bengal International 9


University
Instruction Set of 8086
• An instruction is a binary pattern designed
inside a microprocessor to perform a specific
function.
• The entire group of instructions that a
microprocessor supports is called Instruction
Set.
• 8086 has more than 20,000 instructions.

19 February 2019 North Bengal International 10


University
Classification of Instruction Set
• Data Transfer Instructions
• Arithmetic Instructions
• Bit Manipulation Instructions
• Program Execution Transfer Instructions
• String Instructions
• Processor Control Instructions

19 February 2019 North Bengal International 11


University
Data Transfer Instructions
• These instructions are used to transfer
data from source to destination.
• The operand can be a constant, memory
location, register or I/O port address.

19 February 2019 North Bengal International 12


University
Data Transfer Instructions
 MOV Des, Src:
 Src operand can be register, memory location or
immediate operand.
 Des can be register or memory operand.
 Both Src and Des cannot be memory location at the
same time.
 E.g.:
 MOV CX, 037A H
 MOV AL, BL
 MOV BX, [0301 H]
19 February 2019 North Bengal International 13
University
Data Transfer Instructions
 MOV Des, Src
 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.

19 February 2019 North Bengal International 14


University
Move (MOV) Example
 MOV AX,100h
 MOV BX,AX
 MOV DX,BX

 MOV AX,1234h
 MOV DX,5678h
 MOV AL,DL
 MOV BH,DH

19 February 2019 North Bengal International 15


University
 MOV AX,1000h, MOV [100h],AX, MOV BX,[100h]
 MOV BYTE PTR [200h],10h, MOV WORD PTR [300h],10h
 Write an Assembly Language Program in 8086 to move 2300H in memory location
0028H.
• CODE SEGMENT
• ASUME CS: CODE, DS: CODE
• ORG 1000H
 MOV AX,2300h MOV WORD PTR [0028H],2300H
 MOV [0028H], AX
• INT 3
• CODE ENDS
• END

Write an Assembly Language Program in 8086 to load 2300H in segment


register DS.
• CODE SEGMENT
• ASUME CS: CODE, DS: CODE
• ORG 1000H
 MOV AX,2300h
 MOV DS,AX
• INT 3
• CODE ENDS
• END

19 February 2019 North Bengal International 16


University
MOV : 16 / 8 Bit register
 To move value
between
registers, their
size must be the
same.

19 February 2019 North Bengal International 17


University
MOV : Memory

 Given only offset where to put value, it will be


automatically select DS as the segment register.
19 February 2019 North Bengal International 18
University
Byte ordering : Little endian
 Since, x86’s byte
ordering is little
endian.
 Therefore, the LSB
will be placed at
lowest address and
MSB will be placed
at highest address.

19 February 2019 North Bengal International 19


University
Displacement
 We can use BX
(Base) register to
point a place of
memory.
 Both register direct or
displacement.

 AX = ?

19 February 2019 North Bengal International 20


University
Data Transfer Instructions
 PUSH Operand:
 It pushes the operand into top of stack.
 E.g.: PUSH BX

 POP Des:
 It pops the operand from top of stack to Des.
 Des can be a general purpose register, segment register
(except CS) or memory location.
 E.g.: POP AX

19 February 2019 North Bengal International 21


University
19 February 2019 North Bengal International 22
University
19 February 2019 North Bengal International 23
University
Data Transfer Instructions
• XCHG Des, Src:
– This instruction exchanges Src with Des.
– It cannot exchange two memory locations directly.
– E.g.: XCHG DX, AX

19 February 2019 North Bengal International 24


University
Data Transfer Instructions
• IN Accumulator, Port Address:
– It transfers the operand from specified port to accumulator
register.

– E.g.: IN AX, 0028 H

• OUT Port Address, Accumulator:


– It transfers the operand from accumulator to specified port.

– E.g.: OUT 0028 H, AX

19 February 2019 North Bengal International 25


University
Example
Write instructions to load the hexadecimal numbers 65H in register CX, and 92H
in the accumulator AX. Display the number 92H at PORT0 and 65H at PORT1.

CODE SEGMENT
ASUME CS: CODE, DS: CODE
ORG 1000H
MOV CX, 0065H
MOV AX, 0092H
OUT PORT0, AX
MOV AX, CX
OUT PORT1, AX
INT 3
CODE ENDS
END

19 February 2019 North Bengal International 26


University
Data Transfer Instructions
• LEA Register, Src:
– It loads a 16-bit register with the offset
address of the data specified by the Src.
– E.g.: LEA BX, [DI]
• This instruction loads the contents of DI
(offset) into the BX register.

19 February 2019 North Bengal International 27


University
Data Transfer Instructions
• LAHF:
– It copies the lower byte of flag register to AH.

• SAHF:
– It copies the contents of AH to lower byte of flag register.

• PUSHF:
– Pushes flag register to top of stack.

• POPF:
– Pops the stack top to flag register.

19 February 2019 North Bengal International 28


University
Arithmetic Instructions
• ADD Des, Src:
– It adds a byte to byte or a word to word.
– It effects AF, CF, OF, PF, SF, ZF flags.
– E.g.:
• ADD AL, 74H
• ADD DX, AX
• ADD AX, [BX]

19 February 2019 North Bengal International 29


University
Write an Assembly Language Program in 8086 to add two 16-bit hexadecimal
numbers.

CODE SEGMENT
ASUME CS: CODE, DS: CODE
ORG 1000H
MOV AX, 1234H
ADD AX, 5678H
INT 3
CODE ENDS
END

19 February 2019 North Bengal International 30


University
Arithmetic Instructions
• ADC Des, Src:
– It adds the two operands with CF.
– It effects AF, CF, OF, PF, SF, ZF flags.
– E.g.:
• ADC AL, 74H
• ADC DX, AX
• ADC AX, [BX]

19 February 2019 North Bengal International 31


University
EX. ADD
 MOV AL, 10h
 ADD AL, 20h ;AL = 30h
 MOV BX, 200h ;BX = 0200h
 MOV WORD PTR [BX], 10h
 ADD WORD PTR [BX], 70h
 MOV AH, 89h ;AX = 8930h
 ADD AX, 9876h ;AX = 21A6h
 ADC BX, 01h ;BX = 0202h ?

19 February 2019 North Bengal International 32


University
Arithmetic Instructions
• SUB Des, Src:
– It subtracts a byte from byte or a word from word.
– It effects AF, CF, OF, PF, SF, ZF flags.
– For subtraction, CF acts as borrow flag.
– E.g.:
• SUB AL, 74H
• SUB DX, AX
• SUB AX, [BX]

19 February 2019 North Bengal International 33


University
Arithmetic Instructions
• SBB Des, Src:
– It subtracts the two operands and also the
borrow from the result.
– It effects AF, CF, OF, PF, SF, ZF flags.
– E.g.:
• SBB AL, 74H
• SBB DX, AX
• SBB AX, [BX]

19 February 2019 North Bengal International 34


University
Ex. SUB
 MOV AL, 10h
 ADD AL, 20h ;AL = 30h
 MOV BX, 200h ;BX = 0200h
 MOV WORD PTR [BX], 10h
 SUB WORD PTR [BX], 70h
 MOV AH, 89h ;AX = 8930h
 SBB AX, 0001h ;AX = 892Eh ?
 SBB AX, 0001h ;AX = 892Dh

19 February 2019 North Bengal International 35


University
Arithmetic Instructions
• INC Src:
– It increments the byte or word by one.
– The operand can be a register or memory
location.
– It effects AF, OF, PF, SF, ZF flags.
– CF is not effected.
– E.g.: INC AX

19 February 2019 North Bengal International 36


University
Arithmetic Instructions
• DEC Src:
– It decrements the byte or word by one.
– The operand can be a register or memory
location.
– It effects AF, OF, PF, SF, ZF flags.
– CF is not effected.
– E.g.: DEC AX

19 February 2019 North Bengal International 37


University
Arithmetic Instructions
• AAA (ASCII Adjust after Addition):
– The data entered from the terminal is in ASCII format.
– In ASCII, 0 – 9 are represented by 30H – 39H.
– This instruction allows us to add the ASCII codes.
– This instruction does not have any operand.
• Other ASCII Instructions:
– AAS (ASCII Adjust after Subtraction)
– AAM (ASCII Adjust after Multiplication)
– AAD (ASCII Adjust Before Division)

19 February 2019 North Bengal International 38


University
Arithmetic Instructions
• DAA (Decimal Adjust after Addition)
– It is used to make sure that the result of
adding two BCD numbers is adjusted to be a
correct BCD number.
– It only works on AL register.

• DAS (Decimal Adjust after Subtraction)


– It is used to make sure that the result of
subtracting two BCD numbers is adjusted to
be a correct BCD number.
– It only works on AL register.
19 February 2019 North Bengal International 39
University
Arithmetic Instructions
• NEG Src:
– It creates 2’s complement of a given
number.
– That means, it changes the sign of a
number.

19 February 2019 North Bengal International 40


University
Ex. NEG
 MOV CX, 10h
 NEG CX ; CX = 0FFF0h
 MOV AX,0FFFFH
 NEG AX ; AX = 1
 MOV BX,1H
 NEG BX ; BX = 0FFFFh

Determine the value of AX after


execution the following instructions:
MOV AX,0FFFFH
NEG AX
19 February 2019 North Bengal International 41
University
Arithmetic Instructions
• CMP Des, Src:
– It compares two specified bytes or words.
– The Src and Des can be a constant, register or memory
location.
– Both operands cannot be a memory location at the
same time.
– The comparison is done simply by internally subtracting
the source from destination.
– The value of source and destination does not change,
but the flags are modified to indicate the result.

19 February 2019 North Bengal International 42


University
Ex. CMP
 MOV CX, 10h
 CMP CX, 20h ;Z=0,S=1,C=1,O=0
 MOV BX, 40h
 CMP BX, 40h ;Z=1,S=0,C=0,O=0
 MOV AX, 30h
 CMP AX, 20h ;Z=0,S=0,C=0,O=0

Describe what happens to the status flags as the sequence of instruction


that follows is executed:
MOV CX, 10H
CMP CX, 20H
Assume that flags ZF, SF, CF, and OF are all initially reset.
19 February 2019 North Bengal International 43
University
Arithmetic Instructions
• MUL Src:
– It is an unsigned multiplication instruction.
– It multiplies two bytes to produce a word or two words to
produce a double word.
– AX = AL * Src
– DX : AX = AX * Src
– This instruction assumes one of the operand in AL or AX.
– Src can be a register or memory location.
• IMUL Src:
– It is a signed multiplication instruction.

19 February 2019 North Bengal International 44


University
8 bit multiplication
 AL is multiplicand
 AX keep the result

 MOV AL,10h ; AL = 10h


 MOV CL,13h ; CL = 13h
 IMUL CL ; AX = 0130h

Write an Assembly Language Program to find the multiplication


of two 8-bit Hex numbers 10H and 13H.

19 February 2019 North Bengal International 45


University
16 bit multiplication
 AX is multiplicand
 DX:AX keep the result

 MOV AX,0100h ; AX = 0100h


 MOV BX,1234h ; BX = 1234h
 IMUL BX ; DX = 0012h
; AX = 3400h

19 February 2019 North Bengal International 46


University
Arithmetic Instructions
• DIV Src:
– It is an unsigned division instruction.
– It divides word by byte or double word by word.
– The operand is stored in AX, divisor is Src and
the result is stored as:
• AH = remainder AL = quotient

• IDIV Src:
– It is a signed division instruction.

19 February 2019 North Bengal International 47


University
8 bit division
 AL is dividend
 AL keep the result
 AH keep the remainder

 MOV AX, 0017h


 MOV BX, 0010h
 DIV BL ; AX = 0701

19 February 2019 North Bengal International 48


University
16 bit multiplication
 DX:AX dividend.
 AX keep the result, DX keep the remainder.

 MOV AX,4022h ;
 MOV DX,0000h ;
 MOV CX,1000h ;
 DIV CX ;AX = 0004
;DX = 0022
Write an Assembly Language Program in 8086 to divide
a 32-bit number by a 16-bit number.

19 February 2019 North Bengal International 49


University
Arithmetic Instructions
• CBW (Convert Byte to Word):
– This instruction converts byte in AL to word in AX.
– The conversion is done by extending the sign bit of
AL throughout AH.

• CWD (Convert Word to Double Word):


– This instruction converts word in AX to double word in
DX : AX.
– The conversion is done by extending the sign bit of
AX throughout DX.

19 February 2019 North Bengal International 50


University
Ex. Conversion
 MOV AL,22h
 CBW ; AX=0022h
 MOV AL,F0h
 CBW ; AX=FFF0h
 MOV AX, 3422h
 CWD ; DX=0000h
; AX=3422h
Determine the value of AX after
execution the following instructions:
MOV AL,22H
CBW
19 February 2019 North Bengal International 51
University
Bit Manipulation Instructions
• These instructions are used at the bit
level.
• These instructions can be used for:
– Testing a zero bit
– Set or reset a bit
– Shift bits across registers

19 February 2019 North Bengal International 52


University
Bit Manipulation Instructions

• NOT Src:
– It complements each bit of Src to produce 1’s
complement of the specified operand.
– The operand can be a register or memory
location.
– NOT CX

19 February 2019 North Bengal International 53


University
Bit Manipulation Instructions
• AND Des, Src: (AND DX,BX)
– It performs AND operation of Des and Src.
– Src can be immediate number, register or
memory location.
– Des can be register or memory location.
– Both operands cannot be memory locations at the
same time.
– CF and OF become zero after the operation.
– PF, SF and ZF are updated.
19 February 2019 North Bengal International 54
University
Bit Manipulation Instructions
• OR Des, Src: (OR DX,BX)
– It performs OR operation of Des and Src.
– Src can be immediate number, register or
memory location.
– Des can be register or memory location.
– Both operands cannot be memory locations at the
same time.
– CF and OF become zero after the operation.
– PF, SF and ZF are updated.
19 February 2019 North Bengal International 55
University
Bit Manipulation Instructions
• XOR Des, Src: (XOR DX,BX)
– It performs XOR operation of Des and Src.
– Src can be immediate number, register or
memory location.
– Des can be register or memory location.
– Both operands cannot be memory locations at the
same time.
– CF and OF become zero after the operation.
– PF, SF and ZF are updated.
19 February 2019 North Bengal International 56
University
Bit Manipulation Instructions
• SHL Des, Count:(SHL AL,1; SHL AL,CL)
– It shift bits of byte or word left, by count.
– It puts zero(s) in LSBs.
– MSB is shifted into carry flag.
– If the number of bits desired to be shifted is 1,
then the immediate number 1 can be written
in Count.
– However, if the number of bits to be shifted is
more than 1, then the count is put in CL
register.
19 February 2019 North Bengal International 57
University
Bit Manipulation Instructions
• SHR Des, Count:(SHR AL,1;SHR AL,CL)
– It shift bits of byte or word right, by count.
– It puts zero(s) in MSBs.
– LSB is shifted into carry flag.
– If the number of bits desired to be shifted is 1,
then the immediate number 1 can be written
in Count.
– However, if the number of bits to be shifted is
more than 1, then the count is put in CL
register.
19 February 2019 North Bengal International 58
University
Bit Manipulation Instructions
• ROL Des, Count:(ROL AL,1; ROL AL,CL)
– It rotates bits of byte or word left, by count.
– MSB is transferred to LSB and also to CF.
– If the number of bits desired to be shifted is 1,
then the immediate number 1 can be written in
Count.
– However, if the number of bits to be shifted is
more than 1, then the count is put in CL
register.

19 February 2019 North Bengal International 59


University
Bit Manipulation Instructions
• ROR Des, Count:(ROR AL,1; ROR AL,CL)
– It rotates bits of byte or word right, by count.
– LSB is transferred to MSB and also to CF.
– If the number of bits desired to be shifted is 1,
then the immediate number 1 can be written in
Count.
– However, if the number of bits to be shifted is
more than 1, then the count is put in CL
register.

19 February 2019 North Bengal International 60


University
Program Execution Transfer
Instructions

• These instructions cause change in the


sequence of the execution of instruction.
• This change can be through a condition or
sometimes unconditional.
• The conditions are represented by flags.

19 February 2019 North Bengal International 61


University
Program Execution Transfer
Instructions
• CALL Des:
– This instruction is used to call a subroutine or
function or procedure.
– The address of next instruction after CALL is
saved onto stack.

• RET:
– It returns the control from procedure to calling
program.
– Every CALL instruction should have a RET.
19 February 2019 North Bengal International 62
University
Program Execution Transfer
Instructions
• JMP Des:
– This instruction is used for unconditional jump
from one place to another.

• Jxx Des (Conditional Jump):


– All the conditional jumps follow some
conditional statements or any instruction that
affects the flag.

19 February 2019 North Bengal International 63


University
Conditional Jump Table
Mnemonic Meaning Jump Condition
JA Jump if Above CF = 0 and ZF = 0
JAE Jump if Above or Equal CF = 0
JB Jump if Below CF = 1
JBE Jump if Below or Equal CF = 1 or ZF = 1
JC Jump if Carry CF = 1
JE Jump if Equal ZF = 1
JNC Jump if Not Carry CF = 0
JNE Jump if Not Equal ZF = 0
JNZ Jump if Not Zero ZF = 0
JPE Jump if Parity Even PF = 1
JPO Jump if Parity Odd PF = 0
JZ Jump if Zero ZF = 1

19 February 2019 North Bengal International 64


University
Program Execution Transfer
Instructions
• Loop Des:
– This is a looping instruction.
– The number of times looping is required is
placed in the CX register.
– With each iteration, the contents of CX are
decremented.
– ZF is checked whether to loop again or not.

19 February 2019 North Bengal International 65


University
String Instructions
• String in assembly language is just a
sequentially stored bytes or words.
• There are very strong set of string
instructions in 8086.
• By using these string instructions, the size
of the program is considerably reduced.

19 February 2019 North Bengal International 66


University
String Instructions
• CMPS Des, Src:
– It compares the string bytes or words.

• SCAS String:
– It scans a string.
– It compares the String with byte in AL or with
word in AX.

19 February 2019 North Bengal International 67


University
String Instructions
• MOVS / MOVSB / MOVSW:
– It causes moving of byte or word from one
string to another.
– In this instruction, the source string is in Data
Segment and destination string is in Extra
Segment.
– SI and DI store the offset values for source
and destination index.

19 February 2019 North Bengal International 68


University
String Instructions
• REP (Repeat):
– This is an instruction prefix.
– It causes the repetition of the instruction until
CX becomes zero.
– E.g.: REP MOVSB STR1, STR2
• It copies byte by byte contents.
• REP repeats the operation MOVSB until CX
becomes zero.

19 February 2019 North Bengal International 69


University
Processor Control Instructions
• These instructions control the processor
itself.
• 8086 allows to control certain control flags
that:
– causes the processing in a certain direction
– processor synchronization if more than one
microprocessor attached.

19 February 2019 North Bengal International 70


University
Processor Control Instructions
• STC:
– It sets the carry flag to 1.

• CLC:
– It clears the carry flag to 0.

• CMC:
– It complements the carry flag.

19 February 2019 North Bengal International 71


University
Processor Control Instructions
• STD:
– It sets the direction flag to 1.
– If it is set, string bytes are accessed from higher
memory address to lower memory address.

• CLD:
– It clears the direction flag to 0.
– If it is reset, the string bytes are accessed from lower
memory address to higher memory address.

19 February 2019 North Bengal International 72


University
19 February 2019 North Bengal International 73
University
CODE SEGMENT
ASSUME CS:CODE, DS:CODE
MOV AX, 0001H
ADD AX, 6789H
STC
ADC AX, 0488H
;
SUB AX, 156FH
STC
SBB AX, 080FH
;
MOV AX, 00FEH
INC AL
DEC AL
CBW
NEG AL
;
MOV AL, F0H
MOV BL, 11H
MUL BL
;
MOV AX, F000H
MOV BX, 1234H
IMUL BX
;
MOV AX, 00F0H
MOV BL, 10H
DIV BL
;
MOV AX, −205
MOV BL, 4
IDIV BL
;
HLT
CODE ENDS
END

19 February 2019 North Bengal International 74


University
Instruction / Set Flag
IP AX BX DX Remarks
Mnemonics Bit(s)
Initial Status
MOV AX, 0001H
ADD AX, 6789H
STC
ADC AX, 0488H
SUB AX, 156FH
STC
SBB AX, 080FH
MOV AX, 00FEH
INC AL
DEC AL
CBW
NEG AL
MOV AL, F0H
MOV BL, 11H
MUL BL
MOV AX, F000H
MOV BX, 1234H
IMUL BX
MOV AX, F000H
MOV BL, 10H
DIV BL
MOV AX, −205
MOV BL, 4
IDIV BL

19 February 2019 North Bengal International 75


University
CODE SEGMENT
ASSUME CS:CODE, DS:CODE
ORG 1000H
MOV AX, 1027H
MOV BX, 5A27H
MOV CX, 54A5H
OR AX, BX
XOR AX, CX
NOT AX
TEST CX, BX
AND CX, AX
HLT
CODE ENDS
END

19 February 2019 North Bengal International 76


University
Offset Instruction / Set Flag
AX BX CX DX IP
Address Mnemonics Bit(s)
Initial Status
MOV AX, 1027H
MOV BX, 5A27H
MOV CX, 54A5H
OR AX, BX
XOR AX, CX
NOT AX
TEST CX, BX
AND CX, AX

19 February 2019 North Bengal International 77


University
CODE SEGMENT
ASSUME CS:CODE, DS:CODE
ORG 1000H
MOV AX, 7A24H
MOV BX, 95A3H
ADD AX, BX
JC LEBEL
EEE: OR AX, 23H
JNZ LAST
LEBEL: MOV CX, 0FC7H
SUB AX,CX
JZ EEE
LAST: HLT
CODE ENDS
END

19 February 2019 North Bengal International 78


University
Offset Instruction / Set Flag
AX BX CX DX IP
Address Mnemonics Bit(s)
Initial Status

MOV AX, 7A24H

MOV BX, 95A3H

ADD AX, BX

JC RUET
EEE:
OR AX, 23H
JNZ LAST
RUET:
MOV CX, 0FC7H
SUB AX,CX

JZ EEE
LAST:
HLT

19 February 2019 North Bengal International 79


University
CODE SEGMENT
ASSUME CS:CODE, DS:CODE
ORG 1000H
MOV AX, 0055H
MOV DX, 0505H
MOV CL, 3
SAL AX, CL
SAR DX, CL
MOV CL, 2
ROR AX, CL
ROL DX, CL
STC
RCL AL, CL
RCR DX, CL
HLT
CODE ENDS
END

19 February 2019 North Bengal International 80


University
Offset Instruction / Set Flag
AX BX CX DX IP
Address Mnemonics Bit(s)
Initial Status
MOV AX, 0055H
MOV DX, 0505H
MOV CL, 3
SAL AX, CL
SAR DX, CL
MOV CL, 2
ROR AX, CL
ROL DX, CL
STC
RCL AL, CL
RCR DX, CL

19 February 2019 North Bengal International 81


University

Вам также может понравиться