0% found this document useful (0 votes)
46 views3 pages

Fall 2021 CS609: System Programming Assignment No. 01

This document contains instructions for a system programming assignment involving file I/O in C. It includes 3 questions: 1) Write a program to open a text file, read and display its contents, move the file pointer, and close the file, checking for errors. 2) Calculate the interrupt vector index for interrupt number 20 without code. 3) Explain how interrupt vector entries contain offset and segment addresses, with the offset in the lower word and segment in the higher word.

Uploaded by

ZERMEENA JAFFAR
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
46 views3 pages

Fall 2021 CS609: System Programming Assignment No. 01

This document contains instructions for a system programming assignment involving file I/O in C. It includes 3 questions: 1) Write a program to open a text file, read and display its contents, move the file pointer, and close the file, checking for errors. 2) Calculate the interrupt vector index for interrupt number 20 without code. 3) Explain how interrupt vector entries contain offset and segment addresses, with the offset in the lower word and segment in the higher word.

Uploaded by

ZERMEENA JAFFAR
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Fall 2021 CS609:

System Programming Assignment No. 01


Vu id: mc200203140.

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:

a) Read the file and show the contents on the screen

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.

• INT86 () function’s signature is: int86(int#, & regs , &regs);

• 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)

printf("Error File cannot be Opened.");

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.

You might also like