





Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
This lecture handout is for System Programming course. It was provided by Prof. Indubhushan Vijayabhas at Ambedkar University, Delhi. It includes: Interupt, Mechanism, Invocation, Procedure, Interuppt, Procedure, Call, Programming, Language
Typology: Study notes
1 / 9
This page cannot be seen from the preview
Don't miss anything!






Interrupt Mechanism 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.
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
Main Call proc1() Call proc1()
Proc1()
Proc2()
Int 21h
Int 10h
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)
Moreover it is important to understand the meaning of the four bytes within the interrupt vector. Each entry within the IVT contain a far address the first two bytes (lower word) of which is the offset and the next two bytes (higher word) is the segment address.
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
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: 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 ................ 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: -r AX=0000 BX=0000 CX=0000 DX=0000 SP=FFEE BP=0000 SI=0000 DI= 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= DS=0AF1 ES=0AF1 SS=0AF1 CS=00A7 IP=107C NV UP DI PL NZ NA PO NC 00A7:107C 90 NOP -d ss:ffe 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
#include<BIOS.H> #include<DOS.H> #include<conio.h>
char st[80] ={"Hello World$"};
void main() { clrscr(); //to clear the screen contents _DX = (unsigned int) st; _AH = 0x09; geninterrupt(0x21); 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 the case as the string to be loaded is of global scope and the C language compiler automatically loads the segment address of the global data into the DS register.
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 structure the field ax can be accessed to load a value and also its half components al and ah can be accessed individually. The declaration of this structure goes as below. If this union is to be used a programmer need not declare the following declaration rather declaration already available through its header file “dos.h”
struct full { unsigned int ax; unsigned int bx; unsigned int cx; unsigned int dx; }; struct half { unsigned char al; unsigned char ah; 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 purpose register shows if the field ax in x struct is to be accessed then accessing the fields al and ah in h will also have the same effect as show in the example below. Example:
#include<DOS.H>
union REGS regs; void main (void ) { regs.h.al = 0x55; regs.h.ah = 0x99; printf (“%x”,regs.x.ax); }
output: 9955
The int86() function 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. All the required parameters for an ISR are placed in REGS type of union and its reference is passed to an int86() function. This function will put the value in this union into the respective register and then invoke the interrupt. As the ISR returns it might leave some meaningful value in the register (ISR will return values), these values can be retrieved from the REGS union whose reference was passed into the function as the third parameter. Example using interrupt # 21H service # 42H To make it more meaningful we can again elaborate it by means of an example. Here we make use of ISR 21H/42H which is used to move the file pointer. Its detail is as follows
Int # 21 Service # 42H Inputs AL = Move Technique BX = File Handle CX-DX = No of Bytes File to be moved AH = Service # = 42H