Interrupts in Personal Computers: Experiment #6
Interrupts in Personal Computers: Experiment #6
Birzeit University
Faculty of Engineering and Technology
Department of Electrical and Computer Engineering
Abstract
This experiment aims at understanding and expanding the concept of interruption. Students will
learn how to use and call Interrupt Service Routines (ISR) based on MS Windows XP OS. Besides,
creating a new ISR using debug and TASM will be a main task of the experiment.
1
PART I Theoretical Introduction
The 8086 interrupts can be classified into three types. These are
1. Predefined interrupts
2. User-defined software interrupts
3. User-defined hardware interrupts
The interrupt vector address f or all the 8086 interrupts are determined from a table stored in
locations 00000H through 003FFH. The starting addresses for the service routines for the
interrupts are obtained by the 8086 using this table. Four bytes of the table are assigned to each
interrupt: two bytes for IP and two bytes for CS. The table may contain up to 256 8-bit vectors. If
fewer than 256 interrupts are defined in the system, the user need only provide enough memory for
the interrupt pointer table for obtaining the defined interrupts. The interrupt address vector
(contents of IP and CS) for all the interrupts of the 8086 assigns every interrupt a type code for
identifying the interrupt. There are 256 type codes associated with 256 table entries. Each entry
consists of two addresses, one for storing the IP contents and the other for storing the CS contents.
Each 8086-interrupt physical address vector is 20 bits wide and is computed from the 16-bit
contents of IP and CS. For obtaining an interrupt address vector, the 8086 calculates two addresses
in the pointer table where IP and CS are stored for a particular interrupt type. For example, for the
interrupt type nn (instruction INT nn), the table address for IP=4×nn and the table address for
CS=4×nn+2. For servicing the 8086's non-maskable interrupt (NMI pin), the 8086 assigns the type
code 2 to this interrupt. The 8086 automatically executes the INT2 instruction internally to obtain
the interrupt address vector as follows:
The 8086 loads the values of IP and CS from the 20-bit physical address 00008H and 0000AH in
the pointer table. The user must store the desired 16-bit values of IP and CS in these locations.
Similarly, the I P and CS values for other interrupts are calculated. The 8086-interrupt pointer table
layout is shown in Figure 1.
2
Figure 1 Interrupt Vector Table
3
In response to an interrupt, the 8086 pushes flags, CS, and IP onto the stack, clears TF and IF
flags, and then loads IP and CS from the pointer table using the type code. Interrupt service routine
should be terminated with the IRET (Interrupt Return) instruction which pops the top three s tack
words into IP, CS, and flags, thus returning to the right place in the main program. The 256
interrupt type codes are assigned as follows;
PART II Pre-Lab
4
PART III Practices
-INT 0
Step 3: Run the program using G (Make sure the IP value is 100).
TASKS:
1. Explain what does “INT 0” do?
TASKS:
1. Explain the result (Notice Figure 3)?
2. INT 3 used to set break point and stops the executions. If this instruction was removed, will
there be any changes in the result?
1 n: Interrupt number
5
Figure 3 Activating ISP Automatically
What we are trying to do in this practice is changing the CS and IP to the address of the ISP number
0 and executing using G. This supposed to work as it works with “INT 0” instruction.
Step 2: Run the R command and check the content of the registers.
Step 3: The vector table is located in the address 0:0 on the memory, Display the content of
memory at this address (Hint: use D command).
Step 4: The address of interrupt service routine corresponding to INT 0 is located the range 0-3 as
shown in table below
3 Segment (high)
2 Segment (low)
1 Offset (high)
6
0 Offset (low)
(P.S.: The values of segment and offset below are not necessary the same on your PC)
Step 5: We can run the interrupt service routine by making the CS register points to the
code segment that the interrupt service routine located in it and making the IP register points to the
start address of the interrupt service routine. (Hint: Use R command)
TASKS:
1. You should notice that the results of this practice and Practice I are the Same.
2. What is the routine address of INT F stored in the Interrupt Vector Table?
Now, to change the INT response. What about replacing the code of ISP 0? or maybe creating a
new code and replace the vector values with its address? We can write our routine and make it run
when dived by zero occur by putting the address (segment and offset) of our new routine in
memory location 0-3.
7
Out task: is to rewrite the interrupt routine for INT 0 to display AAAA when a divide by zero
occur.
MOV CX,4
L1: MOV DL,41
MOV AH,6
INT 21
LOOP L1
INT 3
Step 4: Now we can test the new interrupt routine by making a program that makes a division by
zero (e.g. Practice II)
Code Example:
MOV CL,0
MOV AX,5043
DIV CL
INT 3
Notice that when we execute the program AAAA is displayed instead of divide overflow (Notice
Figure 6).
8
3.4 PRACTICE V: Creating Your Own ISP Using TASM
In this practice we would work on installing a new interrupt service routine for interrupt
number 62.
Setp1: Write down the following code and save it to an Assembly file.
.MODEL TINY
.CODE
.STACK 100H
JMP INSTALL
MESS DB "WELCOME TO COOLEST LAB ON EARTH ENCS411 :D $"
MYINT PROC
L1:
MOV AL ,CS:[BX]
CMP al, '$'
JZ L2
PUSH BX
POP BX
INC BX
JMP L1
L2:
IRET
MYINT ENDP
INSTALL:
;install new interrupt vector
MOV AH,25H ;set interrupt vector
MOV AL,62H ;desired interrupt vector
MOV DX,CS
MOV DS,DX
MOV DX, OFFSET MYINT
INT 21H
MOV AX,3100H
INT 21H
END
9
Step2: Compile and build this ASM file and execute it on MDA-8086 kit. (How? Review Exp#1 Intro.
To MDA Kit)
- Open debug.
- Execute the instruction “INT 62”. What is the result?
.MODEL SMALL
.STACK 100
.CODE
INT 62H
mov AH,4CH
INT 21H
END
TASKS:
1. Explain what does this code do (Line by line)?
2. What does INT 21 do?
10