Amp Module 2

Download as pdf or txt
Download as pdf or txt
You are on page 1of 15

Advanced Microprocessor 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.

Dept of ECE 1 MDIT polytechnic college


Advanced Microprocessor Module 2

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.

Dept of ECE 2 MDIT polytechnic college


Advanced Microprocessor Module 2

Single Step(type-1) Interrupt


When the Trap/Trace Flag (TF) is set to one, the 8086 processor will automatically generate a type-
1 interrupt after execution of each instruction. The user can write an ISS for type-1 interrupt to halt
the processor temporarily and return the control to the user so that after execution of each
instruction, the processor status (content of register/memory) can be verified. If they are correct
then we can proceed to execute the next instruction. Execution of one instruction by one instruction
is known as single step and this feature will be useful to debug a program.
Non-Maskable (type-2) Interrupt
The 8086 processor will automatically generate a type-2 interrupt when it receives a low-to-high
transition on its NMI input pin. This interrupt cannot be disabled or masked. Usually, the type-2
interrupt is used to save program data or processor status in case of system ac power failure.
The ac power failure is detected by an external hardware and whenever the ac power fails, the
external hardware will send an interrupt signal to the NMI input pin of the processor.
Breakpoint (type-3) Interrupt
Type-3 interrupt is used to implement a breakpoint function, which executes a program partly or up
to the desired point and then return the control to the user.
The breakpoint interrupt is initiated by the execution of "INT 3" instructions. To implement the
breakpoint function the system designer has to write an ISS for type-3, which takes care of
displaying a message and return the control to the user whenever type-3 interrupt is initiated.
This interrupt will be useful to debug a program by executing the program part by part. The user can
insert "INT 3" instruction at the desired location and execute the program. Whenever "INT 3"
instruction is encountered, the processor halts the program execution and returns the control to the
user.
Overflow (type-4) Interrupt
In the 8086 processor, the Overflow Flag (OF) will be set if the signed arithmetic operation
generates such a result whose size is larger than the size of the destination register/memory.
During conditions, the type-4 interrupt can be used to indicate an error condition. The type-4
interrupt is initiated by "INTO" instruction.
Interrupt vector table
1. The interrupt vector (or interrupt pointer) table is the link between an interrupt type code and
the procedure that has been designated to service interrupts associated with that code. 8086
supports total 256 types i.e. 00H to FFH.
2. For each type it has to reserve four bytes i.e. double word. This double word pointer contains
the address of the procedure that is to service interrupts of that type.

Dept of ECE 3 MDIT polytechnic college


Advanced Microprocessor Module 2

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.

Addressing modes of 8086


Method of specifying data to be operated by the instruction is called addressing mode.
This specifies that given data is an immediate data or an address. It also specifies whether the
given operand is in register or in register pair.
Different types of addressing modes are
1. Immediate addressing mode
In an immediate addressing mode , 8 bit data or 16 bit data is specifies as part of the
instruction.
Eg: MOV BX, 0065H
2. Direct addressing mode.
In this mode, 16 bit memory address is specifies in the instruction using square bracket.
Eg: MOV AX,[0024H]
3. In this addressing mode the instruction will specifies the name of register which holds the
data to be operated by the instruction.
Eg: MOV AX, BX
4. Register indirect addressing mode
In this addressing mode, 16 bit offset address is specifies by the base register BX or indexed
register SI or DI
Eg: MOV AX, [BX]
5. Base addressing mode.

Dept of ECE 5 MDIT polytechnic college


Advanced Microprocessor Module 2

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

Variable addressing mode


In this mode port address is specified indirectly in the instruction. The address of the port is
implied always to the content of register DX.
Ex: IN AX, DX
OUT DX,AX
10. Implicit addressing mode
In this mode. The instruction contains only the Opcode
Eg: CMC - complement carry flag
HLT - halt

Instruction set of 8086


The 8086 microprocessor supports 8 types of instructions −
 Data Transfer Instructions
 Arithmetic Instructions
 Bit Manipulation Instructions
 String Instructions
 Program Execution Transfer Instructions (Branch & Loop Instructions)

Dept of ECE 6 MDIT polytechnic college


Advanced Microprocessor Module 2

 Processor Control Instructions


 Iteration Control Instructions
 Interrupt Instructions.

Data Transfer Instructions


