MPMC Unit 1 PPT 8086 Microprocessor 19BM302
MPMC Unit 1 PPT 8086 Microprocessor 19BM302
19BM302
24-Aug-22 1
Micro Processor & Micro Controllers
MEMORY MEMORY
Ref: B Ram
24-Aug-22 2
Block diagram of Micro Computer
Data Bus
Input
Device
I/O
Ports CPU MEMORY
Control Bus Control Bus
Output
Device
Address Bus
24-Aug-22 3
Schematic Diagram / Internal parts of Micro Processor
Accumulator
Ref: B Ram
24-Aug-22 4
Micro Processor & Micro Controllers
Syllabus Overview
24-Aug-22 5
Micro Processor & Micro Controllers
Syllabus Overview
24-Aug-22 7
TEXT BOOKS:
2. Mazidi “The 8051 Microcontroller and Embedded Systems Using Assembly and C”,
2nd edition, Pearson education.
3. Andrew N. Sloss, Donimic Symes, Chris Wright, “ARM System Developer’s Guide”,
Elsevier, 1st edition, 2007.
REFERENCE BOOKS:
24-Aug-22 9
Introduction to 8086 Micro Processor
Unit-1 Topics:
Evolution Of Microprocessors,
8086 Microprocessor, Architecture,
Register Model,
Memory Segmentation,
Physical Address Generation,
Addressing Modes,
Pin Diagram
Instruction Set,
Interrupts of 8086,
Interrupt Vector Table.
24-Aug-22 10
Definition of microprocessor:
24-Aug-22 11
Evolution of Microprocessors
The no. of bits processed by the CPU at a time are called word length.
(or)
(or)
The no. of bits identified by the CPU at a time are called word length.
24-Aug-22 12
Fifth Generation Pentium
64 bit processors
3. 8086 processor has 20 address lines A19-A0, and 16 data lines D15-D0.
8086 has 20 bit address lines to access memory. Hence it can access 220 = 1 MB memory location.
8086 has 16-bit address lines to access I/O devices, hence it can access 216 = 64K I/O location
3. 8086 processor has 20 address lines A19-A0, and 16 data lines D15-D0.
The data lines are multiplexed with lower order 16 address lines, and then
the multiplexed address and data lines areAD15-AD0.
The remaining higher order 4 address lines A16-A19 are multiplexing with the status
Lines S3-S6.
4. It has three versions based on the frequency of operation
a) 8086 : 5MHz b) 8086-2: 8MHz c) 8086-1: 10 MHz
5. 8086 processor is available in 40-pin DIP(Dual in line Package).
24-Aug-22 14
Features of 8086: - cont’d…
24-Aug-22 15
Architecture of 8086 Microprocessor
Register organization of 8086
Why Registers ?
Registers in 8086
1. General Data Registers (4) 2. Segment Registers (4) 3. Flag Register (1)
4. Pointers and Index Registers (5)
24-Aug-22 16
Architecture of 8086 Microprocessor
Register organization of 8086
AX AH AL Accumulator SP
CS
Base used to BP
DS FLAGS
BX BH BL store OFFSET for
forming physical / PSW
address ES SI
CX CH CL Counter in string &
loop instructions SS DI
DX DH DL Destination/
Implicit IP
Segment registers
DX Register: Data register can be used as a port number in I/O operations and implicit
operand or destination in case of few instructions. In integer 32-bit multiply and divide
instruction the DX register contains high-order word of the initial or resulting number.
24-Aug-22 18
Register organization of 8086 cont’d…
Segment Registers of 8086
8086 processor addresses segmented version of memory ( 220 =1MB size).
Size of each segment is 64KB. (220 = 24 216 = 24. 64KB= Sixteen 64KB logical segments)
Physical address =[ Base address x 10 ] + OFFSET address
24-Aug-22 20
8086 Microprocessor
Architecture Registers and Special Functions
AX 16-bit Accumulator Stores the 16-bit results of arithmetic and logic operations
AL 8-bit Accumulator Stores the 8-bit results of arithmetic and logic operations
BX Base register Used to hold base value in base addressing mode to access memory
data
CX Count Register Used to hold the count value in SHIFT, ROTATE and LOOP instructions
DX Data Register Used to hold data for multiplication and division operations
SP Stack Pointer Used to hold the offset address of top stack memory
BP Base Pointer Used to hold the base value in base addressing using SS register to
access data from stack memory
SI Source Index Used to hold index value of source operand (data) for string
instructions
DI Destination Index Used to hold the index value of destination operand (data) for string
operations 21
Register organization of 8086 cont’d…
U U U U OF DF IF TF SF ZF U AC U PF U CY
OV=overflow flag DF=direction flag TF=trap flag IF=interrupt flag SF=sign flag
ZF=zero flag AC=auxiliary carry flag PF=parity flag CY=carry flag
24-Aug-22 22
8086 Microprocessor
Execution Unit (EU)
Flag Register
Architecture Auxiliary Carry Flag
lowest nibble, i.e, bit three during This flag is set, when there is
addition, or borrow for the lowest a carry out of MSB in case of
nibble, i.e, bit three, during addition or a borrow in case
subtraction. of subtraction.
This flag is set, when the This flag is set, if the result of This flag is set to 1, if the lower
result of any computation the computation or comparison byte of the result contains even
is negative performed by an instruction is number of 1’s ; for odd number
zero of 1’s set to zero.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
OF DF IF TF SF ZF AF PF CF
Tarp Flag
Over flow Flag If this flag is set, the processor
This flag is set, if an overflow occurs, i.e, if the result of a signed enters the single step execution
operation is large enough to accommodate in a destination
mode by generating internal
register. The result is of more than 7-bits in size in case of 8-bit
signed operation and more than 15-bits in size in case of 16-bit interrupts after the execution of
sign operations, then the overflow will be set. each instruction
Direction Flag Interrupt Flag
This is used by string manipulation instructions. If this flag bit
is ‘0’, the string is processed beginning from the lowest Causes the 8086 to recognize
address to the highest address, i.e., auto incrementing mode. external mask interrupts; clearing IF
Otherwise, the string is processed from the highest address disables these interrupts.
towards the lowest address, i.e., auto decrementing mode. 23
Architecture of 8086 Microprocessor
The 8086 CPU is divided into two independent functional units:
•Bus Interface Unit (BIU)
•Execution Unit (EU) Ref: Hall
Architecture of 8086 Microprocessor
Functions of Bus Interface Unit
1. It sends address of the memory or I/O.
2. It fetches instruction from memory.
3. It reads data from port/memory.
4. It writes data into port/memory.
5. It supports instruction queuing.
6. It provides the address relocation facility.
Note:
BIU contains the circuit for physical address calculations
and
a pre-decoding instruction byte queue (6 Bytes long)
24-Aug-22 25
Architecture of 8086 Microprocessor
Instruction Queue
To increase the execution speed,
BIU fetches as many as six instruction bytes ahead to time from memory.
All six bytes are then held in first in first out ( FIFO) 6 byte register called instruction queue.
This pre fetching operation of BIU may be in parallel with execution operation of EU,
24-Aug-22 26
PIPELINING
Fetching the next instruction while the current instruction
executes is called pipelining.
24-Aug-22 27
Architecture of 8086 Microprocessor
Execution Unit (EU)
The functions of execution unit are:
• To tell BIU where to fetch the instructions or data from.
• To decode the instructions.
• To execute the instructions.
• The EU contains the control circuitry to perform various internal operations.
• A decoder in EU decodes the instruction fetched memory to generate
different internal or external control signals required to perform the operation.
• EU has 16-bit ALU, which can perform arithmetic and logical operations on 8-bit
as well as 16-bit.
24-Aug-22 28
Architecture of 8086 Microprocessor
Execution Unit (EU)
a). ALU
b). Register Set.
c). Operand & Flag Register.
d). Control System.
24-Aug-22 29
Architecture of 8086 Microprocessor
ALU in Execution Unit (EU)
a).ALU (Arithmetic and Logical Unit):- It performs Arithmetic and Logical operations on
8 bits/16bits. The Bit Capacity of ALU is 16bits.
i) NOT ii) AND iii) OR iv) EX-OR v) TEST vi) Logical Shift
24-Aug-22 31
Advantages due to Memory Segmentation
• In 8086 microprocessor, memory is divided into 4 segments.
• It allows the memory addressing capacity to be 1 Mbyte even though the
address associated with individual instruction is only 16-bit.
• It allows instruction code, data, stack and portion of program to be more
than 64 KB long by using more than one code, data, stack segment, and
extra segment.
• It facilitates use of separate memory areas for program, data and stack.
• It permits a program or its data to be put in different areas of memory, each
time the program is executed i.e. program can be relocated which is very
useful in multiprogramming.
• Program can work on several data sets by reloading the DS register.
24-Aug-22 32
Architecture of 8086 Microprocessor
Memory Segments of 8086
Segment Registers generate memory address when combined with other in the microprocessor.
Code Segment (CS): The CS register is used for addressing a memory location in the
Code Segment of the memory, where the executable program is stored.
Data Segment (DS): The DS contains most data used by program. Data are accessed in the
Data Segment by an offset address or the content of other register that holds the offset
address.
Stack Segment (SS): SS defined the area of memory used for the stack.
Extra Segment (ES): ES is additional data segment that is used by some of the string to hold
the destination data.
24-Aug-22 34
Physical Address Generation
8086 processor addresses segmented version of memory ( 220 =1MB size).
Size of each segment is 64KB. (220 = 24 216 = 24. 64KB= Sixteen 64KB logical segments)
3. If the Stack segment register contains 3000H and the stack pointer register contains
8434H, What is the physical address of the top of the stack?
4. If the 8086 execution unit calculates an effective address of 14A3H and DS contains
7000H, What Physical Address will the BIU produce?
24-Aug-22 37
Addressing Modes of 8086
The different ways in which a processor can access data are called
addressing modes
1. Immediate AM
2. Register AM
3. Memory Addressing Modes:
i. Direct AM ii. Register Indirect AM iii. Register Relative AM iv. Indexed AM
v. Based Indexed AM vi. Based Indexed Displacement AM
4. Implied AM
5. I/O AM : a) I/O Direct AM b) I/O Indirect AM
6. Segment AM :
i. Intra Segment Direct AM ii. Inter Segment Direct AM
iii. Intra Segment Indirect AM iv. Inter Segment Indirect AM
24-Aug-22 40
Addressing Modes
An Addressing mode shows how the data is represented in the instruction.
1. Immediate AM 2. Register AM
3. Direct AM 4. Register Indirect AM
5. Register Relative AM 6. Based Indexed AM
7. Based Indexed Displacement AM 8. Implied AM
9. I/O Direct AM 10. I/O Indirect AM
11. Indexed AM 12. Intra Segment Direct AM
13. Inter Segment Direct AM 14. Intra Segment Indirect AM
15. Inter Segment Indirect AM
24-Aug-22 41
Ref: Brey
BX=0300H, SI=0200H, ARRAY=1000H , DS=1000H
24-Aug-22 42
BX=0300H, SI=0200H, ARRAY=1000H , DS=1000H
24-Aug-22 43
BX=0300H, SI=0200H, ARRAY=1000H , DS=1000H
Scaled MOV [BX +2* SI], AX Register AX DS*10H + BX+ 2*SI Memory
Index 1000*10H+ 0300H+0400H Address 10700H
24-Aug-22 44
Addressing Modes cont’d…
Ex:
MOV AX, BX ; 16-bit data transfer
24-Aug-22 48
Addressing Modes cont’d…
24-Aug-22 49
Addressing Modes cont’d…
24-Aug-22 50
Addressing Modes cont’d…
11. Indexed Addressing Mode: -
Here the data address is represented in the operand field through an index register
in an instruction.
24-Aug-22 51
Addressing Modes cont’d…
If the both source and destination appears in same segment then it is called
intra segment.
The destination address is directly placed in the operand field of the instruction.
If the both source and destination appears in different segment then it is called
inter segment.
The destination address is directly placed in the operand field of the instruction.
24-Aug-22 53
Instruction Set of 8086
24-Aug-22 54
Instruction Set of 8086:-
Instructions in the instruction set of 8086 are classified into different types,
24-Aug-22 55
Instruction Set of 8086:- cont’d…
24-Aug-22 56
Instruction Set of 8086:- cont’d…
The another operand for the instruction are the default registers (AX or DX)
and these are not represented in the operand field of the instruction.
24-Aug-22 58
Instruction Set of 8086:- cont’d…
24-Aug-22 59
Instruction Set of 8086:- cont’d…
The Data Transfer Instructions are those, which transfers the DATA
(means copy of data) from any one source to any one destination.
The 8086 processor doesn’t support the following types of Data transfer Operations
24-Aug-22 60
Instruction Set of 8086:- cont’d…
24-Aug-22 61
1. Data Transfer Instructions cont’d…
The specified word is any 16-bit register content or any memory location contents.
For this instruction execution the content of SP is decrement by ‘2’.
Ex: - PUSH BX
PUSH [1250H]
24-Aug-22 62
1. Data Transfer Instructions cont’d…
Ex: - POP CX
POP [2050H]
24-Aug-22 63
1. Data Transfer Instructions cont’d…
24-Aug-22 64
1. Data Transfer Instructions cont’d…
24-Aug-22 65
1. Data Transfer Instructions cont’d…
1.3. Address Transfer Instructions
i) LEA: - Load Effective Address of operand into specified register (16-bit)
ii) LDS: - It loads destination register and DS, from memory source.
The offset is placed in the destination register and the segment base is placed in
DS.
To use this instruction the word at the lower order memory address must contain
the offset and the word at the higher order address must contain the segment
base address.
The offset is placed in the destination register and the segment base is placed in ES.
This instruction is very similar to LDS except that it initializes ES instead of DS.
24-Aug-22 67
1. Data Transfer Instructions cont’d…
24-Aug-22 68
1. Data Transfer Instructions cont’d…
• 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.
21-Nov-2010 69
2. Arithmetic Instructions
24-Aug-22 70
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.
– i.e., All conditional flags will be effected.
– E.g.:
• ADD AL, 74H
• ADD DX, AX
• ADD AX, [BX]
24-Aug-22 71
Arithmetic Instructions
• ADC Des, Src:
– It adds the two operands with CF.
– It effects AF, CF, OF, PF, SF, ZF flags.
– i.e., All conditional flags will be effected.
– E.g.:
• ADC AL, 74H
• ADC DX, AX
• ADC AX, [BX]
24-Aug-22 72
Arithmetic Instructions
24-Aug-22 73
Arithmetic Instructions
24-Aug-22 74
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.
– i.e., All conditional flags except CF will be effected.
– Destination operand must not be an immediate
number.
– E.g.: INC AX
» INC [BX]
» INC [2050H]
24-Aug-22 75
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.
– i.e., All conditional flags except CF will be effected.
– E.g.: DEC AX
» DEC [BX]
» DEC [2050H]
24-Aug-22 76
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)
24-Aug-22 77
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.
24-Aug-22 78
Arithmetic Instructions
• NEG Src:
– It creates 2’s complement of a given number.
– That means, it changes the sign of a number.
– Ex:
» NEG AX
» NEG [1250H]
» NEG [BX]
24-Aug-22 79
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.
– Ex:
» CMP AX, BX
» CMP AX, [2050H]
» CMP BX,, 3050H
24-Aug-22 80
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.
– Ex: MUL BL; MUL [2050H]; MUL CX
• IMUL Src:
– It is a signed multiplication instruction.
24-Aug-22 81
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.
24-Aug-22 82
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.
24-Aug-22 83
3. Logical or Bit Manipulation Instructions
Logical Instructions
NOT
AND
OR
XOR
TEST
24-Aug-22 84
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
24-Aug-22 85
Logical or 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.
Ex: - NOT AX
NOT [2050H]
24-Aug-22 86
Bit Manipulation Instructions
• AND Des, Src:
– 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.
24-Aug-22 87
Bit Manipulation Instructions
• OR Des, Src:
– 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.
• Ex: - OR AX, BX
OR AX, [3050H]
OR AX, 1200H
OR [3040H], 1250H
24-Aug-22 88
Bit Manipulation Instructions
• XOR Des, Src:
– 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.
24-Aug-22 89
Bit Manipulation Instructions
• TEST Des, Src:
• This instruction ANDs the contents of a source byte or word
with the contents of specified destination byte or word.
• Flags are updated but neither operand is changed .
• TEST instruction is often used to set flags before a condition
jump instruction.
• Ex: - TEST AL, BH; AND BH with AL, updates flags but result not
stored.
– 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. SAL AX,1; MOV CL, 05H; SAL AX, CL
Cy= 0 1 0 1 1 0 1 1 1 0
Cy= 1 0 1 1 0 1 1 1 0
24-Aug-22 92
Bit Manipulation Instructions : Shift Instructions
• SHR Des, Count:
– It shift bits of byte or word right, by count.
– However, if the number of bits to be shifted is more than 1, then the count is
put in CL register.
0 1 0 1 0 1 0 0 1 Cy= 0
0 1 0 1 0 1 0 0 Cy= 1
24-Aug-22 93
Bit Manipulation Instructions : Shift Instructions
• SAR Des, Count:
– It shift bits of byte or word right, by count.
– However, if the number of bits to be shifted is more than 1, then the count is
put in CL register.
1 0 1 0 1 0 0 1 Cy= 0
1 1 0 1 0 1 0 0 Cy= 1
24-Aug-22 94
Bit Manipulation Instructions : Rotate Instructions
• ROL Des, Count:
– It rotates bits of byte or word left, by count.
Cy= 1 0 0 1 1 0 1 1 1
Cy= 0 0 1 1 0 1 1 1 0
24-Aug-22 95
Bit Manipulation Instructions : Rotate Instructions
• ROR Des, Count:
– It rotates bits of byte or word right, by count.
– However, if the number of bits to be shifted is more than 1, then the count is
put in CL register.
1 0 1 0 1 0 0 1 Cy= 0
1 1 0 1 0 1 0 0 Cy= 1
24-Aug-22
96
Bit Manipulation Instructions : Rotate Instructions
• RCL Des, Count:
– This instruction rotates all the bits in a specified byte or word some number of
bits position to the left along with the carry flags.
– MSB is placed as a new carry and previous carry in place as new LSB.
Eg.
RCL CX, 1
MOV CL, 04H
RCL AL, CL
Cy= 1 0 0 1 1 0 1 1 1
Cy= 0 0 1 1 0 1 1 1 1
24-Aug-22 97
Bit Manipulation Instructions : Rotate Instructions
• RCR Des, Count:
– RCR instruction : RCR destination , count
– This instruction rotates all bits in a specified byte or word some number of bit
positions to the right along with the carry flag.
– LSB is placed as a new carry and previous carry is in place as a new MSB.
1 0 1 0 1 0 0 1 Cy= 0
0 1 0 1 0 1 0 0 Cy= 1
24-Aug-22
98
5. Program Flow control Instructions
• 2 types.
– i. Uncondtional Branching Instructions : CALL RET JMP
24-Aug-22 99
5.1: Unconditional Branching Instructions
• CALL Des: Main ISR
– This instruction is used to call a subroutine or function or procedure,
from a main program.
– Ex: CALL [CX] ; CALL DWORD PTR [BX]
– The address of next instruction after CALL is saved onto stack.
– 1. NEAR CALL : is used when the subprogram and main program both
appears in same segment
– 2. FAR CALL: is used when the subprogram and main program appears
in different segments.
24-Aug-22 101
5.2: Conditional Branching Instructions
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 No Carry CF = 0
JNE Jump if Not Equal ZF = 0
JNZ Jump if Not Zero ZF = 0
JPE Jump if Parity is Even PF = 1
JPO Jump if Parity is Odd PF = 0
JZ Jump if Zero ZF = 1
24-Aug-22 102
6. Loop related Instructions
• Loop Des:
– This is a looping instruction.
24-Aug-22 103
7. Machine control / Processor Control Instructions
• These instructions are used to control the machine operation.
• These instructions are also called ‘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.
24-Aug-22 104
7. Machine control / Processor Control Instructions cont’d…
• ESC: Escape
• NOP : No Operation
24-Aug-22 105
8. Flag Manipulation Instructions
• STC:
– It Sets the carry flag to 1.
• CLC:
– It clears the carry flag to 0.
• CMC:
– It complements the carry flag.
24-Aug-22 106
8. Flag Manipulation Instructions cont’d…
• STD:
– It sets the direction flag to 1.
– If it is set, string bytes are accessed from higher memory
address to lower memory address. Auto Decrement
• 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. Auto Increment
– STI : Set the Interrupt Flag
– CLI : Clear the Interrupt Flag
24-Aug-22 107
9. 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.
– The length of the string byte must be stored in CX.
• 4. SCAS String:
– It scans a string.
– It compares the String with byte in AL or with word in AX.
– Whenever a match to the specified operand, is found in the
string, Execution stops and ZF will SET.
– If no match, ZF is RESET.
24-Aug-22 109
9. String Instructions cont’d…
• 6. 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.
24-Aug-22 111
9. String Instructions cont’d…
After executing ISR , the control is transferred back again to the main program.
In 8086 system, the 1st 1KB of memory 00000H to 003FC H is set as table
for storing the starting address of ISR.
Starting address of ISR, is called as Interrupt vector or interrupt pointer. Hence the
table is called as Interrupt vector table or interrupt pointer table .
Interrupt vector table
Interrupts of 8086 cont’d…
One pin that acknowledges, INTA (pin 24), the interrupt requested
on INTR.
Hardware and Software Interrupts
The nonmaskable interrupt is Cannot be ignored by the microprocessor.
generated by en external device, Generates a Type 2 interrupt (address
trough a rising edge on the NMI pin. 0008H in the Interrupt vector table)
The maskable interrupts (00…FFH) can • an external device, trough a high logic
Hardware be generated by: level on the INTR pin (the external
interrupts (IF (interrupt flag) in FLAGS register device has to specify the interrupt
enables or disables (masks) the P to number).
accept maskable interrupts.) • microprocessor itself (i.e. when trying
to divide by 0), (the interrupt number is
hardware defined).
Software interrupts (exceptions) using the INT instruction
(followed by the interrupt number (type)).
Interrupt priority
Divide-error Highest
INT, INTO
NMI
INTR
Single-step Lowest
Hardware Interrupts of 8086 cont’d…
INTR
INTR is a maskable hardware interrupt.
The interrupt can be enabled/disabled using STI/CLI instructions
(or)
using more complicated method of updating the FLAGS register with the
help of the POPF instruction.
NMI
The content of IP & CS of ISR will be taken from the N*4 as OFFSET address
and 0000 as segment address.
A break point is used to examine the CPU and memory after the execution
of a group of Instructions.
whereas other instructions of the form “INT nn” are 2 byte instructions.
Address/Data bus
A0 Indication
0 0 Whole word is received/transmitted [D15-D0 data lines are active]
0 1 Byte from Odd memory bank [D15-D8 data lines are active]
1 0 Byte from Even memory bank [D7-D0 data lines are active]
1 1 Passive
MN/ MX*
MINIMUM / MAXIMUM
RESET (Input)
CLK
• If READY=0 then the processor will insert WAIT states between T3 and T4.
TEST*
Pins 24 -31
Pins 24 -31
0 1 Byte from Odd memory bank [D15-D8 data lines are active]
1 0 Byte from Even memory bank [D7-D0 data lines are active]
1 1 Passive
M/ Transfer Type
0 0 1 I/O read
0 1 0 I/O write
1 0 1 Memory read
1 1 0 Memory write
0 0 Extra (ES)
0 1 Stack (SS)
1 1 Data (DS)
In 8086-based system the lower 8 lines of data bus, Do- D7, are connected
to even bank memory ICs and
The upper 8 lines of data bus, D8- D15 are connected to odd bank memory .
These two signals selectively allow reading from or writing into either
an odd byte location, even byte location, or both.
0 1 Byte from Odd memory bank [D15-D8 data lines are active]
1 0 Byte from Even memory bank [D7-D0 data lines are active]
1 1 Passive
The system designer should allot equal address space in odd and even
bank for both EPROM and RAM.
Similarly, the RAM capacity of the system can be implemented in two ICs
or in multiple ICs.
This choice depends on the availability of memory IC and the system designer.
8/24/2022 6:27 AM 145
PHYSICAL MEMORY ORGANIZATION cont’d...
LOOP L1 35 B4 B4 B4 B4 B4 B4 B4
MOV [SI],AX SI 0300 00 35 35 35 35 35 35 35
INT 03
HLT
LARGEST NO IN AN ARRAY AL CX=06
MOV SI,0300 13 13 13 13 13 13 13
MOV CX,0006 68 68 68 68 68 68 68
MOV AX,0000
E9 E9 E9 E9 E9 E9 E9
L1: CMP AX,[SI]
JAE L2 4A 4A 4A 4A 4A 4A 4A
MOV AX,[SI] SI 0301 B4 B4 B4 B4 B4 B4 B4
L2: INC SI
SI 0300 35 35 35 35 35 35 35
INC SI
LOOP NE L1
MOV [SI],AX
INT 03
HLT
SMALLEST NUMBER IN AN ARRAY
MOV SI,0300
MOV CX,0003
MOV AX,FFFF
L1 : CMP AX,[SI]
JB L2
MOV AX,[SI]
L2 : INC SI
INC SI
LOOP NE L1
MOV [SI],AX
INT 03
HLT
AM OF N NO’S
MOV BX,0500
MOV CL,[BX]
MOV DI,0000
INC BX
L1: MOV AL,[BX]
MOV AH,00
ADD DI, AX
INC BX
LOOP L1
MOV DL,[0500]
MOV AX,DI
DIV DL
INT 03
HLT
SUM OF N NATURAL NO’S SUM OF SQUARES OF ‘N’ SUM OF CUBES OF N
MOV AX,0005 NATURAL NUMBERS NATURAL NO’S
MOV BX,AX
INC BX MOV CX,[3000] MOV CX,[3000]
MUL BX MOV BX,0001 MOV BX,0001
MOV CL,02 L1: MOV AX,BX L1: MOV AX,BX
DIV CL MUL AX MUL AX
INT 03 ADD [3002],AX MUL BX
HLT INC BX ADD [3002],AX
DEC CX INC BX
Hint: n(n+1)/2 JNZ L1 DEC CX
INT 03 JNZ L1
HLT INT 03
HLT
ASCENDING ORDER DESCENDING ORDER
Assume CS:CODE,DS:DATA
DATA SEGMENT
CODE SEGMENT
NUM1 DB 04H DUP(0)
MOV AX,DATA
NUM2 DB 04H DUP(0)
MOV DS,AX
RESULT DB 04H DUP(0)
DATA ENDS
LEA SI,NUM1
LEA DI,NUM2
END
LEA BX,RESULT
MOV CX,0004 H