SlideShare a Scribd company logo
MC932-MICROPROCESSORS
AND ITS APPLICATIONS
Course teach by
P.Karthikeyan.,MTech
Asst Professor-3
VCET,Madurai
1
Dept of ECE,VCET Madurai
Objective of the course
• Understand the Microprocessor architecture
and assembly language programming flow for
the development and debugging in embedded
applications like mobile, set top box and
navigation in high level languages.
• Understand the basics for the hardware
protocols like UART,PCI and USB for the
application development in embedded systems.
2
Dept of ECE,VCET Madurai
UNIT-I
THE 8086 PROCESSOR -
SOFTWARE ASPECTS
3
Dept of ECE,VCET Madurai
Evolution of Microprocessors
4
Dept of ECE,VCET Madurai
8086 MP Overview
• Intel 8086 Microprocessors are the basis of all
IBM-PC compatible computers
(8086 introduced in 1978, first IBM-PC released in 1981)
• All Intel, AMD and other advanced
microprocessors are based on and are
compatible with the original 8086.
• At Power Up and Reset time, Pentiums,
Athlons etc all look like 8086 processors.
5
Dept of ECE,VCET Madurai
8086 Architecture Overview
• Intel 8086 is a 16b microprocessor:
– 16b data registers, 16b ALU
• Width of external data bus:
– 8086: 16b
• Width of external address bus: 16b+4b=20b
• Segment: Offset memory model
• Little-Endian Data Format
• The 8086 used an instruction queue to speed up
performance
• While the processor is decoding and executing an
instruction, its bus interface can be reading new
instructions, since at that time the bus is not actually in use
6
Dept of ECE,VCET Madurai
8086 Architecture
7
Dept of ECE,VCET Madurai
Basic Internal Architecture Of 8086
• The 8086 make use of this idle time by pre-fetching the
next instruction while the current instruction is being
executed.
• Here the bus is always busy.
• The 8086 contains two internal units; the execution unit
(EU) and the bus interface unit (BIU).
• The BIU is responsible for fetching an instruction or the
operand of an instruction from the memory.
• The EU is responsible for executing the instructions.
• The 8086 both are able to utilize the bus with maximum
efficiency because both contain internal memory in the form of
a queue.
• The 8086 queue is 2 bytes wide and three locations deep. It is
therefore able to hold three 16-bit numbers.
8
Dept of ECE,VCET Madurai
Bus Interface Unit (BIU)
• The BIU contains a prefetch queue, a bus controller,
segment registers and the instruction pointer.
• The main purposes of the BIU are:
1. To keep the prefetch queue filled with instructions.
2. To generate and accept the control signals.
3. To provide the system with a memory address or I/O port
number.
4. To act as a window between the EU and memory for
data.
9
Dept of ECE,VCET Madurai
Bus Interface Unit (BIU)
• Instruction Queue: the next instructions or data can be fetched from
memory while the processor is executing the current instruction
– The memory interface is slower than the processor execution
time so this speeds up overall performance
• Segment Registers:
– CS, DS, SS and ES are 16b registers
– Used with the 16b Base registers to generate the 20b address
– Allow the 8086 to address 1MB of memory
• Instruction Pointer (IP) contains the Offset Address of the next
instruction, the distance in bytes from the address given by the
current CS register
10
Dept of ECE,VCET Madurai
Execution Unit (EU)
• The purpose of the EU is to carry out instructions that are
fetched from the prefetch queue.
• It contains; an Arithmetic and Logic Unit(ALU), an
instruction register, and a register array.
• The ALU performs arithmetic and logic operations on
memory and or register data.
• The instruction register receives the instructions from the
prefetch queue. From here these instructions are decoded to
direct the operation of the execution unit.
• The register array holds information temporarily. It also
contains pointers or index registers used to address operand
data located in the memory.
11
Dept of ECE,VCET Madurai
System Architecture
• Three types of buses are
 Address Bus
 Data Bus
 Control Bus
• The address bus provides the memory address to the system memory
and also I/O addresses to the I/O devices. The 8086 has a 20-bit
address bus.
• The data bus transfers data between the microprocessor and the
memory and I/O attached to the system. The 8086 has a16-bit data
bus.
• The control bus provides control signals that cause the memory or
I/O to perform a READ or WRITE operation. It consists of three
signals RD, WR and IO/M.
• The 8086 having address of 1M bytes of memory because they both
contain a 20-bit address bus.
12
Dept of ECE,VCET Madurai
8086/8088 Register File
CS
DS
SS
ES
AH
BH
CH
DH
AL
BL
CL
DL
IP
SP
BP
SI
DI
0
7
0
15
0
7
0
15
Accumulator
Base
Counter
Data
Code Segment
Data Segment
Stack Segment
Extra Segment
Instruction Pointer
Stack Pointer
Base Pointer
Source Index
Destination Index
}
}
}
AX
BX
CX
DX
13
Dept of ECE,VCET Madurai
8086/8088 Register File (cont)
Flags Register
x x x x OF DF IF TF SF ZF x AF x PF x CF
0
15
Status and Control Bits Maintained in Flags Register
– Generally Set and Tested Individually
– Nine 1-bit flags in 8086; Seven are unused
14
Dept of ECE,VCET Madurai
Flags Register
• Carry Flag (CF) - this flag is set to 1 when there is an unsigned overflow.
When there is no overflow this flag is set to 0.
• Parity Flag (PF) - this flag is set to 1 when there is even number of one bits
in result, and 0 when there is odd number of one bits.
• Auxiliary Flag (AF) - set to 1 when there is an unsigned overflow for low
nibble (4 bits).
• Zero Flag (ZF) - set to 1 when result is zero. For non-zero result this flag is
set to 0.
• Sign Flag (SF) - set to 1 when result is negative. When result is positive it
is set to 0. (This flag takes the value of the most significant bit.)
• Trap Flag (TF) - Used for on-chip debugging.
• Interrupt enable Flag (IF) - when this flag is set to 1 CPU reacts to
interrupts from external devices.
• Direction Flag (DF) - this flag is used by some instructions to process data
chains, when this flag is set to 0 - the processing is done forward, when this
flag is set to 1 the processing is done backward.
• Overflow Flag (OF) - set to 1 when there is a signed overflow.
15
Dept of ECE,VCET Madurai
Status Flags
CF Carry Flag Arithmetic Carry/Borrow
OF Overflow Flag Arithmetic Overflow
ZF Zero Flag Zero Result; Equal Compare
SF Sign Flag Negative Result; Non-Equal Compare
PF Parity Flag Even Number of “1” bits
AF Auxiliary Carry Used with BCD Arithmetic
Indicate Current Processor Status
16
Dept of ECE,VCET Madurai
Control Flags
DF Direction Flag Auto-Increment/Decrement
– used for “string operations”
IF Interrupt Flag Enables Interrupts
– allows “fetch-execute” to be interrupted
TF Trap Flag Allows Single-Step
– for debugging; causes interrupt after each op
Influence the 8086 During Execution Phase
17
Dept of ECE,VCET Madurai
8086/8088 Register File (cont)
0
15
IP Contains Address of NEXT Instruction to be Fetched
– Automatically Incremented
– Programmer can control with jump and branch
Instruction Pointer Register
18
Dept of ECE,VCET Madurai
AX, BX, CX, DX
• Can Be Used Separately as 1-byte Registers
AX = AH:AL
• Temporary Storage to Avoid Memory Access
– Faster Execution
– Avoids Memory Access
• Some Special uses for Certain Instructions
AH
BH
CH
DH
AL
BL
CL
DL
0
7 0
7
Accumulator
Base
Counter
Data
General Purpose Registers
AX
BX
CX
DX
19
Dept of ECE,VCET Madurai
AX, BX, CX, DX - Some Specialized Uses
AX, Accumulator
Main Register for Performing Arithmetic
mult/div must use AH, AL
“accumulator” Means Register with Simple ALU
BX, Base
Point to Translation Table in Memory
Holds Memory Offsets; Function Calls
CX, Counter
Index Counter for Loop Control
DX, Data
After Integer Division Execution - Holds Remainder
AH
BH
CH
DH
AL
BL
CL
DL
0
7 0
7
Accumulator
Base
Counter
Data
AX
BX
CX
DX
20
Dept of ECE,VCET Madurai
CS, DS, ES, SS - Segment Registers
CS, Code Segment
Used to “point” to Instructions
Determines a Memory Address (along with IP)
Segmented Address written as CS:IP
DS, Data Segment
Used to “point” to Data
Determines Memory Address (along with other registers)
ES, Extra Segment allows to Data Address Registers
SS, Stack Segment
Used to “point” to Data in Stack Structure (LIFO)
Used with SP or BP
SS:SP or SS:BP are valid Segmented Addresses
Contains “Base Value” for Memory Address
21
Dept of ECE,VCET Madurai
IP, SP, BP, SI, DI - Offset Registers
IP, Instruction Pointer
Used to “point” to Instructions
Determines a Memory Address (along with CS)
Segmented Address written as CS:IP
SI, Source Index; DI, Destination Index
Used to “point” to Data
Determines Memory Address (along with other registers)
DS, ES commonly used
SP, Stack Pointer;BP, Base Pointer
Used to “point” to Data in Stack Structure (LIFO)
Used with SS
SS:SP or SS:BP are valid Segmented Addresses
These can also be used as General Registers !!!!!!
Contains “Index Value” for Memory Address
22
Dept of ECE,VCET Madurai
Memory Segmentation
• x86 Memory Partitioned into Segments
 8086: maximum size is 64K (16-bit index reg.)
 8086: can have 4 active segments (CS, SS, DS, ES)
 8086: 2-data; 1-code; 1-stack
