Microprocessor and Interfacing Techniques: (Course Code: CET208A) Credits-3
Microprocessor and Interfacing Techniques: (Course Code: CET208A) Credits-3
Microprocessor and Interfacing Techniques: (Course Code: CET208A) Credits-3
10/09/2021 Microprocessor and Interfacing Techniques (CET208A) _T5_S Y BTech_ School of Computer Engineering & Technology_ 2020-21 1
Microprocessor and Interfacing Techniques CET208A
Examination scheme:
Continuous Assessment: 50 Marks, End Semester: 50 Marks
Course Objectives:
1. To understand fundamental concepts of architecture and programming of 8086 Microprocessor.
2. To comprehend memory organization of 8086 Microprocessor and its interfacing with input-output
devices.
3. To make the students aware of peripheral ICs and their interfacing with 8086 Microprocessor.
4. To study working of NDP and Motherboard of IBM PC.
Course Outcomes:Upon completion of the course, the students will be able to:
1. Explain architecture and programming model of microprocessor 8086 and develop assembly language
programs for various applications.
2. Demonstrate memory organization of microprocessor 8086 and design interface of 8086 with memory
and peripheral devices.
3. Illustrate the concept of serial communication and interrupt handling.
4. Summarize the motherboard functional blocks along with NDP 8087.
Microprocessor and Interfacing Techniques (CET208A) _T5_S Y BTech_ School of
10/09/2021 2
Computer Engineering & Technology_ 2020-21
Syllabus
Unit 1 - 8086 Architecture: Architecture and Functional Pin description of 8086,
Programmers model (Register Set) and Segmentation of 8086, logical to physical
address translation, Addressing modes, Instruction set of 8086 in detail, 8086
Programming examples.
Assembly Language Programming, Assembler, Linker, Debugger, Directives,
Procedures (Near & Far), Macros, Loop constructs.
Unit 2 -Memory and I/O Interfacing: Memory/I/O Read/write cycle timing
diagrams, Memory and I/O space of 8086. Memory organization: even and odd banks.
Address decoding for memory/IO interfacing. Using NAND gate and Decoder.
Programmable Peripheral Interface 8255: Features, Block Diagram, Control & status
registers, Operating modes & Interfacing Concept of ADC and DAC
5. Write 8086 ALP to interface DAC through 8255 and generate following waveforms on
oscilloscope, (i) Square wave - Variable Duty Cycle and Frequency. (ii) Ramp wave - Variable
direction (iii) Trapezoidal wave (iv) Stair case wave. (Demo)
6. Perform an experiment to establish communication between two 8251 systems A and B.
Program 8251 system A in asynchronous transmitter mode and 8251 system B in asynchronous
receiver mode. Write an ALP to transmit the data from system A and receive the data at system
B.
OR
Inline C programming (Directory creation and Delete) / PC to PC communication.
10/09/2021 Microprocessor and Interfacing Techniques (CET208A) _T5_S Y BTech_ School of Computer Engineering & Technology_ 2020-21 18
Stephen Morse: Father of the 8086 Processor
10/09/2021 Microprocessor and Interfacing Techniques (CET208A) _T5_S Y BTech_ School of Computer Engineering & Technology_ 2020-21 19
Introduction of 8086 Architecture
• 8086 Microprocessor is an enhanced version of 8085 Microprocessor
that was designed by Intel in 1976.
• It is a 16-bit Microprocessor
• 20 address lines and
• 16 data lines
• 1MB storage
• It supports two modes of operation, i.e. Maximum mode and
Minimum mode.
1. Maximum mode: It is suitable for system having multiple processors.
2. Minimum mode: It is suitable for system having a single processor.
Microprocessor and Interfacing Techniques (CET208A) _T5_S Y BTech_ School of Computer Engineering & Technology_ 2020-21
10/09/2021 20
Features of 8086
It has an instruction queue, which is capable of storing six instruction bytes
from the memory resulting in faster processing.
It was the first 16-bit processor having 16-bit ALU, 16-bit registers, internal
data bus, and 16-bit external data bus resulting in faster processing.
It is available in 3 versions based on the frequency of operation −
1. 8086-1 → 5MHz
2. 8086-2 → 8MHz
3. 8086-3 → 10 MHz
It uses two stages of pipelining, i.e. Fetch Stage and Decode Execute Stage,
which improves performance.
It has 256 vectored interrupts.
10/09/2021 Microprocessor and Interfacing Techniques (CET208A) _T5_S Y BTech_ School of Computer Engineering & Technology_ 2020-21 21
8086 –detail architecture (Block diagram)
10/09/2021 Microprocessor and Interfacing Techniques (CET208A) _T5_S Y BTech_ School of Computer Engineering & Technology_ 2020-21 22
Basic Architecture of 8086
10/09/2021 Microprocessor and Interfacing Techniques (CET208A) _T5_S Y BTech_ School of Computer Engineering & Technology_ 2020-21 23
The Bus Interface Unit (BIU)
It is processor’s connection to
outside world. It performs –
Memory
• Instruction fetching
• Reading and writing of
data operands from / to
Input BIU Output
memory Device (CPU) Device
• Inputting or outputting
data from / to devices
Microprocessor and Interfacing Techniques (CET208A) _T5_S Y BTech_ School of Computer Engineering &
10/09/2021 Technology_ 2020-21 24
BIU contd….
To perform these functions it has
• Segment registers
• Instruction Pointer
• Address generation Adder
• Bus Control logic
• Instruction Queue
INS 3 (H)
INS 3 (L)
Memory INS 2 (H) Instruction register
INS 2 (L)
INS 1 (H)
INS 1 (L)
Prefetch CU
10/09/2021 Microprocessor and Interfacing Techniques (CET208A) _T5_S Y BTech_ School of Computer Engineering & Technology_ 2020-21 26
When does the BIU Prefetch ?…
Whenever the instruction
queue is not full and has room
for at least 2 more bytes
AND
at the same time the execution
unit is not asking it to read or
write data to or from memory
10/09/2021 Microprocessor and Interfacing Techniques (CET208A) _T5_S Y BTech_ School of Computer Engineering & Technology_ 2020-21 28
The Execution Unit
• It decodes the instruction.
• Generates addresses for data if
necessary
• Instructs BIU to read or write
data from/to memory
• Performs specified operation
• Updates the flags
• If the Queue is empty EU has to
wait till the instruction is
fetched..
8086 provides 16 bit four segment registers which point to each of the
segment:
• Code Segment Register points to base of the CODE segment
• Data Segment Register points to base of the Data Segment
• Stack Segment Register points to base of the Stack Segment
• Extra Segment Register points to base of the Extra Segment
Microprocessor and Interfacing Techniques (CET208A) _T5_S Y BTech_ School of
10/09/2021 Computer Engineering & Technology_ 2020-21 31
Programmers Model
10/09/2021
Microprocessor and Interfacing Techniques (CET208A) _T5_S Y BTech_ School of Computer Engineering & Technology_ 2020-21 32
8086 Registers
General Purpose Index
AH AL
BP
AX
SP
BH BL
BX
SI
CH CL
DI
CX
DH DL
DX Segment
CS
Flags DS
IP ES
AX - Accumulator
BX - Base Register
CX - Count Register
DX - Data Register
•BX
• Base Register
• Also serves as an address register
• DX
–Data register
–Used in Multiplication and Division
–Also used in I/O operations
Microprocessor and Interfacing Techniques (CET208A) _T5_S Y BTech_ School of
10/09/2021 Computer Engineering & Technology_ 2020-21 36
Pointer and Index Registers
Overflow Carry
Direction Parity
10/09/2021 Microprocessor and Interfacing Techniques (CET208A) _T5_S Y BTech_ School of Computer Engineering & Technology_ 2020-21 39
Parity flag
The parity flag will be set whenever the number of bit “1” are even.
AX AH AL Accumulator
EU registers BX BH BL Base Register
CX CH CL Count Register
DX DH DL Data Register
SP Stack Pointer
BP Base Pointer
SI Source Index Register
DI Destination Index Register
FLAGS
Microprocessor and Interfacing Techniques (CET208A) _T5_S Y BTech_ School of
10/09/2021 Computer Engineering & Technology_ 2020-21 45
Programmers Model
10/09/2021 Microprocessor and Interfacing Techniques (CET208A) _T5_S Y BTech_ School of Computer Engineering & Technology_ 2020-21 46
The Stack
• The stack is used for temporary storage of
information such as data or addresses.
Example: Assuming that SS = 1000h and SP = 0xF820. This means that current
stack top is the physical address 0x1F820 (this is due to memory segmentation in 8086).
The next two machine instructions of the program are:
PUSH AX
PUSH BX
• These first instruction shall push the value stored in AX (16-bit register) to the stack.
This is done by subtracting a value of 2 (2 bytes) from SP.
• The new value of SP becomes 0xF81E. The CPU then copies the value of AX to the
memory word whose physical address is 0x1F81E.
POP BX
POP AX
POP BX copies the word at 0x1F81C (which is the old value of BX) to BX,
then increases SP by 2. SP now is 0xF81E.
Adder
CS
IP
10/09/2021 Microprocessor and Interfacing Techniques (CET208A) _T5_S Y BTech_ School of Computer Engineering & Technology_ 2020-21 54
The Memory as seen by 8086
The segment registers are 16 bit in size.
A segment register points to a block of 64Kbytes of memory.
Each segment register can track or access such 16 blocks (2 16 = 64KB)
16 X 64KB = 1MB
The address bus of 8086 is 20 bit which implies it can access 1MB of memory
The instruction pointer points to every instruction within a 64KB block of CODE
Memory
The Index Registers point to data variables / bytes within a block of 64KB of DATA
memory
The Stack pointer tracks the stack variables within a 64KBblock of STACK Memory
10/09/2021 Microprocessor and Interfacing Techniques (CET208A) _T5_S Y BTech_ School of Computer Engineering & Technology_ 2020-21 55
CS : IP Physical Address
0000 : 0000 00000 The maximum memory which 8086 can access using
0000 : FFFF 0FFFF
1000 : 0000 10000
20bit address bus
1000 : FFFF 1FFFF = 1 MB
2000 : 0000 20000
2000 : FFFF 2FFFF
3000 : 0000 30000 Total number of blocks of 64KB each
3000 : FFFF 3FFFF = Total Memory / Block size
= 1MB / 64 KB = 16
A000 : 0000 A0000
A000 : FFFF AFFFF
B000 : 0000 B0000 Only 4 blocks or segment are active at a time in
B000 : FFFF BFFFF memory :
C000 : 0000
C000 : FFFF
C0000
CFFFF CODE segment
D000 : 0000 D0000 DATA segment
D000 : FFFF DFFFF
STACKsegment and the
E000 : 0000 E0000
E000 : FFFF EFFFF EXTRA segment
F000 : 0000 F0000
F000 : FFFF FFFFF
Active memory = 4 x 64 KB = 256KB
Microprocessor and Interfacing Techniques (CET208A) _T5_S Y BTech_ School of
10/09/2021 Computer Engineering & Technology_ 2020-21 56
Memory Segmentation & Re-locatability
• Memory is a group of ‘n’ 64K blocks as seen by 8086 processor
• wherein n= 16 (16 X 64K = 1MB : the max. addressable memory by 8086)
• Each memory location has two addresses – Base and Offset
• Base address is the address of the first line / byte of a 64K block or segment
• Offset address is the line / byte number from base of a block
• Base address is defined by OS at run time
• Offset address defined by Compiler at compilation time
• This two dimensional addressing makes a program “Relocatable” i.e. a
program may get loaded in any block available and still be executed
successfully.
• Base address defined in Segment Register
• Offsets in IP or Index registers
Microprocessor and Interfacing Techniques (CET208A) _T5_S Y BTech_ School of
10/09/2021 Computer Engineering & Technology_ 2020-21 57
Memory The Physical or Actual Address
Addr. Data/Instr CS : IP
0000 : 0005H
IP 0005H 0005H I6H
IP 0004H 0004H I5H 0000 : 0004H
IP 0003H 0003H I4H
0000 : 0003H
IP 0002H 0002H I3H
IP 0001H 0001H I2H 0000 : 0002H
0000H I1H 0000 : 0001H
IP 0000H
Assume AX = 00H
0000H
After Executing
MOV AX, 1234H
MOV BX, AX
MOV BH, AH
MOV BH, AL
MOV BH, AX
ERROR
MOV BX, AH
Microprocessor and Interfacing Techniques (CET208A) _T5_S Y BTech_ School of
10/09/2021 Computer Engineering & Technology_ 2020-21 61
DIRECT ADDRESSING
10/09/2021 64
Microprocessor and Interfacing Techniques (CET208A) _T5_S Y BTech_ School of Computer Engineering & Technology_ 2020-21
For accessing data in memory
4.Register relative addressing eg.: MOV CX, [Bx+0004H]
5.Base relative-plus index addressing eg.: MOV AL,[BX+SI+10H]
6.String addressing modes eg. MOVSB, CMPSB
10/09/2021 Microprocessor and Interfacing Techniques (CET208A) _T5_S Y BTech_ School of Computer Engineering & Technology_ 2020-21 65
Assembly Language Program Development Tools
There are several tools available to support the programmer
of assembly language for better experience of programming.
They are as follows:
•
Editor
•
Assembler
•
Linker
•
Debuggers
10/09/2021 Microprocessor and Interfacing Techniques (CET208A) _T5_S Y BTech_ School of Computer Engineering & Technology_ 2020-21 66
The flow chart of ALP Tools
Edit
prog.asm
Assemble
Link
prog.exe prog.map
Debug Run
10/09/2021 Microprocessor and Interfacing Techniques (CET208A) _T5_S Y BTech_ School of Computer Engineering & Technology_ 2020-21 67
The flow chart of ALP Tools
10/09/2021 Microprocessor and Interfacing Techniques (CET208A) _T5_S Y BTech_ School of Computer Engineering & Technology_ 2020-21 68
ALP Tools :Editor
Editor
• Write new (.asm) programs
• Make changes to existing ones
Example: gedit, a GNU editor
10/09/2021 Microprocessor and Interfacing Techniques (CET208A) _T5_S Y BTech_ School of Computer Engineering & Technology_ 2020-21 69
ALP Tools : Assembler
10/09/2021 Microprocessor and Interfacing Techniques (CET208A) _T5_S Y BTech_ School of Computer Engineering & Technology_ 2020-21 70
ALP Tools : Linker
Linking Multiple Files
10/09/2021 Microprocessor and Interfacing Techniques (CET208A) _T5_S Y BTech_ School of Computer Engineering & Technology_ 2020-21 71
ALP Tools : Loader
The loader is a part of the operating system that will load
the program from secondary storage into primary storage
(i.e., main memory).
10/09/2021 Microprocessor and Interfacing Techniques (CET208A) _T5_S Y BTech_ School of Computer Engineering & Technology_ 2020-21 72
ALP Tools : Debugger
•Traces program execution
Either step-by-step, or
Using breakpoints
•It shows:
Source (.asm) code
Registers
Memory contents with address
10/09/2021 Microprocessor and Interfacing Techniques (CET208A) _T5_S Y BTech_ School of Computer Engineering & Technology_ 2020-21 73
Instruction set of 8086
Instructions in 8086 are mainly divided into following categories:
Data Transfer Instructions
Arithmetic Instruction
Bit manipulation Instruction
String Instruction
Program execution transfer Instruction
Processor control Instruction
10/09/2021 Microprocessor and Interfacing Techniques (CET208A) _T5_S Y BTech_ School of Computer Engineering & Technology_ 2020-21 74
Data Transfer Instructions
Instruction to transfer a word
MOV − copy the byte or word from the source to the destination.
POP − get a word from the top of the stack to the provided location.
10/09/2021 Microprocessor and Interfacing Techniques (CET208A) _T5_S Y BTech_ School of Computer Engineering & Technology_ 2020-21 75
Data Transfer Instructions
Instructions to transfer the address
LEA − load the address of operand into the provided register.
LDS − load DS register and other provided register from the memory
LES − load ES register and other provided register from the memory.
POPF − copy a word at the top of the stack to the flag register.
10/09/2021 Microprocessor and Interfacing Techniques (CET208A) _T5_S Y BTech_ School of Computer Engineering & Technology_ 2020-21 76
Data Transfer Instructions :MOV
MOV Des, Src:
It is used to copy the content of Source(Src) to Destination(Des)
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]
10/09/2021 Microprocessor and Interfacing Techniques (CET208A) _T5_S Y BTech_ School of Computer Engineering & Technology_ 2020-21 77
Data Transfer Instructions :MOV
10/09/2021 Microprocessor and Interfacing Techniques (CET208A) _T5_S Y BTech_ School of Computer Engineering & Technology_ 2020-21 78
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 Destination.
Des can be a general purpose register, segment register (except CS) or memory
location.
E.g.: POP AX
10/09/2021 Microprocessor and Interfacing Techniques (CET208A) _T5_S Y BTech_ School of Computer Engineering & Technology_ 2020-21 79
Data Transfer Instructions using Stack
LIFO stack
TOS SP 0008 H 0008H
PUSH AX :
TOS SP 0006 H AL AH
PUSH AX :
0008H
0006 H AL AH
TOS SP 0004 H BL BH
10/09/2021 Microprocessor and Interfacing Techniques (CET208A) _T5_S Y BTech_ School of Computer Engineering & Technology_ 2020-21 80
Data Transfer Instructions :
XCHG Des, Src:
10/09/2021 Microprocessor and Interfacing Techniques (CET208A) _T5_S Y BTech_ School of Computer Engineering & Technology_ 2020-21 81
Data Transfer Instructions :
XLAT/XLATB
load in AL reg [BX+AL]
section .data
arr db 30h, 31h, 32h, 33h, 34h, 35h, 36h, 37h, 38h, 39h,, 41h, 42h, 43h, 44h,45h,46h
Section .text
Global _start
_start:
----
MOV BX, arr
MOV AL, 05 +5 BX
XLATB
30h 31h 32h 33h 34h 35h 36h 37h ------ 46h
---
End
AL = [BX+05] = 35h
10/09/2021 Microprocessor and Interfacing Techniques (CET208A) _T5_S Y BTech_ School of Computer Engineering & Technology_ 2020-21 82
Data Transfer Instructions :
LEA Register, Src:
It loads a 16-bit register with the offset address of the data specified by the Src.
10/09/2021 Microprocessor and Interfacing Techniques (CET208A) _T5_S Y BTech_ School of Computer Engineering & Technology_ 2020-21 83
Data Transfer Instructions :
LDS dest,src (Load pointer using DS)
10/09/2021 Microprocessor and Interfacing Techniques (CET208A) _T5_S Y BTech_ School of Computer Engineering & Technology_ 2020-21 85
Arithmetic instructions
Instructions to perform addition
10/09/2021 Microprocessor and Interfacing Techniques (CET208A) _T5_S Y BTech_ School of Computer Engineering & Technology_ 2020-21 86
Arithmetic instructions
Instructions to perform subtraction
SUB − subtract the byte from byte/word from word.
NEG − negate each bit of the provided byte/word and add 1/2’s complement.
IDIV − divide the signed word by byte or signed double word by word.
CBW − fill the upper byte of the word with the copies of sign bit of the lower byte.
CWD − fill the upper word of the double word with the sign bit of the lower word.
10/09/2021 Microprocessor and Interfacing Techniques (CET208A) _T5_S Y BTech_ School of Computer Engineering & Technology_ 2020-21 88
Arithmetic instructions
ADD Des, Src: ADC Des, Src:
It adds a byte to byte or a word It adds the two operands with
to word. CF.
It effects AF, CF, OF, PF, SF, ZF It effects AF, CF, OF, PF, SF,
flags. ZF flags.
E.g.: E.g.:
ADD AL, 74H ADC AL, 74H
ADD DX, AX ADC DX, AX
ADD AX, [BX] ADC AX, [BX]
Microprocessor and Interfacing Techniques (CET208A) _T5_S Y BTech_ School of Computer Engineering & Technology_
10/09/2021 2020-21 89
Arithmetic instructions
SUB Des, Src: SBB Des, Src:
It subtracts a byte from byte or a It subtracts the two operands and
word from word. also the borrow from the result.
It effects AF, CF, OF, PF, SF, ZF It effects AF, CF, OF, PF, SF, ZF
flags. flags.
For subtraction, CF acts as borrow E.g.:
flag. SBB AL, 74H
E.g.:
SBB DX, AX
SUB AL, 74H
SBB AX, [BX]
SUB DX, AX
SUB AX, [BX]
Microprocessor and Interfacing Techniques (CET208A) _T5_S Y BTech_ School of Computer Engineering & Technology_
10/09/2021 2020-21 90
Arithmetic instructions
DAA (Decimal Adjust after
Example: If AL = 35H, BL = 47H
Addition) ADD AL,BL
It is used to make sure that the DAA
result of adding two BCD
numbers is adjusted to be a AL = 7CH
correct BCD number. Thus with DAA
10/09/2021 Microprocessor and Interfacing Techniques (CET208A) _T5_S Y BTech_ School of Computer Engineering & Technology_ 2020-21 91
Arithmetic instructions
AAA (ASCII Adjust after Addition):
Implied Addressing Mode
Converts number in AL register from
ASCII to Hex
i.e. If lower nibble of AL > 9 then Other ASCII Instructions:
1. AL=AL+6 AAS (ASCII Adjust after
Subtraction)
2. AH=AH+1
AAM (ASCII Adjust after
3. AL=AL AND 0FH Multiplication)
This instruction does not have any AAD (ASCII Adjust Before
operand. Division)
Example: AL = 34H & BL = 33H
ADD AL, BL
AAA
Will result in AL= 07H
10/09/2021 Microprocessor and Interfacing Techniques (CET208A) _T5_S Y BTech_ School of Computer Engineering & Technology_ 2020-21 92
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. And Flags-OF, CF
Unused bits of destination register is always filled with sign bit
IMUL Src:
It is a signed multiplication instruction.
Microprocessor and Interfacing Techniques (CET208A) _T5_S Y BTech_ School of Computer Engineering & Technology_
10/09/2021 2020-21 93
MUL instruction
8 bit multiplication • 16 bit multiplication
• AL is multiplicand • AX is multiplicand
• AX keep the result • DX:AX keep the result
Microprocessor and Interfacing Techniques (CET208A) _T5_S Y BTech_ School of Computer Engineering & Technology_
10/09/2021 2020-21 95
DIV instruction
Microprocessor and Interfacing Techniques (CET208A) _T5_S Y BTech_ School of Computer Engineering & Technology_
10/09/2021 2020-21 97
Arithmetic instructions
INC Src: DEC Src:
It increments the byte or word by one. It decrements the byte or word by
The operand can be a register or one.
memory location. The operand can be a register or
E.g.: INC AX memory location.
E.g.: DEC AX
INC [SI]
DEC [SI]
10/09/2021 Microprocessor and Interfacing Techniques (CET208A) _T5_S Y BTech_ School of Computer Engineering & Technology_ 2020-21 98
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 CF, ZF, SF are
modified to indicate the result.
NEG Src:
Microprocessor and Interfacing Techniques (CET208A) _T5_S Y BTech_ School of Computer Engineering & Technology_
10/09/2021 2020-21 99
CMP instruction
Microprocessor and Interfacing Techniques (CET208A) _T5_S Y BTech_ School of Computer Engineering & Technology_
10/09/2021 2020-21 100
Arithmetic instructions
10/09/2021 Microprocessor and Interfacing Techniques (CET208A) _T5_S Y BTech_ School of Computer Engineering & Technology_ 2020-21 101
Bit Manipulation instructions
Instructions to perform logical operation
NOT − invert each bit of a byte or word.
AND − adding each bit in a byte/word with the corresponding bit in another byte/word.
OR − multiply each bit in a byte/word with the corresponding bit in another byte/word.
XOR − perform Exclusive-OR operation over each bit in a byte/word with the corresponding bit in another
byte/word.
SHR − shift bits of a byte/word towards the right and put zero(S) in MSBs.
SAR − shift bits of a byte/word towards the right and copy the old MSB into the new MSB.
10/09/2021 Microprocessor and Interfacing Techniques (CET208A) _T5_S Y BTech_ School of Computer Engineering & Technology_ 2020-21 102
Bit Manipulation instructions
ROL − rotate bits of byte/word towards the left, i.e. MSB to LSB and to Carry Flag [CF].
ROR − rotate bits of byte/word towards the right, i.e. LSB to MSB and to Carry Flag [CF].
RCR − rotate bits of byte/word towards the right, i.e. LSB to CF and CF to MSB.
RCL − rotate bits of byte/word towards the left, i.e. MSB to CF and CF to LSB.
Microprocessor and Interfacing Techniques (CET208A) _T5_S Y BTech_ School of Computer Engineering & Technology_
10/09/2021 2020-21 103
Bit Manipulation instructions
Instructions to perform logical operation:
AND − Used for adding each bit in a byte/word with the corresponding bit in another byte/word.
CF,OF=0
PF,SF,ZF flags affected. AF-Undefinded.
Microprocessor and Interfacing Techniques (CET208A) _T5_S Y BTech_ School of Computer Engineering & Technology_
10/09/2021 2020-21 104
Bit Manipulation instructions
OR − Used to multiply each bit in a byte/word with the corresponding bit in another byte/word.
EX: OR AH,CL
OR BL,80H
OR CX, TABLE[BX][SI]
CF,OF=0
PF,SF,ZF flags affected. AF-Undefind.
XOR − Used to perform Exclusive-OR operation over each bit in a byte/word with the
corresponding bit in another byte/word.
EX: TEST AL,BH ;AND BH with AL, no result stored. Update PF, SF, ZF.
Microprocessor and Interfacing Techniques (CET208A) _T5_S Y BTech_ School of Computer Engineering & Technology_
10/09/2021 2020-21 106
Bit Manipulation instructions
CF
1 0 0 0 0 0 0 1 0
src- reg/mem
Microprocessor and Interfacing Techniques (CET208A) _T5_S Y BTech_ School of Computer Engineering & Technology_
10/09/2021 2020-21 108
Bit Manipulation instructions
10/09/2021 Microprocessor and Interfacing Techniques (CET208A) _T5_S Y BTech_ School of Computer Engineering & Technology_ 2020-21 109
Bit Manipulation instructions
SHR src, 1
CF
1 0 0 0 0 0 0 1
0
SAR src, 1
CF
1 0 0 0 0 0 0 1
10/09/2021 Microprocessor and Interfacing Techniques (CET208A) _T5_S Y BTech_ School of Computer Engineering & Technology_ 2020-21 110
Bit Manipulation instructions
Microprocessor and Interfacing Techniques (CET208A) _T5_S Y BTech_ School of Computer Engineering & Technology_
10/09/2021 2020-21 111
Bit Manipulation instructions
Microprocessor and Interfacing Techniques (CET208A) _T5_S Y BTech_ School of Computer Engineering & Technology_
10/09/2021 2020-21 112
Bit Manipulation instructions
ROL src, 1
CF
1 0 0 0 0 0 0 1
ROR src, 1
After Rotation - Reg =11000000, CF = 1
CF
1 0 0 0 0 0 0 1
Microprocessor and Interfacing Techniques (CET208A) _T5_S Y BTech_ School of Computer Engineering & Technology_
10/09/2021 2020-21 113
Bit Manipulation instructions
RCL Des, Count:
It rotates bits of byte or word right, by count.
LSB to MSB then MSB is transferred to CF and CF to LSB.
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. And recent bit to the CF
(Carry flag)
Microprocessor and Interfacing Techniques (CET208A) _T5_S Y BTech_ School of Computer Engineering & Technology_
10/09/2021 2020-21 114
Bit Manipulation instructions
RCL src, 1
CF
0 1 0 0 0 0 0 0 1
CF
1 0 0 0 0 0 0 1 0
Microprocessor and Interfacing Techniques (CET208A) _T5_S Y BTech_ School of Computer Engineering & Technology_
10/09/2021 2020-21 115
Bit Manipulation instructions
RCR Des, Count:
It rotates bits of byte or word left, by count.
MSB to LSB then LSB is transferred to CF and CF to MSB.
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. And recent bit to the CF (Carry flag)
10/09/2021 Microprocessor and Interfacing Techniques (CET208A) _T5_S Y BTech_ School of Computer Engineering & Technology_ 2020-21 116
String instructions
String : Sequence of bytes or words
8086 instruction set includes instruction for string movement, comparison, scan, load and store.
Offset or effective address of the source operand is stored in SI register and that of the
destination operand is stored in DI register.
INS/INSB/INSW − Used as an input string/byte/word from the I/O port to the provided memory location.
OUTS/OUTSB/OUTSW − Used as an output string/byte/word from the provided memory location to the
I/O port.
SCAS/SCASB/SCASW − scan a string and compare its byte with a byte in AL or string word with a word
in AX.
LODS/LODSB/LODSW − store the string byte into AL or string word into AX.
Microprocessor and Interfacing Techniques (CET208A) _T5_S Y BTech_ School of Computer Engineering & Technology_
10/09/2021 2020-21 118
String instructions
LODS / LODSB / LODSW:
MOVS / MOVSB / MOVSW:
It causes TRANSFER of byte or word from one
It causes moving of byte or word string to another.
from one string to another. In this instruction, the source string is in Data
Segment referred by DS:SI transferred to
In this instruction, Accumulator.
Ex:.
the source string is in Data MOV SI,STRING1
CLD
Segment referred by DS:SI
LODS
destination string is in Extra
Loads one byte from STRING1 into AL
Segment referred by ES:DI.
• Lodsb
Ex: MOVSB str1,str2 Lodsw
Microprocessor and Interfacing Techniques (CET208A) _T5_S Y BTech_ School of Computer Engineering & Technology_
10/09/2021 2020-21 119
String instructions
section .data
string1 DB 'HELLO‘
section .bss
String2 resb 5
Section .text
global _start
_start:
mov si,string1
mov di,string2
CLD ; DF = 0
MOVSB ; mov 1st byte
MOVSB ; mov 2nd byte
10/09/2021 Microprocessor and Interfacing Techniques (CET208A) _T5_S Y BTech_ School of Computer Engineering & Technology_ 2020-21 120
String instructions
STOS / STOSB / STOSW: CMPS Des, Src:
10/09/2021 Microprocessor and Interfacing Techniques (CET208A) _T5_S Y BTech_ School of Computer Engineering & Technology_ 2020-21 122
String instructions
REP
REPZ/ REPE While CX 0 and ZF = 1, repeat execution of
string instruction and
(Repeat CMPS or SCAS (CX) (CX) – 1
until ZF = 0)
REPNZ/ REPNE
While CX 0 and ZF = 0, repeat execution of
(Repeat CMPS or SCAS string instruction and
until ZF = 1) (CX) (CX) - 1
Microprocessor and Interfacing Techniques (CET208A) _T5_S Y BTech_ School of Computer Engineering & Technology_
10/09/2021 2020-21 123
REP/REPZ/REPNZ
. section .data . section .data
string1 DB 'HELLO‘
string1 DB 'HELLO‘
section .bss
section .bss String2 resb 5
String2 resb 5
section .text
section .text global _start
global _start _start:
_start:
MOV SI, STRING1 ; source
MOV SI, STRING1 ; source MOV DI, STRING2 ; destination
MOV DI, STRING2 ; destination CLD ; DF = 0
CLD ; DF = 0
MOV CX, 5
MOVSB ; mov 1st byte
REP MOVSB ; copies 5 chars
MOVSB ; mov 2nd byte
10/09/2021 Microprocessor and Interfacing Techniques (CET208A) _T5_S Y BTech_ School of Computer Engineering & Technology_ 2020-21 124
String Instructions
10/09/2021 Microprocessor and Interfacing Techniques (CET208A) _T5_S Y BTech_ School of Computer Engineering & Technology_ 2020-21 125
Branch/Program Execution Transfer Instructions
These instructions cause change in the sequence of the execution of instruction.
This change can be a conditional or sometimes unconditional.
The conditions are represented by flags.
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.
Microprocessor and Interfacing Techniques (CET208A) _T5_S Y BTech_ School of Computer Engineering & Technology_
10/09/2021 2020-21 126
Branch/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.
Microprocessor and Interfacing Techniques (CET208A) _T5_S Y BTech_ School of Computer Engineering & Technology_
10/09/2021 2020-21 127
Branch/Program Execution Transfer Instructions
Mnemonic Meaning Jump Condition
JB Jump if Below CF = 1
JC Jump if Carry CF = 1
JE Jump if Equal ZF = 1
JZ Jump if Zero ZF = 1
10/09/2021
Microprocessor and Interfacing Techniques (CET208A) _T5_S Y BTech_ School of Computer Engineering & Technology_ 2020-21
128
Branch/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.
INTO (Interrupt on overflow):
It causes the 8086 to do an indirect far call a procedure which is written by the user to
handle the overflow condition.
IRET: To return the execution to the interrupted program
10/09/2021 Microprocessor and Interfacing Techniques (CET208A) _T5_S Y BTech_ School of Computer Engineering & Technology_ 2020-21 129
Machine Control Instructions
HLT (Halt) :- It causes the processor to enter in to the halt state. It can be stop by
INTR,NMI or RESET pin
NOP (No Operation) :- It causes the processor to enter in to the wait state for 3 Clock
cycles.
WAIT :- It causes the processor to enter in to the ideal state. Can be stop by TEST,
INTR OR NMI pin
LOCK :- This instruction prevents other processors to take the control of shared
resources. For e.g LOCK IN AL,80H
Microprocessor and Interfacing Techniques (CET208A) _T5_S Y BTech_ School of Computer Engineering & Technology_ 2020-21
10/09/2021 130
Processor Control/Flag Manipulation Instructions
STC: STD:
It sets the carry flag to 1. It sets the direction flag to 1.
CLC: If it is set, string bytes are accessed
It clears the carry flag to 0. from higher memory address to lower
memory address.
CMC:
It complements the carry flag.
CLD:
STI: It clears the direction flag to 0.
It sets the Interrupt flag to 1. If it is reset, the string bytes are
CLI: accessed from lower memory address
to higher memory address.
It clears the Interrupt flag to 0.
Microprocessor and Interfacing Techniques (CET208A) _T5_S Y BTech_ School of Computer Engineering & Technology_
10/09/2021 2020-21 131
Interrupt Instructions
Microprocessor and Interfacing Techniques (CET208A) _T5_S Y BTech_ School of Computer Engineering & Technology_
10/09/2021 2020-21 132
Comparison of Macro and Procedure
Macro Procedure
•Used for a small number of instructions • Used for a unique task required repeatedly in
used repeatedly in the program the program
•Transfer of control does not take place. • Transfer of control is between main program
and procedure.
•MACRO call is replaced by
instructions by assembler. • call to a procedure is executed during run
time by the processor.
Microprocessor and Interfacing Techniques (CET208A) _T5_S Y BTech_ School of Computer Engineering & Technology_
10/09/2021 2020-21 133
Pin Diagram: 8086
Microprocessor and Interfacing Techniques (CET208A) _T5_S Y BTech_ School of Computer Engineering & Technology_
10/09/2021 2020-21 134
INTEL 8086 - Pin Details
Power Supply
5V 10%
Ground
Reset
Registers, seg
regs, flags
CS: FFFFH, IP:
0000H
If high for
minimum 4
Clock clks
Duty cycle: 33%
10/09/2021 135
INTEL 8086 - Pin Details
Address/Data Bus:
Contains address Address Latch Enable:
bits A15-A0 when ALE
is 1 & data bits D15 – When high,
multiplexed
D0 when ALE is 0.
address/data bus
contains address
information.
10/09/2021 136
INTEL 8086 - Pin Details
INTR
When 1 and IF=1, microprocessor
INTERRUPT prepares to service interrupt. INTA
becomes active after current instruction
completes.
INTA
Interrupt Acknowledge generated by
the microprocessor in response to
INTR. Causes the interrupt vector to be
Non - maskable put onto the data bus.
interrupt NMI
Non-maskable interrupt. Similar to
INTR except IF flag bit is not consulted
.
Interrupt
acknowledge
Interrupt
request
10/09/2021 137
INTEL 8086 - Pin Details
• HOLD Direct
Requests Memory
a direct memory access (DMA).
When 1, microprocessor stops and places
address, data and control bus in high-
Access
impedance state.
• HLDA (Hold Acknowledge)
Indicates that the microprocessor has
Hold entered the hold state.
Hold
acknowledge
10/09/2021 Details
INTEL 8086 - Pin Details
Address/Status Bus
Address bits A19 –
A16 & Status bits S6 –
S3
10/09/2021 Details
Microprocessor and Interfacing Techniques (CET208A) _T5_S Y BTech_ School of Computer Engineering & Technology_ 2020-21
139
INTEL 8086 - Pin Details
1,1: No selection
10/09/2021 140
INTEL 8086 - Pin Details
Min/Max mode
Minimum Mode: +5V
Maximum Mode: 0V
Maximum Mode
Pins
10/09/2021 141
INTEL 8086 - Pin Details
WR
Microprocessor is driving data bus
to memory or an I/O device. When
Read Signal 0, data bus contains valid data
M/IO
Indicates if address is a Memory or
IO address
RD
Write Signal When 0, data bus is driven by
memory or an I/O device
DT/R (Data Transmit/Receive)
Data bus is transmitting/receiving
Memory or I/0 data
DEN (Data bus Enable) Activates
Data external data bus buffers.
Transmit/Recei
ve
S2 S1 S0
000: INTA
001: read I/O port
010: write I/O port
011: halt
100: code access Status Signal
101: read memory
110: write memory Inputs to Bus controller
111: none -passive (8288) to generate
eliminated signals due
to max mode.
10/09/2021 143
Maximum Mode - Pin Details
Lock Output
Used to lock peripherals
off the system
DMA Controller
Activated by using the
LOCK: prefix on any (Request/Grant)
instruction
Lock Output
10/09/2021 144
Microprocessor and Interfacing Techniques (CET208A) _T5_S Y BTech_ School of Computer Engineering & Technology_ 2020-21
Maximum Mode - Pin Details
QS1 QS0
00: Queue is idle
01: First byte of opcode
10: Queue is empty
11: Subsequent byte of
opcode
Queue Status
Used by numeric
coprocessor (8087)
10/09/2021 145
Use of BHE# / BLE#
10/09/2021 Microprocessor and Interfacing Techniques (CET208A) _T5_S Y BTech_ School of Computer Engineering & Technology_ 2020-21 146
Use of BHE# / BLE#
10/09/2021 Microprocessor and Interfacing Techniques (CET208A) _T5_S Y BTech_ School of Computer Engineering & Technology_ 2020-21 147