These instructions are used to transfer the data from the source operand to the destination operand.
Following are the list of instructions under this group –
Instruction to transfer a word
 MOV − Used to copy the byte or word from the provided source to the provided destination.
 PPUSH − Used to put a word at the top of the stack.
 POP − Used to get a word from the top of the stack to the provided location.
 PUSHA − Used to put all the registers into the stack.
 POPA − Used to get words from the stack to all registers.
 XCHG − Used to exchange the data from two locations.
 XLAT − Used to translate a byte in AL using a table in the memory.
Instructions for input and output port transfer
 IN − Used to read a byte or word from the provided port to the accumulator.
 OUT − Used to send out a byte or word from the accumulator to the provided port.
Instructions to transfer the address
 LEA − Used to load the address of operand into the provided register.
 LDS − Used to load DS register and other provided register from the memory
 LES − Used to load ES register and other provided register from the memory.
Instructions to transfer flag registers
 LAHF − Used to load AH with the low byte of the flag register.
 SAHF − Used to store AH register to higher byte of the flag register.
 PUSHF − Used to copy the flag register at the top of the stack.
 POPF − Used to copy a word at the top of the stack to the flag register.

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

 AAA − Used to adjust ASCII after addition.


 DAA − Used to adjust the decimal after the addition/subtraction operation.
Instructions to perform subtraction
 SUB − Used to subtract the byte from byte/word from word.
 SBB − Used to perform subtraction with borrow.
 DEC − Used to decrement the provided byte/word by 1.
 NPG − Used to negate each bit of the provided byte/word and add 1/2’s complement.
 CMP − Used to compare 2 provided byte/word.
 AAS − Used to adjust ASCII codes after subtraction.
 DAS − Used to adjust decimal after subtraction.
Instruction to perform multiplication
 MUL − Used to multiply unsigned byte by byte/word by word.
 IMUL − Used to multiply signed byte by byte/word by word.
 AAM − Used to adjust ASCII codes after multiplication.
Instructions to perform division
 DIV − Used to divide the unsigned word by byte or unsigned double word by word.
 IDIV − Used to divide the signed word by byte or signed double word by word.
 AAD − Used to adjust ASCII codes after division.
 CBW − Used to fill the upper byte of the word with the copies of sign bit of the lower byte.
 CWD − Used to fill the upper word of the double word with the sign bit of the lower word.

Bit Manipulation Instructions


These instructions are used to perform operations where data bits are involved, i.e. operations like
logical, shift, etc. That are
Instructions to perform logical operation
 NOT − Used to invert each bit of a byte or word.
 AND − Used for adding each bit in a byte/word with the corresponding bit in another
byte/word.
 OR − Used to multiply each bit in a byte/word with the corresponding bit in another byte/word.
 XOR − Used to perform Exclusive-OR operation over each bit in a byte/word with the
corresponding bit in another byte/word.
 TEST − Used to add operands to update flags, without affecting operands.
Instructions to perform shift operations
 SHL/SAL − Used to shift bits of a byte/word towards left and put zero(S) in LSBs.
Dept of ECE 8 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.

Program Execution Transfer Instructions (Branch and Loop


Instructions)
These instructions are used to transfer/branch the instructions during an execution. It includes the
following instructions −
Instructions to transfer the instruction during an execution without any condition −
 CALL − Used to call a procedure and save their return address to the stack.
 RET − Used to return from the procedure to the main program.
 JMP − Used to jump to the provided address to proceed to the next instruction.
Instructions to transfer the instruction during an execution with some conditions −

Dept of ECE 9 MDIT polytechnic college


Advanced Microprocessor Module 2

 JA/JNBE − Used to jump if above/not below/equal instruction satisfies.


 JAE/JNB − Used to jump if above/not below instruction satisfies.
 JBE/JNA − Used to jump if below/equal/ not above instruction satisfies.
 JC − Used to jump if carry flag CF = 1
 JE/JZ − Used to jump if equal/zero flag ZF = 1
 JG/JNLE − Used to jump if greater/not less than/equal instruction satisfies.
 JGE/JNL − Used to jump if greater than/equal/not less than instruction satisfies.
 JL/JNGE − Used to jump if less than/not greater than/equal instruction satisfies.
 JLE/JNG − Used to jump if less than/equal/if not greater than instruction satisfies.
 JNC − Used to jump if no carry flag (CF = 0)
 JNE/JNZ − Used to jump if not equal/zero flag ZF = 0
 JNO − Used to jump if no overflow flag OF = 0
 JNP/JPO − Used to jump if not parity/parity odd PF = 0
 JNS − Used to jump if not sign SF = 0
 JO − Used to jump if overflow flag OF = 1
 JP/JPE − Used to jump if parity/parity even PF = 1
 JS − Used to jump if sign flag SF = 1