• Why have segmented memory ?
– Other microprocessors could only address 64K since
they only had a single 16-bit MAR (or smaller).
Segments allowed computers to be built that could use
more than 64K memory (but not all at the same time).
23
Dept of ECE,VCET Madurai
ADD
Memory System
Address Lines
0000
Index Reg. Segment Reg.
Physical Address
0
0
0
15
15
19
Portion of BIU Circuitry
CS
ES
SS
DS
IP
Dedicated Segment Registers
Dedicated Index Registers
BP
DI
SI
SP
8086 Generating Physical Addresses
24
Dept of ECE,VCET Madurai
8086 20-bit Addresses
16-bit Segnment Base Address 0000
16-bit Offset Address
20-bit Physical Address
CS
IP
25
Dept of ECE,VCET Madurai
Segmented Addressing
CS
ES
SS
DS
IP
BP
DI
SI
SP
• Each Segment must begin at Paragraph Boundary
00000h
00010h
00020h
physical address memory
paragraph 1
paragraph 2
paragraph 3
• Each paragraph has phys. address that is multiple of 10h
• BIU is responsible for appending 0000 to Segment
– only need 16-bit segment registers
26
Dept of ECE,VCET Madurai
Segmented Memory (x86 Style)
CS
ES
SS
DS
Data
Segment
Stack
Segment
Extra
Segment
Code
Segment
Segment
Registers
System
Memory
• Segment Registers:
– Point to Base Address
• Index Registers:
– Contain Offset Value
• Notation (Segmented Address):
– CS:IP
– DS:SI
– ES:DI
– SS:BP
– SS:SP
00000h
FFFFFh
fragmentation
27
Dept of ECE,VCET Madurai
Segmented Memory Example
CS
ES
SS
DS
Data
Segment
Stack
Segment
Extra
Segment
Code
Segment
Segment
Registers
System
Memory
• Logical, Segmented Address:
0FE6:012Bh
• Offset, Index Address:
012Bh
• Physical Address:
0FE60h  65120
+ 012Bh  299
0FF8Bh  65149
00000h
FFFFFh
28
Dept of ECE,VCET Madurai
Segment Locations in Physical Memory
segment a segment b
segment c
segment d
segment e
0h 10000h 20000h 30000h
continuous
partially overlapped fully overlapped
Logical
Segments
Physical
Memory
Note that segments can overlap. This means that two different logical
addresses can refer to the same physical address (aliasing).
29
Dept of ECE,VCET Madurai
The offset is the distance in bytes from the start of the segment.
The offset is given by the IP for the Code Segment.
Instructions are always fetched with using the CS register.
The physical address is also called the absolute address
000000H
Memory
Segment Register
Offset
Physical or
Absolute Address
0
+
CS:
IP
0400H
0056H
4000H
4056H
0400
0056
04056H
CS:IP = 400:56
Logical Address
0FFFFFH
Left-shift 4 bits
The Code Segment
30
Dept of ECE,VCET Madurai
The Data Segment
Data is usually fetched with respect to the DS register.
The effective address (EA) is the offset.
The EA depends on the addressing mode.
Memory
Segment Register
Offset
Physical Address
+
DS:
EA
05C0
0050
05C00H
05C50H
05C0 0
0050
05C50H
DS:EA
000000
H
0FFFFFH
31
Dept of ECE,VCET Madurai
Addressing Modes
DATA1 DW 25H DATA1 is defined as a word (16-bit) variable, i.e., a
memory location that contains 25H.
DATA2 EQU 20H DATA2 is not a memory location but a constant.
Direct Addressing
MOV AX,DATA1 [DATA1]  AX, the contents of DATA1 is put into AX.
The CPU goes to memory to get data. 25H is put in AX.
Immediate Addressing
MOV AX,DATA2 DATA2 = 20H  AX, 20H is put in AX.
Does not go to memory to get data.
Data is in the instruction.
MOV AX, OFFSET DATA1
The assembler knows which mode to encode by the way the operands SAM and
FRED are defined.
Assembler directive, DW = Define Word
32
Dept of ECE,VCET Madurai
Addressing Modes
Register Addressing MOV AX,BX AX BX
Register Indirect Addressing MOV AX,[BX] AX DS:BX
Can use BX or BP -- Based Addressing (BP defaults to SS)
or DI or SI -- Indexed Addressing
The offset or effective address (EA) is in the base or index register.
Register Indirect with Displacement MOV AX,SAM[BX]
AX DS:BX + Offset SAM
Indexed with displacement
Based with displacement
Based-Indexed Addressing MOV AX,[BX][SI] EA = BX + SI
Based-Indexed w/Displacement MOV AX,SAM[BX][DI]
EA = BX + DI + offset SAM
AX DS:EA
where EA = BX + offset SAM
33
Dept of ECE,VCET Madurai
Addressing Modes
Branch Related Instructions
Intrasegment
(CS does not change)
Direct -- IP relative displacement
new IP = old IP + displacement
Allows program relocation with
no change in code.
Indirect -- new IP is in memory or a register.
All addressing modes apply.
Intersegment Direct -- new CS and IP are encoded in
(CS changes) the instruction.
Indirect -- new CS and IP are in memory.
All addressing modes apply
except immediate and register.
NEAR JUMPS and CALLS
FAR
34
Dept of ECE,VCET Madurai
Assembly Language
The Assembler is a program that reads the source program as
data and translates the instructions into binary machine code.
The assembler outputs a listing of the addresses and machine
code along with the
source code and a binary file (object file) with the machine code.
Most assemblers scan the source code twice -- called a two-pass
assembler.
• The first pass determines the locations of the labels or
identifiers.
• The second pass generates the code.
35
Dept of ECE,VCET Madurai
Assembly Language
To locate the labels, the assembler has a location counter.
This counts the number of bytes required by each instruction.
• When the program starts a segment, the location counter is
zero.
• If a previous segment is re-entered, the counter resumes the
count.
• The location counter can be set to any offset by the ORG
directive.
In the first pass, the assembler uses the location counter to
construct a symbol table which contains the offsets or values of the
various labels.
The offsets are used in the second pass to generate operand
addresses.
36
Dept of ECE,VCET Madurai
INSTRUCTION SET OF 8086
8086 instructions are categorized as
1)Data Copy/Transfer Instructions
2)Arithmetic and Logical Instructions
3)Branch Instructions
4)Loop Instructions
5)Machine Control Instructions
6)Flag Manipulation Instructions
7)Shift and Rotate Instructions
8)String Instructions
37
Dept of ECE,VCET Madurai
38
Dept of ECE,VCET Madurai
39
Dept of ECE,VCET Madurai
40
Dept of ECE,VCET Madurai
PUSH,POP,IN,OUT,XLAT,LAHF,SAHF
• PUSH -Push to Stack(Push operation decrements SP by
two and then stores the two byte contents of the operand on to
the stack)
• POP -Pop from Stack(The stack pointer incremented by
two. Popping register contents from stack memory)
• PUSHF -Push Flags
• POPF -Pop Flags
• IN -Input from Fixed Port/Variable port
• OUT -Output to Fixed Port/Variable port
• XLAT -Translate Byte to AL
• LAHF -Load AH with Flags
• SAHF -Store AH with Flags
41
Dept of ECE,VCET Madurai
42
Dept of ECE,VCET Madurai
43
Dept of ECE,VCET Madurai
44
Dept of ECE,VCET Madurai
45
Dept of ECE,VCET Madurai
46
Dept of ECE,VCET Madurai
47
Dept of ECE,VCET Madurai
48
Dept of ECE,VCET Madurai
Compare
• Compares the source operand(reg,imme data,mem loc)
with a destination operand(reg or mem loc).
• Comparison, it subtracts the source operand from the
destination operand.
• Both operands are equal zero flag is set. If the source
operand is greater than the destination operand, carry flag
is set or else carry flag is reset.
Examble
CMP BX,0100H Immediate
CMP [5000H],0100H Direct
CMP BX,[SI] Register indirect
CMP BX,CX Register
49
Dept of ECE,VCET Madurai
50
Dept of ECE,VCET Madurai
51
Dept of ECE,VCET Madurai
52
Dept of ECE,VCET Madurai
53
Dept of ECE,VCET Madurai
54
Dept of ECE,VCET Madurai
55
Dept of ECE,VCET Madurai
56
Dept of ECE,VCET Madurai
57
Dept of ECE,VCET Madurai
58
Dept of ECE,VCET Madurai
59
Dept of ECE,VCET Madurai
STRING MANIPULATION INSTRUCTIONS
• REP Repeat Instruction Prefix
• MOVSB/MOVSW Move String Byte or String Word
• CMPS Compare String Byte or String Word
• SCAS Scan String Byte or String Word
• LODS Load String Byte or String Word
• STOS Store String Byte or String Word
60
Dept of ECE,VCET Madurai
Unconditional Branch Instructions
• CALL Unconditional Call
• RET Return from the Procedure
• INT N Interrupt Type N
• INTO Interrupt on Overflow
• JMP Unconditional Jump
• IRET Return from ISR
• LOOP Loop Unconditionally
61
Dept of ECE,VCET Madurai
Conditional Jumps
Name/Alt Meaning Flag setting
JE/JZ Jump equal/zero ZF = 1
JNE/JNZ Jump not equal/zero ZF = 0
JL/JNGE Jump less than/not greater than or = (SF xor OF) = 1
JNL/JGE Jump not less than/greater than or = (SF xor OF) = 0
JG/JNLE Jump greater than/not less than or = ((SF xor OF) or ZF) = 0
JNG/JLE Jump not greater than/ less than or = ((SF xor OF) or ZF) = 1
JB/JNAE Jump below/not above or equal CF = 1
JNB/JAE Jump not below/above or equal CF = 0
JA/JNBE Jump above/not below or equal (CF or ZF) = 0
JNA/JBE Jump not above/ below or equal (CF or ZF) = 1
JS Jump on sign (jump negative) SF = 1
JNS Jump on not sign (jump positive) SF = 0
JO Jump on overflow OF = 1
JNO Jump on no overflow OF = 0
JP/JPE Jump parity/parity even PF = 1
JNP/JPO Jump no parity/parity odd PF = 0
JCXZ Jump on CX = 0 ---
62
Dept of ECE,VCET Madurai
Flag Manipulation
CLC - Clear carry flag
CMC - Complement carry flag
STC - Set carry flag
CLD - Clear direction flag
STD - Set direction flag
CLI - Clear interrupt flag
STI - Set interrupt flag
Processor Control Instructions
WAIT - Wait for Test input pin to go low
HLT - Halt the Processor
NOP - No operation
ESC - Escape to external device like
NDP(numeric co-processor)
LOCK - Bus lock instruction prefix
63
Dept of ECE,VCET Madurai
Assembler Directives
ASSUME Tells the assembler what segments to use.
SEGMENT Defines the segment name and specifies that the
code that follows is in that segment
ORG Originate or Origin: sets the location counter
END End of source code
ENDS End of segment
ENDP End of Procedure
NAME Give source module a name
OFFSET Offset of a label
DW Define word
DB Define byte
DQ Define Quad word
DT Define Ten Bytes
64
Dept of ECE,VCET Madurai
Assembler Directives
EQU Equate or equivalence
EVEN Align or Even memory address
EXTRN External
PUBLIC Public
GROUP Group the related segments
LABEL Assign current location count to a symbol
LENGTH Byte Length of a Label
LOCAL Lables,variables,constants or procedures declared
LOCAL in module
$ Current location count
PROC Procedure
PTR Pointer(FAR PTR,NEAR PTR)
SEG Segment of a Label
SHORT,TYPE,GLOBAL, “+&-”Operators
65
Dept of ECE,VCET Madurai
66
Interrupts
• Interrupt Types
– Hardware Interrupts: External event
– Software Interrupts: Internal event (Software
generated)
– Maskable and non-maskable interrupts
– Interrupt priority
• Interrupt Vectors and Interrupt Handlers
• Interrupt Controllers
Dept of ECE,VCET Madurai
67
The Purpose of Interrupts
• Interrupts are useful when interfacing I/O devices with low data-
transfer rates, like a keyboard or a mouse, in which case polling the
device wastes valuable processing time
• The peripheral interrupts the normal application execution,
requesting to send or receive data.
• The processor jumps to a special program called Interrupt Service
Routine to service the peripheral
• After the processor services the peripheral, the execution of the
interrupted program continues.
Printer Interrupt Modem Interrupt Modem Interrupt
Main Program
Main Program
Main Program
Main Program
Dept of ECE,VCET Madurai
BASIC INTERRUPT TERMINOLOGY
• Interrupt pins: Set of pins used in hardware interrupts
• Interrupt Service Routine (ISR) or Interrupt handler: code used
for handling a specific interrupt
• Interrupt priority: In systems with more than one interrupt
inputs, some interrupts have a higher priority than other
– They are serviced first if multiple interrupts are triggered
simultaneously
• Interrupt vector: Code loaded on the bus by the interrupting
device that contains the Address (segment and offset) of specific
interrupt service routine
• Interrupt Masking: Ignoring (disabling) an interrupt
• Non-Maskable Interrupt: Interrupt that cannot be ignored
(power-down)
Dept of ECE,VCET Madurai
Hardware Interrupts – Interrupt pins and timing
• x86 Interrupt Pins
– INTR: Interrupt Request. Activated by a peripheral device to interrupt the processor.
• Level triggered. Activated with a logic 1.
– /INTA: Interrupt Acknowledge. Activated by the processor to inform the interrupting
device the the interrupt request (INTR) is accepted.
• Level triggered. Activated with a logic 0.
– NMI: Non-Maskable Interrupt. Used for major system faults such as parity errors and
power failures.
• Edge triggered. Activated with a positive edge (0 to 1) transition.
• Must remain at logic 1, until it is accepted by the processor.
• Before the 0 to 1 transition, NMI must be at logic 0 for at least 2 clock cycles.
• No need for interrupt acknowledgement.
Vector
INTR
INTA΄
D7-D0
Dept of ECE,VCET Madurai
Software Interrupts
• Traps: (self-interrupt!)
– Single step mode
– Calls to Operating System (INT 21H - x86, SC –
PPC)
• Exceptions:
– Divide by zero
– Memory protection fault
Dept of ECE,VCET Madurai
Identifying Interrupt Source
• Software Polling,
– Checking each device
• Hardware Polling, (Daisy Chain),
• Hardware Identification (Vectored Interrupts).
Dept of ECE,VCET Madurai
Interrupt Processing
• Save state
– Disable interrupts for the duration of the ISR or allow it
to be interrupted too?
– Save program counter
– Save flags
– Save register values?
• Jump to interrupt service routine
– Location obtained by interrupt vector
• Process interrupt
• Restore state
– Load PC, flags, registers etc.
Dept of ECE,VCET Madurai
Interrupt Processing on the 8086
Microprocessor
• External interface sends an interrupt signal, to the Interrupt
Request (INTR) pin, (or an internal interrupt occurs.)
• The CPU finishes the present instruction (for a hardware
interrupt) and checks the INTR pin.
• If IF=0 the processor ignores the interrupt, else sends
Interrupt Acknowledge (INTA) to hardware interface.
• The interrupt type N is sent to the Central Processor Unit
(CPU) via the Data bus from the hardware interface.
• The contents of the flag registers are pushed onto the stack.
Dept of ECE,VCET Madurai
• Both the interrupt (IF – FR bit 9) and (TF – FR bit 8) flags are
cleared. This disables the INTR pin and the trap or single-step
feature.
• The contents of the code segment register (CS) are pushed onto the
Stack.
• The contents of the instruction pointer (IP) are pushed onto the
Stack.
• The interrupt vector contents are fetched, from (4 x N) and then
placed into the IP and from (4 x N +2) into the CS so that the next
instruction executes at the interrupt service procedure addressed by
the interrupt vector.
• While returning from the interrupt-service routine by the Interrupt
Return (IRET) instruction, the IP, CS and Flag registers are popped
from the Stack and return to their state prior to the interrupt.
Interrupt Processing on the 8086
Microprocessor
74
Dept of ECE,VCET Madurai
Interrupt Vectors
• The processor uses the interrupt vector to determine the address of
the ISR of the interrupting device.
• In the 8088/8086 processor as well as in the 80386/80486/Pentium
processors operating in Real Mode (16-bit operation), the interrupt
vector is a pointer to the Interrupt Vector Table.
– The Interrupt Vector Table occupies the address range from
00000H to 003FFH (the first 1024 bytes in the memory map).
– Each entry in the Interrupt Vector Table is 4 bytes long:
• The first two represent the offset address and the last two the
segment address of the ISR.
– The first 5 vectors are reserved by Intel to be used by the
processor.
• The vectors 5 to 255 are free to be used by the user.
Dept of ECE,VCET Madurai
Dept of ECE,VCET Madurai 76
Interrupt Vector Table
Type 0 POINTER
(DIVIDE ERROR)
Type 1 POINTER
(SINGLE STEP)
Type 2 POINTER
(NON-MASKABLE)
Type 3 POINTER
(BREAK POINT)
Type 4 POINTER
(OVERFLOW)
010H
00CH
008H
004H
000H
16 bits
CS base address
IP offset
Dept of ECE,VCET Madurai 77
03FFH
Type 5
Reserved
Type 31 (Reserved)
Type 32 (Available)
03FCH
080H
07FH
0014H
Reserved
Interrupts
(27)
Type 255 (Available)
Available
Interrupts
(224)
Setting up an Interrupt-Pointer Table
• The first 1 KB of memory is set aside as a table
for storing the starting addresses of ISRs
– these are addresses 00000H to 003FFH
– you need 4 bytes to store the CS and IP values for each
ISR
– thus the table can hold the addresses for 256 ISRs
• Terms
– Interrupt vector/pointer - the starting address of an ISR
– Interrupt vector/pointer table - the table containing the
starting addresses of the ISRs
78
Dept of ECE,VCET Madurai
Dept of ECE,VCET Madurai 79
Interrupt Vector Table
INT Number Physical Address
INT 00 00000
INT 01 00004
INT 02 00008
: :
: :
INT FF 003FC
Dept of ECE,VCET Madurai 80
Dedicated Interrupts
• Type 0 to Type 4 interrupts are dedicated to
specific interrupts
• Type 5 to Type 31 interrupts are reserved by
Intel for more complex microprocessors
• Type 32 to Type 255 interrupts can be user
specified for dealing with hardware or software
interrupts
Dept of ECE,VCET Madurai 81
Type 0 Interrupt Example
• Type 0 specifies a divide by zero interrupt
– Recall DIV instruction
• whenever a quotient from DIV or IDIV
operation is too large to fit in the result
register, a type 0 interrupt happens
automatically
• It’s up to the programmer to handle this interrupt
– one possible is to set a programmer-defined
error flag…BAD_DIV_FLAG
Dept of ECE,VCET Madurai 82
Initialization List
• Initialize the interrupt-vector table
– use the ES register
– the starting address of our type 0 ISR needs to
be in locations 00000H and 00002H
• Set up the data segment
– include a declaration for the BAD_DIV_FLAG
– Initialize DS
• Set up a stack
– Initialize SS and SP
Dept of ECE,VCET Madurai 83
Single-Step Interrupt - Type 1
• If the TF (trap flag) is set, a type 1 interrupt will
automatically occur
• To implement single-stepping, such as in a
debugger:
– set the trap flag
– write an ISR that saves all registers on the
stack, so they can be examined
– load the address of the ISR into the addresses
00004H and 00006H
Dept of ECE,VCET Madurai 84
Nonmaskable Interrupt - Type 2
• Type 2 interrupt automatically occurs when the
CPU receives a low-to-high transition on its NMI
pin
• this type of interrupt cannot be masked by any
program instructions
• normally used to signal that some external
system/device must be taken care of
– pressure sensor on a large steam boiler
– save data in case of a power failure
Dept of ECE,VCET Madurai 85
Breakpoint Interrupt -Type 3
• This type of interrupt is produced by executing an
INT 3 instruction
– no automatic triggers
• Useful for debugging
– many debuggers implement breakpoints by
inserting an INT 3 instruction before the
specified instruction
– the Type 3 ISR may then store all the registers
so that they can be examined by the user
Dept of ECE,VCET Madurai 86
Overflow Interrupt - Type 4
• This type of interrupt may be produced if
the OF (Overflow flag) is set… but not
automatically triggered
• OF will be set if the signed result of an
arithmetic operation on 2 signed numbers is
too large to be represented in the destination
– 01101100 (108 decimal) + 01010001 (81 decimal),
remember that these are signed!
Dept of ECE,VCET Madurai 87
Overflow Interrupt (cont.)
• Can handle OF error using a JO instruction
following arithmetic operation
• Can also use the INTO instruction
– this specifies to Interrupt on Overflow
– if OF is set (1), will execute ISR contained in
the type 4 addresses in the vector table
• INTO is advantageous because you can use the
same ISR for many programs
Dept of ECE,VCET Madurai 88
Software Interrupts
• How do I test out my ISR that handles a
type 2 interrupt without directly signaling
the NMI pin?
– Use a software interrupt
INT 2 ; test out NMI ISR
• You can specify values 0 - 255 (decimal) as
operands to the INT instruction
Dept of ECE,VCET Madurai 89
INTR Interrupts
• These are hardware interrupts
• can be disabled by clearing IF
CLI ; disable interrupts
• can be enabled by setting IF
STI ; enable interrupts
• The interrupt type is sent to the 8086 from an
external hardware device
– could be an 8259A priority interrupt controller
• Remember, IF is automatically cleared in response
to any type of 8086 interrupt
Dept of ECE,VCET Madurai 90
Why Disable INTR Interrupts?
Reason #1
– To prevent an INTR
interrupt from interrupting
a higher priority interrupt
– Interrupt priorities
• Highest - Divide
Error, INT n, INTO
• Lower - NMI
• Still Lower - INTR
• Lowest - Single-Step
Reason #2
-To prevent an interrupt from
continuously interrupting itself
The INTR input is active
high…whenever INTR input is high
and IF is set, the 8086 will be
interrupted
-After IRET, flag is popped
INTR could still possibly be
receiving the same high signal and
cause another interrupt
it is the responsibility of the
external hardware sending the
INTR signal to avoid this
problem

