Fall 2021 CS609: System Programming Assignment No. 01
Fall 2021 CS609: System Programming Assignment No. 01
Question 1:
Suppose you have a text file, myText.txt, saved in D: drive. This file contains the string: “Proud to be a
student of Virtual University of Pakistan”.
Write a C program that will open this file in reading mode and perform the following tasks on it:
b) Move the File Pointer across the file, relative to the beginning of the file (BOF)
c) Close the file when file pointer reaches the End of File (EOF)
d) Print error message (if any error occurs) in opening or moving the file pointer (after checking FLAG
variable defined in the REGS union).
Detailed Instructions:
• Use interrupt 21H/42H and invoke this interrupt using INT86() function.
• The REGS union is defined in DOS.H header file. In this union, an unsigned integer variable cflag is
defined as a FLAG variable. Check its value after invoking INT86().
• This question requires only C language code written in Word file. Output screenshots are not required.
If you attach screenshot, it will not carry any additional marks.
Answer no 1:
#include<stdio.h>
#include<stdlib.h>
int main()
char n[10000];
FILE *fptr;
if ((fptr=fopen("D:/mytext.txt","r"))==NULL)
exit(1);
fscanf(fptr,"%[^\n]",n);
fclose(fptr);
return 0;
Question 2:
Suppose interrupt number 20 is invoked by a hardware device. Do calculations for getting interrupt
vector indexed in Interrupt Vector Table [Code is not required. Perform calculations in Word file]
Answer No 2:
Interrupt vectors are addresses which inform the interrupt handler as to where to find the ISR. All
interrupts are assigned a number from 0 to 255. The interrupt vectors associated with each interrupt
number are stored in the lower 1024 bytes of PC memory. The interrupt vector table is normally located
in the first 1024 bytes of memory at addresses 000000H–0003FFH. It contains 256 different interrupt
vectors. Each vector is 4 bytes long and contains the starting address of the ISR. As in the Question the
interrupt number 20 and also this is hardware interrupt so the offset of address int20H will be 20H*4 =
80H. As the segment vector is 0 so the far address will be 0000:0080H So the offset address is = 0080H
Segment address = 0080H + 2 = 0082H
Question 3:
How offset and segment address of an interrupt occupies the lower and higher word of Interrupt Vector
Table? Show by the help of a diagram
Answer No 3:
In the IVT each entry contains 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.