Interrupt follow a follow a certain mechanism for their invocation just like near or far procedures. To understand this mechanism we need to understand its differences with procedure calls.
Difference between interrupt and procedure calls
Procedures or functions of sub-routines in various different languages are called by different methods as can be seen in the examples.
- Call MyProc
- A= Addition(4,5);
- Printf(“hello world”);
The general concept for procedure call in most of the programming languages is that on invocation of the procedure the parameter list and the return address (which is the value if IP register in case of near or the value of CS and IP registers in case of far procedure) is pushed Moreover in various programming languages whenever a procedure is called its address need to be specified by some notation i.e. in C language the name of the procedure is specified to call a procedure which effectively can be used as its address.
However in case of interrupts the a number is used to specify the interrupt number in the call
- Int 21h
- Int 10h
- Int3
Moreover when an interrupt is invoked three registers are pushed as the return address i.e. the values of IP, CS and Flags in the described order which are restored on return. Also no parameters are pushed onto the stack on invocation parameters can only be passed through registers.
The interrupt vector table
The interrupt number specified in the interrupt call is used as an index into the interrupt vector table. Interrupt vector table is a global table situated at the address 0000:0000H. The size of interrupt vector table is 1024 bytes or 1 KB. Each entry in the IVT is sized 4 bytes hence 256 interrupt vectors are possible numbered (0-FFH). Each entry in the table contains a far address of an interrupt handlers hence there is a maximum of 256 handlers however each handlers can have a number of services within itself. So the number operations that can be performed by calling an interrupt service routine (ISR) is indefinite depending upon the nature of the operating system. Each vector contains a far address of an interrupt handler. The address of the vector and not the address of interrupt handler can be easily calculated if the interrupt number is known. The segment address of the whole IVT is 0000H the offset address for a particular interrupt handler can be determined by multiplying its number with 4 eg. The offset address of the vector of
INT 21H will be 21H * 4 = 84H and the segment for all vectors is 0 hence its far address is 0000:0084H,( this is the far address of the interrupt vector and not the interrupt service routine or interrupt handler). The vector in turn contains the address of the interrupt service routine which is an arbitrary value depending upon the location of the ISR residing in memory.
Fig 2 (Interrupt Vector Table)
Location of ISRs (Interrupt service routines)
Generally there are three kind of ISR within a system depending upon the entity which implements it
- BIOS (Basic I/O services) ISRs
- DOS ISRs
- ISRs provided by third party device drivers
Fig 4 (ISRs in memory)
This fact can be practically analyzed by the DOS command mem/d which gives the status of the memory and also points out which memory area occupied by which process as shown in the text below. The information given by this command indicates the address where IO.SYS and other device drivers have been loaded but the location of ROM BIOS is not shown by this command.
C:\>mem /d
Address Name Size Type
------- -------- ------ ------
000000 000400 Interrupt Vector
000400 000100 ROM Communication Area
000500 000200 DOS Communication Area
000700 IO 000370 System Data
CON System Device Driver
AUX System Device Driver
PRN System Device Driver
CLOCK$ System Device Driver
COM1 System Device Driver
LPT1 System Device Driver
LPT2 System Device Driver
LPT3 System Device Driver
COM2 System Device Driver
COM3 System Device Driver
COM4 System Device Driver
000A70 MSDOS 001610 System Data
002080 IO 002030 System Data
KBD 000CE0 System Program
HIMEM 0004E0 DEVICE=
XMSXXXX0 Installed Device Driver
000490 FILES=
000090 FCBS=
000120 LASTDRIVE=
0007D0 STACKS=
0040C0 COMMAND 000A20 Program
004AF0 MSDOS 000070 -- Free --
004B70 COMMAND 0006D0 Environment
005250 DOSX 0087A0 Program
00DA00 MEM 000610 Environment
00E020 MEM 0174E0 Program
025510 MSDOS 07AAD0 -- Free --
09FFF0 SYSTEM 02F000 System Program
0CF000 IO 003100 System Data
MOUSE 0030F0 System Program
0D2110 MSDOS 000600 -- Free --
0D2720 MSCDEXNT 0001D0 Program
0D2900 REDIR 000A70 Program
0D3380 DOSX 000080 Data
0D3410 MSDOS 00CBE0 -- Free --
655360 bytes total conventional memory
655360 bytes available to MS-DOS
597952 largest executable program size
1048576 bytes total contiguous extended memory
0 bytes available contiguous extended memory
941056 bytes available XMS memory
MS-DOS resident in High Memory Area
Interrupt Invocation
Although hardware and software interrupts are invoked differently i.e hardware interrupts are invoked by means of some hardware whereas software interrupts are invoked by means of software instruction or statement but no matter how an interrupt has been invoked processor follows a certain set steps after invocation of interrupts in exactly same way in both the cases. These steps are listed as below
- Push Flags, CS, IP Registers, Clear Interrupt Flag
- Use (INT#)*4 as Offset and Zero as Segment
- This is the address of interrupt Vector and not the ISR
- Use lower two bytes of interrupt Vector as offset and move into IP
- Use the higher two bytes of Vector as Segment Address and move it into CS=0:[offset+2]
- Branch to ISR and Perform I/O Operation
- Return to Point of Interruption by Popping the 6 bytes i.e. Flags CS, IP.
This can be analyzed practically by the use of debug program, used to debug assembly language code, by assembling and debugging INT instructions
C:\>debug
-d 0:84
0000:0080 7C 10 A7 00-4F 03 55 05 8A 03 55 05 |...O.U...U.
0000:0090 17 03 55 05 86 10 A7 00-90 10 A7 00 9A 10 A7 00 ..U.............
0000:00A0 B8 10 A7 00 54 02 70 00-F2 04 74 CC B8 10 A7 00 ....T.p...t.....
0000:00B0 B8 10 A7 00 B8 10 A7 00-40 01 21 04 50 09 AB D4 ........@.!.P...
0000:00C0 EA AE 10 A7 00 E8 00 F0-B8 10 A7 00 C4 23 02 C9 .............#..
0000:00D0 B8 10 A7 00 B8 10 A7 00-B8 10 A7 00 B8 10 A7 00 ................7
0000:00E0 B8 10 A7 00 B8 10 A7 00-B8 10 A7 00 B8 10 A7 00 ................
0000:00F0 B8 10 A7 00 B8 10 A7 00-B8 10 A7 00 B8 10 A7 00 ................
0000:0100 8A 04 10 02 ....
-a
0AF1:0100 int 21
0AF1:0102
-r
AX=0000 BX=0000 CX=0000 DX=0000 SP=FFEE BP=0000 SI=0000 DI=0000
DS=0AF1 ES=0AF1 SS=0AF1 CS=0AF1 IP=0100 NV UP EI PL NZ NA PO NC
0AF1:0100 CD21 INT 21
-t
AX=0000 BX=0000 CX=0000 DX=0000 SP=FFE8 BP=0000 SI=0000 DI=0000
DS=0AF1 ES=0AF1 SS=0AF1 CS=00A7 IP=107C NV UP DI PL NZ NA PO NC
00A7:107C 90 NOP
-d ss:ffe8
0AF1:FFE0 02 01 F1 0A 02 F2 00 00
0AF1:FFF0 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00
The dump at the address 0000:0084 H shows the value of the vector of the interrupt # 21H i.e. 21H * 4 = 84H. This address holds the value 107CH in lower word and 00A7H in the higher word which indicates that the segment address of interrupt # 21 is 00A7H and the offset address of this ISR is 107CH.
Moreover the instruction INT 21H can be assembled and executed in the debug program, on doing exactly so the instruction is traced through and the result is monitored. It can be seen that on execution of this instruction the value of IP is changed to 107CH and the value of CS is changed to 00A7H which cause the execution to branch to the Interrupt # 21H in memory and the previous values of flags, CS and IP registers are temporarily saved onto the stack as the value of SP is reduced by 6 and the dump at the location SS:SP will show these saved values as well.
Parameter passing into Software interrupts
In case of procedures or function in various programming languages parameters are passed through stack. Interrupts are also kind of function provided by the operating system but they do not accept parameters by stack rather they need to passed parameters through registers.
Software interrupts invocation
Now let’s see how various interrupts can be invoked by means of software statements. First there should be way to pass parameters into a software interrupt before invoking the interrupt; there are several methods for doing this. One of the methods is the use of pseudo variables. A variable can be defined a space within the memory whose value can be changed during the execution of a program but a pseudo variable acts very much like a variable as its value can be changed anywhere in the program but is not a true variable as it is not stored in memory. C programming language provides the use of pseudo variables to access various registers within the processor.
The are various registers like AX, BX, CX and DX within the processor they can be directly accessed in a program by using their respective pseudo variable by just attaching a “_” (underscore) before the register’s name eg. _AX = 5; A = _BX .
After passing the appropriate parameters the interrupt can be directly invoked by calling the geninterrupt () function. The interrupt number needs to be passed as parameter into the geninterrupt() function.
Interrupt # 21H, Service # 09 description
Now lets learn by means of an example how this can be accomplished. Before invoking the interrupt the programmer needs to know how the interrupt behaves and what parameters it requires. Lets take the example of interrupt # 21H and service # 09 written as 21H/09H in short. It is used to print a string ending by a ‘$’ character and other parameters describing the string are as below
Inputs
AH = 0x09
DS = Segment Address of string
DX = Offset Address of string
Output
The ‘$’ terminated string at the address DS:DX is displayed
One thing is note worthy that the service # is placed in AH which is common with almost all the interrupts and its service. Also this service is not returning any siginificant data, if some service needs to return some data it too is received in registers depending upon the particular interrupt.
Example:
#include
#include
#include
char st[80] ={"Hello World$"};
void main()
{
clrscr(); //to clear the screen contents
_DX = (unsigned int) st;
_AH = 0x09;
getch(); //waits for the user to press any key
}
this is a simple example in which the parameters of int 21H/09H are loaded and then int 21H is invoked. DX and AH registers are accessed through pseudo variables and then geninterrupt()is called to invoke the ISR. Also note that _DS is not loaded. This is th
Another Method for invoking software interrupts
This method makes use of a Union. This union is formed by two structure which correspond to general purpose registers AX, BX, CX and DX. And also the half register AH, AL, BH, BL, CH, CL, DH, DL. These structures are combined such that through this str
struct full
unsigned int ax;
unsigned int bx;
unsigned int cx;
unsigned int dx;
};
struct half
{
unsigned char al;
unsigned char bl;
unsigned char bh;
unsigned char cl;
unsigned char ch;
unsigned char dl;
unsigned char dh;
};
typedef union tagREGS
struct full x;
struct half h;
}REGS;
This union can be used to signify any of the full or half general purpo
Example:
#include
union REGS regs;
void main (void )
regs.h.al = 0x55;
regs.h.ah = 0x99;
printf (“%x”,regs.x.ax);
}
output:
9955
The significance of this REGS union can only be understood after understanding the int86() function. The int86() has three parameters. The first parameter is the interrupt number to be invoked, the second parameter is the reference to a REGS type union which contains the value of parameters that should be passed as inputs, and third parameter is a reference to a REGS union which will contain the value of registers returned by this function. A
Example using interrupt # 21H service # 42H
Int # 21 Service # 42H
Inputs
AL = Move Technique
CX-DX = No of Bytes File to be moved
AH = Service # = 42H
DX-AX = No of Bytes File pointer actually moved.
CX-DX specify the number of bytes to move a double word is needed to specify this value as the size of file in DOS can be up to 2 GB.
On return of the service DX-AX will contain the number of bytes the file pointer is actually moved eg. If the file pointer is moved relative to the EOF zero bytes the DX-AX on return will contain the size of file if the file pointer was at BOF before calling the service.
6 comments:
I'm truly enjoying the design and layout of your site. It's a very easy on the eyes which makes it much
more enjoyable for me to come here and visit more often.
Did you hire out a developer to create your theme? Fantastic
work!
my blog appliance repair business opportunity
Today, I went to the beach with my children. I found a sea shell and gave it to my 4 year old daughter and said "You can hear the ocean if you put this to your ear." She put the shell to her ear and screamed.
There was a hermit crab inside and it pinched her ear.
She never wants to go back! LoL I know this
is completely off topic but I had to tell someone!
Also visit my web site ... sd memory card class 10
Hmm it looks like your site ate my first comment (it was super long)
so I guess I'll just sum it up what I wrote and say, I'm thoroughly
enjoying your blog. I as well am an aspiring blog
writer but I'm still new to the whole thing. Do you have any points for first-time blog writers? I'd genuinely appreciate it.
Here is my web blog ... freezer storage baskets stackable
Pretty section of content. I just stumbled upon your website
and in accession capital to assert that I acquire in fact enjoyed account your blog posts.
Any way I will be subscribing to your feeds and even I achievement you access consistently quickly.
Feel free to surf to my webpage: journals.fotki.com
Hey there, I think your blog might be having browser compatibility issues.
When I look at your blog in Firefox, it looks fine but when opening in Internet Explorer, it has some overlapping.
I just wanted to give you a quick heads up! Other then that,
very good blog!
my webpage refrigerators home depot
Hi,An important element when designing internet sites is keeping the website simple to navigate for Web Design Cochin. It's no use spending numerous hours in creating a website and visitors can not travel easily round the website or internet pages.
Post a Comment
Thanks for interest it