More Related Content

Similar to MICROPROCESSORS AND ITS APPLICATIONS UNIT-I.ppt

Module 1 8086
Module 1 8086Module 1 8086
Module 1 8086
Deepak John
 
8086 microprocessor-architecture-120207111857-phpapp01
8086 microprocessor-architecture-120207111857-phpapp018086 microprocessor-architecture-120207111857-phpapp01
8086 microprocessor-architecture-120207111857-phpapp01
destaw belay
 
8086 microprocessor-architecture-120207111857-phpapp01
8086 microprocessor-architecture-120207111857-phpapp018086 microprocessor-architecture-120207111857-phpapp01
8086 microprocessor-architecture-120207111857-phpapp01
Siva Raman
 
486 or 80486 DX Architecture
486 or 80486 DX Architecture486 or 80486 DX Architecture
486 or 80486 DX Architecture
Muthusamy Arumugam
 
20838382 microprocessor-8085-notes
20838382 microprocessor-8085-notes20838382 microprocessor-8085-notes
20838382 microprocessor-8085-notes
Ravali Sunki
 
microprocessor
 microprocessor microprocessor
microprocessor
ATTO RATHORE
 
UNIT 1.pptx
UNIT 1.pptxUNIT 1.pptx
UNIT 1.pptx
BASKARS53
 
