Amp Module 2
Amp Module 2
Amp Module 2
Interrupt is the method of creating a temporary halt during program execution and allows
peripheral devices to access the microprocessor. The microprocessor responds to that interrupt with
an ISR (Interrupt Service Routine), which is a short program to instruct the microprocessor on how
to handle the interrupt.
SOURCES OF INTERRUPTS IN 8086
An interrupt in 8086 can come from one of the following three sources.
1. One source is from an external signal applied to NMI or INTR input pin of the processor. The
interrupts initiated by applying appropriate signals to these input pins are called hardware interrupts.
2. A second source of an interrupt is execution of the interrupt instruction "INT n", where n is the
type number. The interrupts initiated by "INT n" instructions are called software interrupts.
3. The third source of an interrupt is from some condition produced in the 8086 by the execution of
an instruction. An example of this type of interrupt is divide by zero interrupt. Program execution will
be automatically interrupted if you attempt to divide an operand by zero. Such conditional interrupts
are also known as exceptions
Types of interrupts
The following image shows the types of interrupts we have in a 8086 microprocessor −
Hardware Interrupts
Hardware interrupt is caused by any peripheral device by sending a signal through a specified pin to
the microprocessor.
The 8086 has two hardware interrupt pins, i.e. NMI and INTR. NMI is a non-maskable interrupt and
INTR is a maskable interrupt having lower priority. One more interrupt pin associated is INTA called
interrupt acknowledge.
NMI
It is a single non-maskable interrupt pin (NMI) having higher priority than the maskable interrupt
request pin (INTR)and it is of type 2 interrupt.
INTR
The INTR is a maskable interrupt because the microprocessor will be interrupted only if interrupts
are enabled using set interrupt flag instruction. It should not be enabled using clear interrupt Flag
instruction.
Software Interrupts
Interrupts are generated by a software instruction and operate similarly to a jump or branch
instruction. There are 256 type interrupts.
The type numbers are in the range of 0 to 255. The 8086 processor has dual facility of initiating
these 256 interrupts. The interrupts can be initiated either by executing "INT n" instruction where n
is the type number or the interrupt can be initiated by sending an appropriate signal to INTR input
pin of the processor
INT n is invoked as software interrupts- n is the type no in the range 0 to 255(00 to FF) Interrupts
are divided into three groups
1.Type 0 to Type4 (Dedicated Interrupts) –
TYPE 0 interrupt represents division by zero situation.
TYPE 1 interrupt represents single-step execution during the debugging of a program. - TYPE 2
interrupt represents non-maskable NMI interrupt.
TYPE 3 interrupt represents break-point interrupt.
TYPE 4 interrupt represents overflow interrupt.
2.Type 5 to 31(Not used by 8086, reserved for higher processor like 80286,80386….
3.Type 32-255(Available for user) - User defined interrupts
Predefined or dedicated interrupts
1.Devide by zero(type-0) Interrupt
Type-0 interrupt is implemented as a part of the execution of the divide instruction. The 8086 will
automatically do a type-0 interrupt if the result of a division operation is too large to fit in the
destination register and this interrupt is non maskable. Since the type-0 interrupt cannot be disabled
in any way, we have to account for it in the programs using divide instructions. To account for this,
we have to write an ISS which takes the desired action or indicate error condition when an invalid
division occurs. The ISS should be stored in memory and the address of ISS is stored in interrupt
vector table.
3. To store vector address in any interrupt ,it requires 4 byte memory location, ie first 2byte for
offset address and next 2 byte for base address.
4. For storing vector address of all 256 interrupts ,8086 microprocessor required total 1kb
memory locations(256x1024=1kb)
5. To find out vector address of any interrupts, multiply the interrupt type number by 4
Eg: for type 4, 4x4 =(16)10 (00016)16
.
Interrupt response in 8086
Main program Push flag
Clear IF
Clear TF
Push CS
Push IP
Fetch ISR
address
Pop IP
Pop CS
Pop Flag
Main program
Dept of ECE 4 MDIT polytechnic college
Advanced Microprocessor Module 2
Interrupt response means the processing step of microprocessor when an interrupt occurs
That are
1. The value of flag register is pushed into the stack. It means that the value of stack pointer is
decremented by 2 and the value of flag register is pushed to the memory address of stack segment
2. The interrupt system is disabled by clearing the interrupt flag
3. The single step trap flag is disabled by clearing the trap flag
4 Stack pointer is decremented by 2 and the content ocf code segment are pushed on to the stack.
5.Again SP is decremented by 2 and the content of IP are pushed on to the stack.
6. Fetch the ISR address and execute the ISR program to service the interrupt.
7. The ISR will be terminated by IRET instruction, then the stack top is popped to the IP,CS and flag
register respectively. After every POP operation, stack pointer is incremented by 2.
8. Then the status of the response is restored , microprocessor will resume the execution of main
program.
in this mode, 16 bit offset address is specifies in two parts. One part is specifies as the
content of BX or BP and the second part is displacement of memory location.
Eg: MOV AX, [BX+0056H]
6. Indexed addressing mode
In this mode, offset address of data is specifies by ther sum of content of SI or DI register
and displacement value.
7. Base indexed addressing mode
In this, the offset address of data is specifies by the sum of content of base register and
index register.
Eg: MOV AX,[BX+SI]
8. Base indexed with displacement addressing mode
The offset address of the data is specifies as sum of content of BX,SI or DI and
displacement values.
Eg: MOV AX, [BX+SI+0056H]
9. I/O port addressing mode
It is of two types
Fixed addressing mode
In this mode port address is specified with fixed port address. During the execution of
program port address cannot be changed.
Eg: IN AL,19 H
Arithmetic Instructions
These instructions are used to perform arithmetic operations like addition, subtraction,
multiplication, division, etc. That are,
Instructions to perform addition
ADD − Used to add the provided byte to byte/word to word.
ADC − Used to add with carry.
INC − Used to increment the provided byte/word by 1.
Dept of ECE 7 MDIT polytechnic college
Advanced Microprocessor Module 2
SHR − Used to shift bits of a byte/word towards the right and put zero(S) in MSBs.
SAR − Used to shift bits of a byte/word towards the right and copy the old MSB into the new
MSB.
Instructions to perform rotate operations
ROL − Used to rotate bits of byte/word towards the left, i.e. MSB to LSB and to Carry Flag
[CF].
ROR − Used to rotate bits of byte/word towards the right, i.e. LSB to MSB and to Carry Flag
[CF].
RCR − Used to rotate bits of byte/word towards the right, i.e. LSB to CF and CF to MSB.
RCL − Used to rotate bits of byte/word towards the left, i.e. MSB to CF and CF to LSB.
String Instructions
String is a group of bytes/words and their memory is always allocated in a sequential order.−
REP − Used to repeat the given instruction till CX ≠ 0.
REPE/REPZ − Used to repeat the given instruction until CX = 0 or zero flag ZF = 1.
REPNE/REPNZ − Used to repeat the given instruction until CX = 0 or zero flag ZF = 1.
MOVS/MOVSB/MOVSW − Used to move the byte/word from one string to another.
COMS/COMPSB/COMPSW − Used to compare two string bytes/words.
INS/INSB/INSW − Used as an input string/byte/word from the I/O port to the provided
memory location.
OUTS/OUTSB/OUTSW − Used as an output string/byte/word from the provided memory
location to the I/O port.
SCAS/SCASB/SCASW − Used to scan a string and compare its byte with a byte in AL or
string word with a word in AX.
LODS/LODSB/LODSW − Used to store the string byte into AL or string word into AX.
Interrupt Instructions
These instructions are used to call the interrupt during program execution.
INT − Used to interrupt the program during execution and calling service specified.
INTO − Used to interrupt the program during execution if OF = 1
IRET − Used to return from interrupt service to the main program
Assembler
It is a software tool which converts the assembly language program to machine language
program.
Assembler directives
Assembler directives are the directions to the assembler which indicate how an operand or section of the
program is to be processed. These are also called pseudo operations which are not executable by the
microprocessor.
Types of assembler directives are
Data definition and storage allocation directives
Program organization directives
Alignment directives
Program end directives
Procedure definition directives
Macro definition directives
Data control directives
Header file inclusion directives
.
.
ROOE ENDP
It shows that the procedure ROOT is to be aligned at even address memory loications.
ORG: Origin
This directive tells the assembler where to load instructions and data into memory. Ie, the start of
the memory allocation for a particular segment.
EX: ORG 2000H
Program end directives
END: End of a program.
It marks the end of assembly language program. It should be the last statement in the file.
Procedure definition directives
They are used to define sub programs. These are PROC and ENDP
PROC: procedure
It marks the start of a named procedure in the statement. The types NEAR or FAR specify the type
of the procedure. NEAR indicates that the subprogram is in the same memory segment. FAR
indicates that the subprogram is located in different memory segments.
EX;
RESULT PROC NEAR
RESULT2 PROC FAR
ENDP: End of Procedure:
It indicates the end of a procedure.
.
ENDM
Data control directives
These informs the assembler about the names, procedures and labels to be accessed from or can
be used in other program modules. These are PUBLIC and EXTRN .
PUBLIC AND EXTERN
The directive informs the assembler that the specified variable or segment can be accessed from
other modules. They must be declared as PUBLIC in a module which it physically exists.
EX:
MODULE 1 SEGMENT
PUBLIC ROOT FAR
MODULE 1 ENDS
MODULE 2 SEGMENT
EXTRN ROOT FAR
MODULE 2 ENDS
Header file inclusion directives
It is used to define an include file header. It informs the assembler to include the statements
defined in the include file.
General form; INCLUDE< FILE PATH SPECIFICATION>