Processor Control Instructions


These instructions are used to control the processor action by setting/resetting the flag values.
Following are the instructions under this group −
 STC − Used to set carry flag CF to 1
 CLC − Used to clear/reset carry flag CF to 0
 CMC − Used to put complement at the state of carry flag CF.
 STD − Used to set the direction flag DF to 1
 CLD − Used to clear/reset the direction flag DF to 0
 STI − Used to set the interrupt enable flag to 1, i.e., enable INTR input.
 CLI − Used to clear the interrupt enable flag to 0, i.e., disable INTR input.

Iteration Control Instructions


These instructions are used to execute the given instructions for number of times. Following is the
list of instructions under this group −
 LOOP − Used to loop a group of instructions until the condition satisfies, i.e., CX = 0
 LOOPE/LOOPZ − Used to loop a group of instructions till it satisfies ZF = 1 & CX = 0
 LOOPNE/LOOPNZ − Used to loop a group of instructions till it satisfies ZF = 0 & CX = 0
 JCXZ − Used to jump to the provided address if CX = 0
Dept of ECE 10 MDIT polytechnic college
Advanced Microprocessor Module 2

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

Data definition and storage allocation directives


These assembler directives are used to define the program variables and specified amount of
memory to them. These are DB, DW, DD, DQ, DT, and STRUCT
DB: Define Byte
The DB directive is used to reserve byte or bytes of memory location in the available memory.
It directs the assembler to allocate the specified number of memory bytes to the said data type that
may be a constant , variable, string ASCII codes, etc.
Ex:RANK DB 01H, 02H

Dept of ECE 11 MDIT polytechnic college


Advanced Microprocessor Module 2

DW: Define Word


The DW directive is used to reserve two bytes of memory location in the available memory.
Ex: DATA DW 2134H
DD: Define Double Word
This directive is used to reserve 4 bytes or two words of memory location in the available memory
DQ: Define Quad Word
This directive is used to reserve 8 bytes or 4 words of memory location in the available memory.
DT: Define Ten Bytes
This directive is used to reserve 10 bytes of memory location in the available memory with specific
values.
STRUCT : structure declaration
This is used to declare the data type which is a collection of primary data types (DB,DW and DW).
It allows the user to define a variable which has more than one data types.

Program organization directives


These directives are used to organize the program segments. These are SEGMENT, ENDS and
ASSUME.
SEGMENT: Logical segment. This is used to mark the starting of a logical segment. The started
segment is also assigned a label by this statement.
ENDS: End of Segment:
It marks the end of a logical segment.
ASSUME: assume logical segment name: It informs the assembler the name of the logical
segment to be assumed for different segments used in the program
The ASSUME statement is a must at the starting of each assembly language program
Ex: ASSUME CS : CODE
This statement directs the assembler that the machine codes are available in a segment named
CODE.
Alignment directives
These directives are used to control location counter used by the assembler during machine code
generation. They include EVEN and ORG
EVEN: align on even memory address.
This directive updates the location counter to the next even address.
EX: EVEN
PROCEDURE ROOT
.
Dept of ECE 12 MDIT polytechnic college
Advanced Microprocessor Module 2

.
.
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.

Macro definition directives


These directives reduces the recurrence of the numerical values or constants in program code
These are EQU, MACRO and ENDM
EQU: it simply equate a symbolic name to numerical value. Such symbols are called macro
symbols.
Ex: SUM EQU 15H
MACRO: It marks the beginning of a macro. It consists of a macro followed by the keyword
MACRO and macro arguments if any.the MACRO should lie in between the directives MACRO and
ENDM.
Ex: Macro name MACRO[arguments]
.
.
Dept of ECE 13 MDIT polytechnic college
Advanced Microprocessor Module 2

.
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>

Dept of ECE 14 MDIT polytechnic college


Advanced Microprocessor Module 2

Dept of ECE 15 MDIT polytechnic college

You might also like