8086 archi notes final
8086 archi notes final8086 archi notes final
8086 archi notes final
HarshitParkar6677
 
8086 archi notes final
8086 archi notes final8086 archi notes final
8086 archi notes final
HarshitParkar6677
 
The Intel 8086 microprocessor
The Intel 8086 microprocessorThe Intel 8086 microprocessor
The Intel 8086 microprocessor
George Thomas
 
Assembly_Language _Programming_UNIT.pptx
Assembly_Language _Programming_UNIT.pptxAssembly_Language _Programming_UNIT.pptx
Assembly_Language _Programming_UNIT.pptx
VickyThakur61
 
UNIT 1.pptx
UNIT 1.pptxUNIT 1.pptx
UNIT 1.pptx
srinath594128
 
Microprocessor 8086
Microprocessor 8086Microprocessor 8086
Microprocessor 8086
Aanjaney Singh Chauhan
 
Introduction to 8085svv
Introduction to 8085svvIntroduction to 8085svv
Introduction to 8085svv
Shivashekharayya Viraktamath
 
26677766 8086-microprocessor-architecture-110905125037-phpapp02
26677766 8086-microprocessor-architecture-110905125037-phpapp0226677766 8086-microprocessor-architecture-110905125037-phpapp02
26677766 8086-microprocessor-architecture-110905125037-phpapp02
Avijeet Negel
 
Ec 1303 microprocessor_its_applications
Ec 1303 microprocessor_its_applicationsEc 1303 microprocessor_its_applications
Ec 1303 microprocessor_its_applications
Merin Jesuraj
 
Presentation on 8086 microprocessor
Presentation on 8086 microprocessorPresentation on 8086 microprocessor
Presentation on 8086 microprocessor
Diponkor Bala
 
Embeded system
Embeded systemEmbeded system
Embeded system
SUneel Gupta
 
Architecture of 8086 microprocessor
Architecture of  8086 microprocessorArchitecture of  8086 microprocessor
Architecture of 8086 microprocessor
Anirban Saha Anik
 
EC 8691 Microprocessor and Microcontroller.pptx
EC 8691 Microprocessor and Microcontroller.pptxEC 8691 Microprocessor and Microcontroller.pptx
EC 8691 Microprocessor and Microcontroller.pptx
GobinathAECEJRF1101
 

Similar to MICROPROCESSORS AND ITS APPLICATIONS UNIT-I.ppt (20)

Module 1 8086
Module 1 8086Module 1 8086
Module 1 8086
 
8086 microprocessor-architecture-120207111857-phpapp01
8086 microprocessor-architecture-120207111857-phpapp018086 microprocessor-architecture-120207111857-phpapp01
8086 microprocessor-architecture-120207111857-phpapp01
 
8086 microprocessor-architecture-120207111857-phpapp01
8086 microprocessor-architecture-120207111857-phpapp018086 microprocessor-architecture-120207111857-phpapp01
8086 microprocessor-architecture-120207111857-phpapp01
 
486 or 80486 DX Architecture
486 or 80486 DX Architecture486 or 80486 DX Architecture
486 or 80486 DX Architecture
 
20838382 microprocessor-8085-notes
20838382 microprocessor-8085-notes20838382 microprocessor-8085-notes
20838382 microprocessor-8085-notes
 
microprocessor
 microprocessor microprocessor
microprocessor
 
UNIT 1.pptx
UNIT 1.pptxUNIT 1.pptx
UNIT 1.pptx
 
8086 archi notes final
8086 archi notes final8086 archi notes final
8086 archi notes final
 
8086 archi notes final
8086 archi notes final8086 archi notes final
8086 archi notes final
 
The Intel 8086 microprocessor
The Intel 8086 microprocessorThe Intel 8086 microprocessor
The Intel 8086 microprocessor
 
Assembly_Language _Programming_UNIT.pptx
Assembly_Language _Programming_UNIT.pptxAssembly_Language _Programming_UNIT.pptx
Assembly_Language _Programming_UNIT.pptx
 
UNIT 1.pptx
UNIT 1.pptxUNIT 1.pptx
UNIT 1.pptx
 
Microprocessor 8086
Microprocessor 8086Microprocessor 8086
Microprocessor 8086
 
Introduction to 8085svv
Introduction to 8085svvIntroduction to 8085svv
Introduction to 8085svv
 
26677766 8086-microprocessor-architecture-110905125037-phpapp02
26677766 8086-microprocessor-architecture-110905125037-phpapp0226677766 8086-microprocessor-architecture-110905125037-phpapp02
26677766 8086-microprocessor-architecture-110905125037-phpapp02
 
Ec 1303 microprocessor_its_applications
Ec 1303 microprocessor_its_applicationsEc 1303 microprocessor_its_applications
Ec 1303 microprocessor_its_applications
 
Presentation on 8086 microprocessor
Presentation on 8086 microprocessorPresentation on 8086 microprocessor
Presentation on 8086 microprocessor
 
Embeded system
Embeded systemEmbeded system
Embeded system
 
Architecture of 8086 microprocessor
Architecture of  8086 microprocessorArchitecture of  8086 microprocessor
Architecture of 8086 microprocessor
 
EC 8691 Microprocessor and Microcontroller.pptx
EC 8691 Microprocessor and Microcontroller.pptxEC 8691 Microprocessor and Microcontroller.pptx
EC 8691 Microprocessor and Microcontroller.pptx
 

More from kpkarthi2001

IOT_Embedded_Systems_industrail applications.ppt
IOT_Embedded_Systems_industrail applications.pptIOT_Embedded_Systems_industrail applications.ppt
IOT_Embedded_Systems_industrail applications.ppt
kpkarthi2001
 
C2S-Cat_I-Proposal-template_Institution_Startup-MSME_Details.pptx
C2S-Cat_I-Proposal-template_Institution_Startup-MSME_Details.pptxC2S-Cat_I-Proposal-template_Institution_Startup-MSME_Details.pptx
C2S-Cat_I-Proposal-template_Institution_Startup-MSME_Details.pptx
kpkarthi2001
 
LIGHTNING_FLASH_Real_Time_Forecast_03032023_00UTC.pptx
LIGHTNING_FLASH_Real_Time_Forecast_03032023_00UTC.pptxLIGHTNING_FLASH_Real_Time_Forecast_03032023_00UTC.pptx
LIGHTNING_FLASH_Real_Time_Forecast_03032023_00UTC.pptx
kpkarthi2001
 
Cyclone Predication using Machine Learing
Cyclone Predication using Machine LearingCyclone Predication using Machine Learing
Cyclone Predication using Machine Learing
kpkarthi2001
 
figure.ppt
figure.pptfigure.ppt
figure.ppt
kpkarthi2001
 
GB Dean(III) - 27.04.23 ppt.pptx
GB Dean(III)  - 27.04.23 ppt.pptxGB Dean(III)  - 27.04.23 ppt.pptx
GB Dean(III) - 27.04.23 ppt.pptx
kpkarthi2001
 
