@zareen said in CS409 Assignment 2 Solution and Discussion:
Consider the given below the ERD
b715a3fa-af52-42a4-ac14-a1726d7469d4-image.png
Semester: Spring 2019
CS609: System Programming
Graded
Assignment No. 03
Total Marks: 20
Due Date: July 16, 2019
Instructions:
Please read the following instructions carefully before submitting assignment. It should be clear that your assignment will not get any credit if:
♣ The assignment is submitted after due date.
♣ The submitted assignment does not open or file is corrupt.
♣ You have not followed steps described in Detailed Instructions of the problem statement.
♣ Assignment is copied (partial or full) from any source (websites, forums, students, etc.) Strict action will be taken in this regard.
Note: You have to upload only .doc or .docx file. Assignment in any other format (extension) will not be accepted and will be awarded with zero marks.
Objectives:
The objective of this assignment is to provide hands-on experience of System Programming concepts including:
• Hard Disk interrupts
• Hard Disk data reading
• Hard Disk BioDisk() function
For any assignment related query, contact at [email protected]
Problem Statement:
Q: Write a program which reads two physically addressed blocks from disk using biosdisk() function.
Instructions:
• Declare arrays to handle head, sector and track numbers to read from hard disk.
unsigned char headno[10];
unsigned char secno[10];
unsigned char trackno[10];
• Similarly declare a buffer of 1024 char to store data 2 blocks data etc.
• unsigned char buf[1024];
• Use printf to print message of entering head no. i.e printf("Head ");
• Use gets function to get head no. from user i.e gets(headno);
• Use puts function to put headno in array of headno
• Use biodisk function to read two blocks i.e
biosdisk(2,0x80,atoi(headno),atoi(trackno),atoi(secno),2,buf) ;
• Similarly get and put sector and track numbers.
• Show error message in case of failure of biodisk() function.
Note: Your assignment file should be a single Word file (.doc or .docx) containing code only.
Best of Luck!
@moaaz
Another Idea solution
#include <bios.h>
#include <dos.h>
FILE *fp;
unsigned char buf[1024];
unsigned char st[60];
unsigned char headno[10];
unsigned char secno[10];
unsigned char trackno[10];
void main (void)
{
int i;
for (i=0; i<1024; i++)
buf[i]=0;
gets(st);
fp=fopeon(st,”wb”);
printf(“Head”);
gets(headno);
puts(headno);
printf(“/nsector ”);
gets(secno);
puts(secno);
printf(“/ntrack ”);
gets(trackno);
puts(trackno);
i = biosdisk(2, 0x80, atoi(headno), atoi(trackno), atoi(trackno), 2,buf);
}
if(*(((char *)(&i))+1)= =0)
{
fwrite(buf,2,1024,fp);
fclose(fp);
}
else
{
printf(“Cannot Read Error# = %x” i);
}
Idea Solution
#include #include FILE *fp;
unsigned char buf[1024];
unsigned char st[60];
unsigned char headno[10];
unsigned char secno[10];
unsigned char trackno[10];
void main (void) {
int i ;
for (i=0;i<1024;i++)
buf[i]=0;
gets(st);
fp=fopen(st,"wb");
printf("Head ");
gets(headno);
puts (headno);
i = biosdisk(2,0x80,atoi(headno), atoi(trackno),atoi(secno),2,buf) ;
if (*(((char *)(&i))+1)==0) {
fwrite(buf,2,1024,fp); fclose(fp);
}
else printf("Cannot Read Error# = %x",i);
}
@Anaya-Ali