DDI0029G_7TDMI_R3_trm.pdf
DDI0029G_7TDMI_R3_trm.pdfDDI0029G_7TDMI_R3_trm.pdf
DDI0029G_7TDMI_R3_trm.pdf
kpkarthi2001
 
registration-customers.pdf
registration-customers.pdfregistration-customers.pdf
registration-customers.pdf
kpkarthi2001
 
8253
82538253

More from kpkarthi2001 (9)

IOT_Embedded_Systems_industrail applications.ppt
IOT_Embedded_Systems_industrail applications.pptIOT_Embedded_Systems_industrail applications.ppt
IOT_Embedded_Systems_industrail applications.ppt
 
C2S-Cat_I-Proposal-template_Institution_Startup-MSME_Details.pptx
C2S-Cat_I-Proposal-template_Institution_Startup-MSME_Details.pptxC2S-Cat_I-Proposal-template_Institution_Startup-MSME_Details.pptx
C2S-Cat_I-Proposal-template_Institution_Startup-MSME_Details.pptx
 
LIGHTNING_FLASH_Real_Time_Forecast_03032023_00UTC.pptx
LIGHTNING_FLASH_Real_Time_Forecast_03032023_00UTC.pptxLIGHTNING_FLASH_Real_Time_Forecast_03032023_00UTC.pptx
LIGHTNING_FLASH_Real_Time_Forecast_03032023_00UTC.pptx
 
Cyclone Predication using Machine Learing
Cyclone Predication using Machine LearingCyclone Predication using Machine Learing
Cyclone Predication using Machine Learing
 
figure.ppt
figure.pptfigure.ppt
figure.ppt
 
GB Dean(III) - 27.04.23 ppt.pptx
GB Dean(III)  - 27.04.23 ppt.pptxGB Dean(III)  - 27.04.23 ppt.pptx
GB Dean(III) - 27.04.23 ppt.pptx
 
DDI0029G_7TDMI_R3_trm.pdf
DDI0029G_7TDMI_R3_trm.pdfDDI0029G_7TDMI_R3_trm.pdf
DDI0029G_7TDMI_R3_trm.pdf
 
registration-customers.pdf
registration-customers.pdfregistration-customers.pdf
registration-customers.pdf
 
8253
82538253
8253
 

Recently uploaded

BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdfBPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
MIGUELANGEL966976
 
Embedded machine learning-based road conditions and driving behavior monitoring
Embedded machine learning-based road conditions and driving behavior monitoringEmbedded machine learning-based road conditions and driving behavior monitoring
Embedded machine learning-based road conditions and driving behavior monitoring
IJECEIAES
 
A SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMS
A SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMSA SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMS
A SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMS
IJNSA Journal
 
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student MemberIEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
VICTOR MAESTRE RAMIREZ
 
132/33KV substation case study Presentation
132/33KV substation case study Presentation132/33KV substation case study Presentation
132/33KV substation case study Presentation
kandramariana6
 
Recycled Concrete Aggregate in Construction Part II
Recycled Concrete Aggregate in Construction Part IIRecycled Concrete Aggregate in Construction Part II
Recycled Concrete Aggregate in Construction Part II
Aditya Rajan Patra
 
Textile Chemical Processing and Dyeing.pdf
Textile Chemical Processing and Dyeing.pdfTextile Chemical Processing and Dyeing.pdf
Textile Chemical Processing and Dyeing.pdf
NazakatAliKhoso2
 
Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024
Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024
Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024
Sinan KOZAK
 
22CYT12-Unit-V-E Waste and its Management.ppt
22CYT12-Unit-V-E Waste and its Management.ppt22CYT12-Unit-V-E Waste and its Management.ppt
22CYT12-Unit-V-E Waste and its Management.ppt
KrishnaveniKrishnara1
 
Iron and Steel Technology Roadmap - Towards more sustainable steelmaking.pdf
Iron and Steel Technology Roadmap - Towards more sustainable steelmaking.pdfIron and Steel Technology Roadmap - Towards more sustainable steelmaking.pdf
Iron and Steel Technology Roadmap - Towards more sustainable steelmaking.pdf
RadiNasr
 
spirit beverages ppt without graphics.pptx
spirit beverages ppt without graphics.pptxspirit beverages ppt without graphics.pptx
spirit beverages ppt without graphics.pptx
Madan Karki
 
ACEP Magazine edition 4th launched on 05.06.2024
ACEP Magazine edition 4th launched on 05.06.2024ACEP Magazine edition 4th launched on 05.06.2024
ACEP Magazine edition 4th launched on 05.06.2024
Rahul
 
Engine Lubrication performance System.pdf
Engine Lubrication performance System.pdfEngine Lubrication performance System.pdf
Engine Lubrication performance System.pdf
mamamaam477
 
ML Based Model for NIDS MSc Updated Presentation.v2.pptx
ML Based Model for NIDS MSc Updated Presentation.v2.pptxML Based Model for NIDS MSc Updated Presentation.v2.pptx
ML Based Model for NIDS MSc Updated Presentation.v2.pptx
JamalHussainArman
 
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECTCHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
jpsjournal1
 
International Conference on NLP, Artificial Intelligence, Machine Learning an...
International Conference on NLP, Artificial Intelligence, Machine Learning an...International Conference on NLP, Artificial Intelligence, Machine Learning an...
International Conference on NLP, Artificial Intelligence, Machine Learning an...
gerogepatton
 
Modelagem de um CSTR com reação endotermica.pdf
Modelagem de um CSTR com reação endotermica.pdfModelagem de um CSTR com reação endotermica.pdf
Modelagem de um CSTR com reação endotermica.pdf
camseq
 
Manufacturing Process of molasses based distillery ppt.pptx
Manufacturing Process of molasses based distillery ppt.pptxManufacturing Process of molasses based distillery ppt.pptx
Manufacturing Process of molasses based distillery ppt.pptx
Madan Karki
 
New techniques for characterising damage in rock slopes.pdf
New techniques for characterising damage in rock slopes.pdfNew techniques for characterising damage in rock slopes.pdf
New techniques for characterising damage in rock slopes.pdf
wisnuprabawa3
 
Eric Nizeyimana's document 2006 from gicumbi to ttc nyamata handball play
Eric Nizeyimana's document 2006 from gicumbi to ttc nyamata handball playEric Nizeyimana's document 2006 from gicumbi to ttc nyamata handball play
Eric Nizeyimana's document 2006 from gicumbi to ttc nyamata handball play
enizeyimana36
 

Recently uploaded (20)

BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdfBPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
 
Embedded machine learning-based road conditions and driving behavior monitoring
Embedded machine learning-based road conditions and driving behavior monitoringEmbedded machine learning-based road conditions and driving behavior monitoring
Embedded machine learning-based road conditions and driving behavior monitoring
 
A SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMS
A SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMSA SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMS
A SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMS
 
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student MemberIEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
 
132/33KV substation case study Presentation
132/33KV substation case study Presentation132/33KV substation case study Presentation
132/33KV substation case study Presentation
 
Recycled Concrete Aggregate in Construction Part II
Recycled Concrete Aggregate in Construction Part IIRecycled Concrete Aggregate in Construction Part II
Recycled Concrete Aggregate in Construction Part II
 
Textile Chemical Processing and Dyeing.pdf
Textile Chemical Processing and Dyeing.pdfTextile Chemical Processing and Dyeing.pdf
Textile Chemical Processing and Dyeing.pdf
 
Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024
Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024
Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024
 
22CYT12-Unit-V-E Waste and its Management.ppt
22CYT12-Unit-V-E Waste and its Management.ppt22CYT12-Unit-V-E Waste and its Management.ppt
22CYT12-Unit-V-E Waste and its Management.ppt
 
Iron and Steel Technology Roadmap - Towards more sustainable steelmaking.pdf
Iron and Steel Technology Roadmap - Towards more sustainable steelmaking.pdfIron and Steel Technology Roadmap - Towards more sustainable steelmaking.pdf
Iron and Steel Technology Roadmap - Towards more sustainable steelmaking.pdf
 
spirit beverages ppt without graphics.pptx
spirit beverages ppt without graphics.pptxspirit beverages ppt without graphics.pptx
spirit beverages ppt without graphics.pptx
 
ACEP Magazine edition 4th launched on 05.06.2024
ACEP Magazine edition 4th launched on 05.06.2024ACEP Magazine edition 4th launched on 05.06.2024
ACEP Magazine edition 4th launched on 05.06.2024
 
Engine Lubrication performance System.pdf
Engine Lubrication performance System.pdfEngine Lubrication performance System.pdf
Engine Lubrication performance System.pdf
 
ML Based Model for NIDS MSc Updated Presentation.v2.pptx
ML Based Model for NIDS MSc Updated Presentation.v2.pptxML Based Model for NIDS MSc Updated Presentation.v2.pptx
ML Based Model for NIDS MSc Updated Presentation.v2.pptx
 
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECTCHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
 
International Conference on NLP, Artificial Intelligence, Machine Learning an...
International Conference on NLP, Artificial Intelligence, Machine Learning an...International Conference on NLP, Artificial Intelligence, Machine Learning an...
International Conference on NLP, Artificial Intelligence, Machine Learning an...
 
Modelagem de um CSTR com reação endotermica.pdf
Modelagem de um CSTR com reação endotermica.pdfModelagem de um CSTR com reação endotermica.pdf
Modelagem de um CSTR com reação endotermica.pdf
 
Manufacturing Process of molasses based distillery ppt.pptx
Manufacturing Process of molasses based distillery ppt.pptxManufacturing Process of molasses based distillery ppt.pptx
Manufacturing Process of molasses based distillery ppt.pptx
 
New techniques for characterising damage in rock slopes.pdf
New techniques for characterising damage in rock slopes.pdfNew techniques for characterising damage in rock slopes.pdf
New techniques for characterising damage in rock slopes.pdf
 
Eric Nizeyimana's document 2006 from gicumbi to ttc nyamata handball play
Eric Nizeyimana's document 2006 from gicumbi to ttc nyamata handball playEric Nizeyimana's document 2006 from gicumbi to ttc nyamata handball play
Eric Nizeyimana's document 2006 from gicumbi to ttc nyamata handball play
 

MICROPROCESSORS AND ITS APPLICATIONS UNIT-I.ppt

  • 1. MC932-MICROPROCESSORS AND ITS APPLICATIONS Course teach by P.Karthikeyan.,MTech Asst Professor-3 VCET,Madurai 1 Dept of ECE,VCET Madurai
  • 2. Objective of the course • Understand the Microprocessor architecture and assembly language programming flow for the development and debugging in embedded applications like mobile, set top box and navigation in high level languages. • Understand the basics for the hardware protocols like UART,PCI and USB for the application development in embedded systems. 2 Dept of ECE,VCET Madurai
  • 3. UNIT-I THE 8086 PROCESSOR - SOFTWARE ASPECTS 3 Dept of ECE,VCET Madurai
  • 5. 8086 MP Overview • Intel 8086 Microprocessors are the basis of all IBM-PC compatible computers (8086 introduced in 1978, first IBM-PC released in 1981) • All Intel, AMD and other advanced microprocessors are based on and are compatible with the original 8086. • At Power Up and Reset time, Pentiums, Athlons etc all look like 8086 processors. 5 Dept of ECE,VCET Madurai
  • 6. 8086 Architecture Overview • Intel 8086 is a 16b microprocessor: – 16b data registers, 16b ALU • Width of external data bus: – 8086: 16b • Width of external address bus: 16b+4b=20b • Segment: Offset memory model • Little-Endian Data Format • The 8086 used an instruction queue to speed up performance • While the processor is decoding and executing an instruction, its bus interface can be reading new instructions, since at that time the bus is not actually in use 6 Dept of ECE,VCET Madurai
  • 7. 8086 Architecture 7 Dept of ECE,VCET Madurai
  • 8. Basic Internal Architecture Of 8086 • The 8086 make use of this idle time by pre-fetching the next instruction while the current instruction is being executed. • Here the bus is always busy. • The 8086 contains two internal units; the execution unit (EU) and the bus interface unit (BIU). • The BIU is responsible for fetching an instruction or the operand of an instruction from the memory. • The EU is responsible for executing the instructions. • The 8086 both are able to utilize the bus with maximum efficiency because both contain internal memory in the form of a queue. • The 8086 queue is 2 bytes wide and three locations deep. It is therefore able to hold three 16-bit numbers. 8 Dept of ECE,VCET Madurai
  • 9. Bus Interface Unit (BIU) • The BIU contains a prefetch queue, a bus controller, segment registers and the instruction pointer. • The main purposes of the BIU are: 1. To keep the prefetch queue filled with instructions. 2. To generate and accept the control signals. 3. To provide the system with a memory address or I/O port number. 4. To act as a window between the EU and memory for data. 9 Dept of ECE,VCET Madurai
  • 10. Bus Interface Unit (BIU) • Instruction Queue: the next instructions or data can be fetched from memory while the processor is executing the current instruction – The memory interface is slower than the processor execution time so this speeds up overall performance • Segment Registers: – CS, DS, SS and ES are 16b registers – Used with the 16b Base registers to generate the 20b address – Allow the 8086 to address 1MB of memory • Instruction Pointer (IP) contains the Offset Address of the next instruction, the distance in bytes from the address given by the current CS register 10 Dept of ECE,VCET Madurai
  • 11. Execution Unit (EU) • The purpose of the EU is to carry out instructions that are fetched from the prefetch queue. • It contains; an Arithmetic and Logic Unit(ALU), an instruction register, and a register array. • The ALU performs arithmetic and logic operations on memory and or register data. • The instruction register receives the instructions from the prefetch queue. From here these instructions are decoded to direct the operation of the execution unit. • The register array holds information temporarily. It also contains pointers or index registers used to address operand data located in the memory. 11 Dept of ECE,VCET Madurai
  • 12. System Architecture • Three types of buses are  Address Bus  Data Bus  Control Bus • The address bus provides the memory address to the system memory and also I/O addresses to the I/O devices. The 8086 has a 20-bit address bus. • The data bus transfers data between the microprocessor and the memory and I/O attached to the system. The 8086 has a16-bit data bus. • The control bus provides control signals that cause the memory or I/O to perform a READ or WRITE operation. It consists of three signals RD, WR and IO/M. • The 8086 having address of 1M bytes of memory because they both contain a 20-bit address bus. 12 Dept of ECE,VCET Madurai
  • 13. 8086/8088 Register File CS DS SS ES AH BH CH DH AL BL CL DL IP SP BP SI DI 0 7 0 15 0 7 0 15 Accumulator Base Counter Data Code Segment Data Segment Stack Segment Extra Segment Instruction Pointer Stack Pointer Base Pointer Source Index Destination Index } } } AX BX CX DX 13 Dept of ECE,VCET Madurai
  • 14. 8086/8088 Register File (cont) Flags Register x x x x OF DF IF TF SF ZF x AF x PF x CF 0 15 Status and Control Bits Maintained in Flags Register – Generally Set and Tested Individually – Nine 1-bit flags in 8086; Seven are unused 14 Dept of ECE,VCET Madurai
  • 15. Flags Register • Carry Flag (CF) - this flag is set to 1 when there is an unsigned overflow. When there is no overflow this flag is set to 0. • Parity Flag (PF) - this flag is set to 1 when there is even number of one bits in result, and 0 when there is odd number of one bits. • Auxiliary Flag (AF) - set to 1 when there is an unsigned overflow for low nibble (4 bits). • Zero Flag (ZF) - set to 1 when result is zero. For non-zero result this flag is set to 0. • Sign Flag (SF) - set to 1 when result is negative. When result is positive it is set to 0. (This flag takes the value of the most significant bit.) • Trap Flag (TF) - Used for on-chip debugging. • Interrupt enable Flag (IF) - when this flag is set to 1 CPU reacts to interrupts from external devices. • Direction Flag (DF) - this flag is used by some instructions to process data chains, when this flag is set to 0 - the processing is done forward, when this flag is set to 1 the processing is done backward. • Overflow Flag (OF) - set to 1 when there is a signed overflow. 15 Dept of ECE,VCET Madurai
  • 16. Status Flags CF Carry Flag Arithmetic Carry/Borrow OF Overflow Flag Arithmetic Overflow ZF Zero Flag Zero Result; Equal Compare SF Sign Flag Negative Result; Non-Equal Compare PF Parity Flag Even Number of “1” bits AF Auxiliary Carry Used with BCD Arithmetic Indicate Current Processor Status 16 Dept of ECE,VCET Madurai
  • 17. Control Flags DF Direction Flag Auto-Increment/Decrement – used for “string operations” IF Interrupt Flag Enables Interrupts – allows “fetch-execute” to be interrupted TF Trap Flag Allows Single-Step – for debugging; causes interrupt after each op Influence the 8086 During Execution Phase 17 Dept of ECE,VCET Madurai
  • 18. 8086/8088 Register File (cont) 0 15 IP Contains Address of NEXT Instruction to be Fetched – Automatically Incremented – Programmer can control with jump and branch Instruction Pointer Register 18 Dept of ECE,VCET Madurai
  • 19. AX, BX, CX, DX • Can Be Used Separately as 1-byte Registers AX = AH:AL • Temporary Storage to Avoid Memory Access – Faster Execution – Avoids Memory Access • Some Special uses for Certain Instructions AH BH CH DH AL BL CL DL 0 7 0 7 Accumulator Base Counter Data General Purpose Registers AX BX CX DX 19 Dept of ECE,VCET Madurai
  • 20. AX, BX, CX, DX - Some Specialized Uses AX, Accumulator Main Register for Performing Arithmetic mult/div must use AH, AL “accumulator” Means Register with Simple ALU BX, Base Point to Translation Table in Memory Holds Memory Offsets; Function Calls CX, Counter Index Counter for Loop Control DX, Data After Integer Division Execution - Holds Remainder AH BH CH DH AL BL CL DL 0 7 0 7 Accumulator Base Counter Data AX BX CX DX 20 Dept of ECE,VCET Madurai
  • 21. CS, DS, ES, SS - Segment Registers CS, Code Segment Used to “point” to Instructions Determines a Memory Address (along with IP) Segmented Address written as CS:IP DS, Data Segment Used to “point” to Data Determines Memory Address (along with other registers) ES, Extra Segment allows to Data Address Registers SS, Stack Segment Used to “point” to Data in Stack Structure (LIFO) Used with SP or BP SS:SP or SS:BP are valid Segmented Addresses Contains “Base Value” for Memory Address 21 Dept of ECE,VCET Madurai
  • 22. IP, SP, BP, SI, DI - Offset Registers IP, Instruction Pointer Used to “point” to Instructions Determines a Memory Address (along with CS) Segmented Address written as CS:IP SI, Source Index; DI, Destination Index Used to “point” to Data Determines Memory Address (along with other registers) DS, ES commonly used SP, Stack Pointer;BP, Base Pointer Used to “point” to Data in Stack Structure (LIFO) Used with SS SS:SP or SS:BP are valid Segmented Addresses These can also be used as General Registers !!!!!! Contains “Index Value” for Memory Address 22 Dept of ECE,VCET Madurai
  • 23. Memory Segmentation • x86 Memory Partitioned into Segments  8086: maximum size is 64K (16-bit index reg.)  8086: can have 4 active segments (CS, SS, DS, ES)  8086: 2-data; 1-code; 1-stack • Why have segmented memory ? – Other microprocessors could only address 64K since they only had a single 16-bit MAR (or smaller). Segments allowed computers to be built that could use more than 64K memory (but not all at the same time). 23 Dept of ECE,VCET Madurai
  • 24. ADD Memory System Address Lines 0000 Index Reg. Segment Reg. Physical Address 0 0 0 15 15 19 Portion of BIU Circuitry CS ES SS DS IP Dedicated Segment Registers Dedicated Index Registers BP DI SI SP 8086 Generating Physical Addresses 24 Dept of ECE,VCET Madurai
  • 25. 8086 20-bit Addresses 16-bit Segnment Base Address 0000 16-bit Offset Address 20-bit Physical Address CS IP 25 Dept of ECE,VCET Madurai
  • 26. Segmented Addressing CS ES SS DS IP BP DI SI SP • Each Segment must begin at Paragraph Boundary 00000h 00010h 00020h physical address memory paragraph 1 paragraph 2 paragraph 3 • Each paragraph has phys. address that is multiple of 10h • BIU is responsible for appending 0000 to Segment – only need 16-bit segment registers 26 Dept of ECE,VCET Madurai
  • 27. Segmented Memory (x86 Style) CS ES SS DS Data Segment Stack Segment Extra Segment Code Segment Segment Registers System Memory • Segment Registers: – Point to Base Address • Index Registers: – Contain Offset Value • Notation (Segmented Address): – CS:IP – DS:SI – ES:DI – SS:BP – SS:SP 00000h FFFFFh fragmentation 27 Dept of ECE,VCET Madurai
  • 28. Segmented Memory Example CS ES SS DS Data Segment Stack Segment Extra Segment Code Segment Segment Registers System Memory • Logical, Segmented Address: 0FE6:012Bh • Offset, Index Address: 012Bh • Physical Address: 0FE60h  65120 + 012Bh  299 0FF8Bh  65149 00000h FFFFFh 28 Dept of ECE,VCET Madurai
  • 29. Segment Locations in Physical Memory segment a segment b segment c segment d segment e 0h 10000h 20000h 30000h continuous partially overlapped fully overlapped Logical Segments Physical Memory Note that segments can overlap. This means that two different logical addresses can refer to the same physical address (aliasing). 29 Dept of ECE,VCET Madurai
  • 30. The offset is the distance in bytes from the start of the segment. The offset is given by the IP for the Code Segment. Instructions are always fetched with using the CS register. The physical address is also called the absolute address 000000H Memory Segment Register Offset Physical or Absolute Address 0 + CS: IP 0400H 0056H 4000H 4056H 0400 0056 04056H CS:IP = 400:56 Logical Address 0FFFFFH Left-shift 4 bits The Code Segment 30 Dept of ECE,VCET Madurai
  • 31. The Data Segment Data is usually fetched with respect to the DS register. The effective address (EA) is the offset. The EA depends on the addressing mode. Memory Segment Register Offset Physical Address + DS: EA 05C0 0050 05C00H 05C50H 05C0 0 0050 05C50H DS:EA 000000 H 0FFFFFH 31 Dept of ECE,VCET Madurai
  • 32. Addressing Modes DATA1 DW 25H DATA1 is defined as a word (16-bit) variable, i.e., a memory location that contains 25H. DATA2 EQU 20H DATA2 is not a memory location but a constant. Direct Addressing MOV AX,DATA1 [DATA1]  AX, the contents of DATA1 is put into AX. The CPU goes to memory to get data. 25H is put in AX. Immediate Addressing MOV AX,DATA2 DATA2 = 20H  AX, 20H is put in AX. Does not go to memory to get data. Data is in the instruction. MOV AX, OFFSET DATA1 The assembler knows which mode to encode by the way the operands SAM and FRED are defined. Assembler directive, DW = Define Word 32 Dept of ECE,VCET Madurai
  • 33. Addressing Modes Register Addressing MOV AX,BX AX BX Register Indirect Addressing MOV AX,[BX] AX DS:BX Can use BX or BP -- Based Addressing (BP defaults to SS) or DI or SI -- Indexed Addressing The offset or effective address (EA) is in the base or index register. Register Indirect with Displacement MOV AX,SAM[BX] AX DS:BX + Offset SAM Indexed with displacement Based with displacement Based-Indexed Addressing MOV AX,[BX][SI] EA = BX + SI Based-Indexed w/Displacement MOV AX,SAM[BX][DI] EA = BX + DI + offset SAM AX DS:EA where EA = BX + offset SAM 33 Dept of ECE,VCET Madurai
  • 34. Addressing Modes Branch Related Instructions Intrasegment (CS does not change) Direct -- IP relative displacement new IP = old IP + displacement Allows program relocation with no change in code. Indirect -- new IP is in memory or a register. All addressing modes apply. Intersegment Direct -- new CS and IP are encoded in (CS changes) the instruction. Indirect -- new CS and IP are in memory. All addressing modes apply except immediate and register. NEAR JUMPS and CALLS FAR 34 Dept of ECE,VCET Madurai
  • 35. Assembly Language The Assembler is a program that reads the source program as data and translates the instructions into binary machine code. The assembler outputs a listing of the addresses and machine code along with the source code and a binary file (object file) with the machine code. Most assemblers scan the source code twice -- called a two-pass assembler. • The first pass determines the locations of the labels or identifiers. • The second pass generates the code. 35 Dept of ECE,VCET Madurai
  • 36. Assembly Language To locate the labels, the assembler has a location counter. This counts the number of bytes required by each instruction. • When the program starts a segment, the location counter is zero. • If a previous segment is re-entered, the counter resumes the count. • The location counter can be set to any offset by the ORG directive. In the first pass, the assembler uses the location counter to construct a symbol table which contains the offsets or values of the various labels. The offsets are used in the second pass to generate operand addresses. 36 Dept of ECE,VCET Madurai
  • 37. INSTRUCTION SET OF 8086 8086 instructions are categorized as 1)Data Copy/Transfer Instructions 2)Arithmetic and Logical Instructions 3)Branch Instructions 4)Loop Instructions 5)Machine Control Instructions 6)Flag Manipulation Instructions 7)Shift and Rotate Instructions 8)String Instructions 37 Dept of ECE,VCET Madurai
  • 41. PUSH,POP,IN,OUT,XLAT,LAHF,SAHF • PUSH -Push to Stack(Push operation decrements SP by two and then stores the two byte contents of the operand on to the stack) • POP -Pop from Stack(The stack pointer incremented by two. Popping register contents from stack memory) • PUSHF -Push Flags • POPF -Pop Flags • IN -Input from Fixed Port/Variable port • OUT -Output to Fixed Port/Variable port • XLAT -Translate Byte to AL • LAHF -Load AH with Flags • SAHF -Store AH with Flags 41 Dept of ECE,VCET Madurai
  • 49. Compare • Compares the source operand(reg,imme data,mem loc) with a destination operand(reg or mem loc). • Comparison, it subtracts the source operand from the destination operand. • Both operands are equal zero flag is set. If the source operand is greater than the destination operand, carry flag is set or else carry flag is reset. Examble CMP BX,0100H Immediate CMP [5000H],0100H Direct CMP BX,[SI] Register indirect CMP BX,CX Register 49 Dept of ECE,VCET Madurai
  • 60. STRING MANIPULATION INSTRUCTIONS • REP Repeat Instruction Prefix • MOVSB/MOVSW Move String Byte or String Word • CMPS Compare String Byte or String Word • SCAS Scan String Byte or String Word • LODS Load String Byte or String Word • STOS Store String Byte or String Word 60 Dept of ECE,VCET Madurai
  • 61. Unconditional Branch Instructions • CALL Unconditional Call • RET Return from the Procedure • INT N Interrupt Type N • INTO Interrupt on Overflow • JMP Unconditional Jump • IRET Return from ISR • LOOP Loop Unconditionally 61 Dept of ECE,VCET Madurai
  • 62. Conditional Jumps Name/Alt Meaning Flag setting JE/JZ Jump equal/zero ZF = 1 JNE/JNZ Jump not equal/zero ZF = 0 JL/JNGE Jump less than/not greater than or = (SF xor OF) = 1 JNL/JGE Jump not less than/greater than or = (SF xor OF) = 0 JG/JNLE Jump greater than/not less than or = ((SF xor OF) or ZF) = 0 JNG/JLE Jump not greater than/ less than or = ((SF xor OF) or ZF) = 1 JB/JNAE Jump below/not above or equal CF = 1 JNB/JAE Jump not below/above or equal CF = 0 JA/JNBE Jump above/not below or equal (CF or ZF) = 0 JNA/JBE Jump not above/ below or equal (CF or ZF) = 1 JS Jump on sign (jump negative) SF = 1 JNS Jump on not sign (jump positive) SF = 0 JO Jump on overflow OF = 1 JNO Jump on no overflow OF = 0 JP/JPE Jump parity/parity even PF = 1 JNP/JPO Jump no parity/parity odd PF = 0 JCXZ Jump on CX = 0 --- 62 Dept of ECE,VCET Madurai
  • 63. Flag Manipulation CLC - Clear carry flag CMC - Complement carry flag STC - Set carry flag CLD - Clear direction flag STD - Set direction flag CLI - Clear interrupt flag STI - Set interrupt flag Processor Control Instructions WAIT - Wait for Test input pin to go low HLT - Halt the Processor NOP - No operation ESC - Escape to external device like NDP(numeric co-processor) LOCK - Bus lock instruction prefix 63 Dept of ECE,VCET Madurai
  • 64. Assembler Directives ASSUME Tells the assembler what segments to use. SEGMENT Defines the segment name and specifies that the code that follows is in that segment ORG Originate or Origin: sets the location counter END End of source code ENDS End of segment ENDP End of Procedure NAME Give source module a name OFFSET Offset of a label DW Define word DB Define byte DQ Define Quad word DT Define Ten Bytes 64 Dept of ECE,VCET Madurai
  • 65. Assembler Directives EQU Equate or equivalence EVEN Align or Even memory address EXTRN External PUBLIC Public GROUP Group the related segments LABEL Assign current location count to a symbol LENGTH Byte Length of a Label LOCAL Lables,variables,constants or procedures declared LOCAL in module $ Current location count PROC Procedure PTR Pointer(FAR PTR,NEAR PTR) SEG Segment of a Label SHORT,TYPE,GLOBAL, “+&-”Operators 65 Dept of ECE,VCET Madurai
  • 66. 66 Interrupts • Interrupt Types – Hardware Interrupts: External event – Software Interrupts: Internal event (Software generated) – Maskable and non-maskable interrupts – Interrupt priority • Interrupt Vectors and Interrupt Handlers • Interrupt Controllers Dept of ECE,VCET Madurai
  • 67. 67 The Purpose of Interrupts • Interrupts are useful when interfacing I/O devices with low data- transfer rates, like a keyboard or a mouse, in which case polling the device wastes valuable processing time • The peripheral interrupts the normal application execution, requesting to send or receive data. • The processor jumps to a special program called Interrupt Service Routine to service the peripheral • After the processor services the peripheral, the execution of the interrupted program continues. Printer Interrupt Modem Interrupt Modem Interrupt Main Program Main Program Main Program Main Program Dept of ECE,VCET Madurai
  • 68. BASIC INTERRUPT TERMINOLOGY • Interrupt pins: Set of pins used in hardware interrupts • Interrupt Service Routine (ISR) or Interrupt handler: code used for handling a specific interrupt • Interrupt priority: In systems with more than one interrupt inputs, some interrupts have a higher priority than other – They are serviced first if multiple interrupts are triggered simultaneously • Interrupt vector: Code loaded on the bus by the interrupting device that contains the Address (segment and offset) of specific interrupt service routine • Interrupt Masking: Ignoring (disabling) an interrupt • Non-Maskable Interrupt: Interrupt that cannot be ignored (power-down) Dept of ECE,VCET Madurai
  • 69. Hardware Interrupts – Interrupt pins and timing • x86 Interrupt Pins – INTR: Interrupt Request. Activated by a peripheral device to interrupt the processor. • Level triggered. Activated with a logic 1. – /INTA: Interrupt Acknowledge. Activated by the processor to inform the interrupting device the the interrupt request (INTR) is accepted. • Level triggered. Activated with a logic 0. – NMI: Non-Maskable Interrupt. Used for major system faults such as parity errors and power failures. • Edge triggered. Activated with a positive edge (0 to 1) transition. • Must remain at logic 1, until it is accepted by the processor. • Before the 0 to 1 transition, NMI must be at logic 0 for at least 2 clock cycles. • No need for interrupt acknowledgement. Vector INTR INTA΄ D7-D0 Dept of ECE,VCET Madurai
  • 70. Software Interrupts • Traps: (self-interrupt!) – Single step mode – Calls to Operating System (INT 21H - x86, SC – PPC) • Exceptions: – Divide by zero – Memory protection fault Dept of ECE,VCET Madurai
  • 71. Identifying Interrupt Source • Software Polling, – Checking each device • Hardware Polling, (Daisy Chain), • Hardware Identification (Vectored Interrupts). Dept of ECE,VCET Madurai
  • 72. Interrupt Processing • Save state – Disable interrupts for the duration of the ISR or allow it to be interrupted too? – Save program counter – Save flags – Save register values? • Jump to interrupt service routine – Location obtained by interrupt vector • Process interrupt • Restore state – Load PC, flags, registers etc. Dept of ECE,VCET Madurai
  • 73. Interrupt Processing on the 8086 Microprocessor • External interface sends an interrupt signal, to the Interrupt Request (INTR) pin, (or an internal interrupt occurs.) • The CPU finishes the present instruction (for a hardware interrupt) and checks the INTR pin. • If IF=0 the processor ignores the interrupt, else sends Interrupt Acknowledge (INTA) to hardware interface. • The interrupt type N is sent to the Central Processor Unit (CPU) via the Data bus from the hardware interface. • The contents of the flag registers are pushed onto the stack. Dept of ECE,VCET Madurai
  • 74. • Both the interrupt (IF – FR bit 9) and (TF – FR bit 8) flags are cleared. This disables the INTR pin and the trap or single-step feature. • The contents of the code segment register (CS) are pushed onto the Stack. • The contents of the instruction pointer (IP) are pushed onto the Stack. • The interrupt vector contents are fetched, from (4 x N) and then placed into the IP and from (4 x N +2) into the CS so that the next instruction executes at the interrupt service procedure addressed by the interrupt vector. • While returning from the interrupt-service routine by the Interrupt Return (IRET) instruction, the IP, CS and Flag registers are popped from the Stack and return to their state prior to the interrupt. Interrupt Processing on the 8086 Microprocessor 74 Dept of ECE,VCET Madurai
  • 75. Interrupt Vectors • The processor uses the interrupt vector to determine the address of the ISR of the interrupting device. • In the 8088/8086 processor as well as in the 80386/80486/Pentium processors operating in Real Mode (16-bit operation), the interrupt vector is a pointer to the Interrupt Vector Table. – The Interrupt Vector Table occupies the address range from 00000H to 003FFH (the first 1024 bytes in the memory map). – Each entry in the Interrupt Vector Table is 4 bytes long: • The first two represent the offset address and the last two the segment address of the ISR. – The first 5 vectors are reserved by Intel to be used by the processor. • The vectors 5 to 255 are free to be used by the user. Dept of ECE,VCET Madurai
  • 76. Dept of ECE,VCET Madurai 76 Interrupt Vector Table Type 0 POINTER (DIVIDE ERROR) Type 1 POINTER (SINGLE STEP) Type 2 POINTER (NON-MASKABLE) Type 3 POINTER (BREAK POINT) Type 4 POINTER (OVERFLOW) 010H 00CH 008H 004H 000H 16 bits CS base address IP offset
  • 77. Dept of ECE,VCET Madurai 77 03FFH Type 5 Reserved Type 31 (Reserved) Type 32 (Available) 03FCH 080H 07FH 0014H Reserved Interrupts (27) Type 255 (Available) Available Interrupts (224)
  • 78. Setting up an Interrupt-Pointer Table • The first 1 KB of memory is set aside as a table for storing the starting addresses of ISRs – these are addresses 00000H to 003FFH – you need 4 bytes to store the CS and IP values for each ISR – thus the table can hold the addresses for 256 ISRs • Terms – Interrupt vector/pointer - the starting address of an ISR – Interrupt vector/pointer table - the table containing the starting addresses of the ISRs 78 Dept of ECE,VCET Madurai
  • 79. Dept of ECE,VCET Madurai 79 Interrupt Vector Table INT Number Physical Address INT 00 00000 INT 01 00004 INT 02 00008 : : : : INT FF 003FC
  • 80. Dept of ECE,VCET Madurai 80 Dedicated Interrupts • Type 0 to Type 4 interrupts are dedicated to specific interrupts • Type 5 to Type 31 interrupts are reserved by Intel for more complex microprocessors • Type 32 to Type 255 interrupts can be user specified for dealing with hardware or software interrupts
  • 81. Dept of ECE,VCET Madurai 81 Type 0 Interrupt Example • Type 0 specifies a divide by zero interrupt – Recall DIV instruction • whenever a quotient from DIV or IDIV operation is too large to fit in the result register, a type 0 interrupt happens automatically • It’s up to the programmer to handle this interrupt – one possible is to set a programmer-defined error flag…BAD_DIV_FLAG
  • 82. Dept of ECE,VCET Madurai 82 Initialization List • Initialize the interrupt-vector table – use the ES register – the starting address of our type 0 ISR needs to be in locations 00000H and 00002H • Set up the data segment – include a declaration for the BAD_DIV_FLAG – Initialize DS • Set up a stack – Initialize SS and SP
  • 83. Dept of ECE,VCET Madurai 83 Single-Step Interrupt - Type 1 • If the TF (trap flag) is set, a type 1 interrupt will automatically occur • To implement single-stepping, such as in a debugger: – set the trap flag – write an ISR that saves all registers on the stack, so they can be examined – load the address of the ISR into the addresses 00004H and 00006H
  • 84. Dept of ECE,VCET Madurai 84 Nonmaskable Interrupt - Type 2 • Type 2 interrupt automatically occurs when the CPU receives a low-to-high transition on its NMI pin • this type of interrupt cannot be masked by any program instructions • normally used to signal that some external system/device must be taken care of – pressure sensor on a large steam boiler – save data in case of a power failure
  • 85. Dept of ECE,VCET Madurai 85 Breakpoint Interrupt -Type 3 • This type of interrupt is produced by executing an INT 3 instruction – no automatic triggers • Useful for debugging – many debuggers implement breakpoints by inserting an INT 3 instruction before the specified instruction – the Type 3 ISR may then store all the registers so that they can be examined by the user
  • 86. Dept of ECE,VCET Madurai 86 Overflow Interrupt - Type 4 • This type of interrupt may be produced if the OF (Overflow flag) is set… but not automatically triggered • OF will be set if the signed result of an arithmetic operation on 2 signed numbers is too large to be represented in the destination – 01101100 (108 decimal) + 01010001 (81 decimal), remember that these are signed!
  • 87. Dept of ECE,VCET Madurai 87 Overflow Interrupt (cont.) • Can handle OF error using a JO instruction following arithmetic operation • Can also use the INTO instruction – this specifies to Interrupt on Overflow – if OF is set (1), will execute ISR contained in the type 4 addresses in the vector table • INTO is advantageous because you can use the same ISR for many programs
  • 88. Dept of ECE,VCET Madurai 88 Software Interrupts • How do I test out my ISR that handles a type 2 interrupt without directly signaling the NMI pin? – Use a software interrupt INT 2 ; test out NMI ISR • You can specify values 0 - 255 (decimal) as operands to the INT instruction
  • 89. Dept of ECE,VCET Madurai 89 INTR Interrupts • These are hardware interrupts • can be disabled by clearing IF CLI ; disable interrupts • can be enabled by setting IF STI ; enable interrupts • The interrupt type is sent to the 8086 from an external hardware device – could be an 8259A priority interrupt controller • Remember, IF is automatically cleared in response to any type of 8086 interrupt
  • 90. Dept of ECE,VCET Madurai 90 Why Disable INTR Interrupts? Reason #1 – To prevent an INTR interrupt from interrupting a higher priority interrupt – Interrupt priorities • Highest - Divide Error, INT n, INTO • Lower - NMI • Still Lower - INTR • Lowest - Single-Step Reason #2 -To prevent an interrupt from continuously interrupting itself The INTR input is active high…whenever INTR input is high and IF is set, the 8086 will be interrupted -After IRET, flag is popped INTR could still possibly be receiving the same high signal and cause another interrupt it is the responsibility of the external hardware sending the INTR signal to avoid this problem