Saturday, 7 September 2013

System Programming


System Programming

System Programming : -
In  IT department of a large organization, a technical expert on some or all of the computer's system software (operating systems, networks, DBMSs, etc.). They are responsible for the efficient performance of the computer systems.
In a user organization, systems programmers typically do not write programs, but perform many technical tasks that integrate vendors' software. They also act as technical advisers to systems analysts, application programmers and operations personnel. For example, they would know whether additional tasks could be added to the computer and would recommend conversion to a new operating or database system in order to optimize performance.
Here are few programs which are written  in C LANGUAGE.   This Is the Lab work  of  Sytem Programming.
Q. Write a program to create a menu driven interface for
i) Displaying contents of a file page wise.
ii) Counting Vowels, character and lines in a file
iii) Copying a file.
i) Displaying contents of a file.
Solution.
#include<stdio.h>
#include<conio.h>
void main()
{
FILE *fp;
char ch;
clrscr();
fp=fopen("B1.txt","w");
while(ch!='z')
{
ch=getche();
fputc(ch,fp);
}
fclose(fp);
getch();
}
Output 1

Q.WAP to display contents of file page wise
Solution 
#include<stdio.h>
#include<conio.h>
void main()
{
FILE *sp1,*sp2;
char ch;
sp1=fopen("H1.txt","r");
sp2=fopen("H2.txt","w");
while(ch!=EOF)
{
ch=getc(sp1);
printf("%c",ch);
fputc(ch,sp2);
}
fclose(sp1);
fclose(sp2);
getch();
}
 Output :- 
Program to display contents of file page wise

Q.Write a program for Counting characters in a file
Solution : -
#include<stdio.h>
#include<conio.h>
void main()
{
FILE *fp,*fs,*fs1;
char ch;
clrscr();
fp=fopen("P.txt","w");
while(ch!='*')
{
ch=getche();
fputc(ch,fp);
}
fclose(fp);
fs=fopen("P.txt","r");
fs1=fopen("P 1.txt","w");
while(ch==EOF)
{
ch=getche();
printf("%c",ch);
fputc(ch,fs1);
}
fclose(fs);
fclose(fs1);
getch();
}

program for Counting characters in a file

Q.Write a program to copy the content of one file into another file.
Solution
#include<stdio.h>
#include<conio.h>
void main()
{
FILE *p,*q;
char file1[20],file2[20];
char ch;
clrscr();
printf("\Enter the source file name to be copied:");
gets(file1);
p=fopen(file1,"r");
if(p==NULL)
{
printf("\n Cannot open %s",file1);
getch();
}
printf("\n Enter the destination file name:");
gets(file2);
q=fopen(file2,"w");
if(q==NULL)
{
printf("Cannot open %s",file2);
getch();
}
while((ch=getc(p))!=EOF)
putc(ch,q);
printf("\n COMPLETED");
fclose(p);
fclose(q);
getch();
}

OUTPUT:
program to copy the content of one file into another file.

Q.Write a Menu driven program
Solution
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
FILE *ptr1,*ptr2,*ptr3;
char ch,k;
printf("Enter ur choice \n a for writing data onto file \n b for copying to another file \n c for writng and copying data \n");
k=getche();
switch(k)
{
case'a':
printf("\n Write the contents of the file \n");
ptr1=fopen("navi1.txt","w");
while(ch!='*')
{
ch=getche();
fputc(ch,ptr1);
}
printf("\n Contents have been written to the file");
fclose(ptr1);
break;
case'b':
ptr1=fopen("navi1.txt","r");
ptr2=fopen("navi2.txt","w");
printf("\n The contents that have been copied are: \n");
while(ch!=EOF)
{
ch=fgetc(ptr1);
printf("%c",ch);
fputc(ch,ptr2);
}
fclose(ptr1);
fclose(ptr2);
break;
case'c':
printf("\n Write the contents of the file \n");
ptr1=fopen("navi1.txt","w");
while(ch!='*')
{
ch=getche();
fputc(ch,ptr1);
}
printf("\n The contents have been written to the file");
fclose(ptr1);
ptr2=fopen("navi1.txt","r");
ptr3=fopen("navi2.txt","w");
printf("\n The contents that have been copied are: \n");
while(ch!=EOF)
{
ch=fgetc(ptr2);
printf("%c",ch);
fputc(ch,ptr3);
}
fclose(ptr2);
fclose(ptr3);
break;
default:
printf("\n Wrong input");
break;
}
getch();
}
Output :- 
a Menu driven program

Q.Write a program To Study the algorithm and development of Pass 1 of Assembler
Solution:-
#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<stdlib.h>
void main()
{
Char opcode[10],operand[10],label[10],code[10][10],ch; char mnemonic[10][10]={"START","LDA","STA","LDCH","STCH","END"};
int locctr,start,len,i=0,j=0;
FILE *fp1,*fp2,*fp3;
clrscr();
fp1=fopen("INPUT.DAT","r");
fp2=fopen("SYMTAB.DAT","w");
fp3=fopen("OUT.DAT","w");
fscanf(fp1,"%s%s%s",label,opcode,operand);
if(strcmp(opcode,"START")==0)
{
start=atoi(operand);
locctr=start;
fprintf(fp3,"%s\t%s\t%s\n",label,opcode,operand);
fscanf(fp1,"%s%s%s",label,opcode,operand);
}
else
locctr=0;
while(strcmp(opcode,"END")!=0)
{
fprintf(fp3,"%d",locctr);
if(strcmp(label,"**")!=0)
fprintf(fp2,"%s\t%d\n",label,locctr);
strcpy(code[i],mnemonic[j]);
while(strcmp(mnemonic[j],"END")!=0)
{
if(strcmp(opcode,mnemonic[j])==0)
{
locctr+=3;
break;
}
strcpy(code[i],mnemonic[j]);
j++;
}
if(strcmp(opcode,"WORD")==0)
locctr+=3;
else if(strcmp(opcode,"RESW")==0)
locctr+=(3*(atoi(operand)));
else if(strcmp(opcode,"RESB")==0)
locctr+=(atoi(operand));
else if(strcmp(opcode,"BYTE")==0)
++locctr;
fprintf(fp3,"\t%s\t%s\t%s\n",label,opcode,operand);
fscanf(fp1,"%s%s%s",label,opcode,operand);
}
fprintf(fp3,"%d\t%s\t%s\t%s\n",locctr,label,opcode,operand);
fcloseall();
printf("\n\nThe contents of Input Table :\n\n");
fp1=fopen("INPUT.DAT","r");
ch=fgetc(fp1);
while(ch!=EOF)
{
printf("%c",ch);
ch=fgetc(fp1);
}
printf("\n\nThe contents of Output Table :\n\n\t");
fp3=fopen("OUT.DAT","r");
ch=fgetc(fp3);
while(ch!=EOF)
{
printf("%c",ch);
ch=fgetc(fp3);
}
len=locctr-start;
printf("\nThe length of the program is %d.\n\n",len);
printf("\n\nThe contents of Symbol Table :\n\n");
fp2=fopen("SYMTAB.DAT","r");
ch=fgetc(fp2);
while(ch!=EOF)
{
printf("%c",ch);
ch=fgetc(fp2);
}
fcloseall();
getch();
}
OUTPUT :-
Write a program To Study the algorithm and development of Pass 1 of Assembler

Q.Write a program To Study the algorithm and development of Pass 2 of Assembler.
Solution 
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char a[10],ad[10],label[10],opcode[10],operand[10],symbol[10],ch;    
Int st,diff,i,address,add,len,actual_len,finaddr,prevaddr,j=0;
char mnemonic[15][15]={"LDA","STA","LDCH","STCH"};
char code[15][15]={"33","44","53","57"};
FILE*fp1,*fp2,*fp3,*fp4;
clrscr();
fp1=fopen("ASSMLIST.DAT","w");
fp2=fopen("SYMTAB.DAT","r");
fp3=fopen("INTERMED.DAT","r");
fp4=fopen("OBJCODE.DAT","w");
fscanf(fp3,"%s%s%s",label,opcode,operand);
while(strcmp(opcode,"END")!=0)
{
prevaddr=address;
fscanf(fp3,"%d%s%s%s",&address,label,opcode,operand);
} finaddr=address;
fclose(fp3);
fp3=fopen("INTERMED.DAT","r");
fscanf(fp3,"%s%s%s",label,opcode,operand);
if(strcmp(opcode,"START")==0)
{
fprintf(fp1,"\t%s\t%s\t%s\n",label,opcode,operand);
fprintf(fp4,"H^%s^00%s^00%d\n",label,operand,finaddr);
fscanf(fp3,"%d%s%s%s",&address,label,opcode,operand);
st=address;
diff=prevaddr-st;
fprintf(fp4,"T^00%d^%d",address,diff); }
while(strcmp(opcode,"END")!=0)
{
if(strcmp(opcode,"BYTE")==0)
{
fprintf(fp1,"%d\t%s\t%s\t%s\t",address,label,opcode,operand);
len=strlen(operand);
actuallen=len-3;
fprintf(fp4,"^");
for(i=2;i<(actual_len+2);i++)
{
itoa(operand[i],ad,16);
fprintf(fp1,"%s",ad);
fprintf(fp4,"%s",ad);
}
fprintf(fp1,"\n");
}
elseif(strcmp(opcode,"WORD")==0)
{
len=strlen(operand);
itoa(atoi(operand),a,10);
fprintf(fp1,"%d\t%s\t%s\t%s\t00000%s\n",address,label,opcode,operand,a);
fprintf(fp4,"^00000%s",a);
}
elseif((strcmp(opcode,"RESB")==0)||(strcmp(opcode,"RESW")==0))
fprintf(fp1,"%d\t%s\t%s\t%s\n",address,label,opcode,operand);
else
{
while(strcmp(opcode,mnemonic[j])!=0)
j++;
if(strcmp(operand,"COPY")==0)
fprintf(fp1,"%d\t%s\t%s\t%s\t%s0000\n",address,label,opcode,operand,code[j]);
else
{
rewind(fp2);
fscanf(fp2,"%s%d",symbol,&add);
while(strcmp(operand,symbol)!=0)
fscanf(fp2,"%s%d",symbol,&add);
fprintf(fp1,"%d\t%s\t%s\t%s\t%s%d\n",address,label,opcode,operand,code[j],add);
fprintf(fp4,"^%s%d",code[j],add);
}
}
fscanf(fp3,"%d%s%s%s",&address,label,opcode,operand);
}
fprintf(fp1,"%d\t%s\t%s\t%s\n",address,label,opcode,operand);
fprintf(fp4,"\nE^00%d",st);
printf("\n Intermediate file is converted into object code");
fcloseall();
printf("\n\nThe contents of Intermediate file:\n\n\t");
fp3=fopen("INTERMED.DAT","r");
ch=fgetc(fp3);
while(ch!=EOF)
{
printf("%c",ch);
ch=fgetc(fp3);
}
printf("\n\nThe contents of Symbol Table :\n\n");
fp2=fopen("SYMTAB.DAT","r");
ch=fgetc(fp2);
while(ch!=EOF)
{
printf("%c",ch);
ch=fgetc(fp2);
}
printf("\n\nThe contents of Output file :\n\n");
fp1=fopen("ASSMLIST.DAT","r");
ch=fgetc(fp1);
while(ch!=EOF)
{
printf("%c",ch);
ch=fgetc(fp1);
}
printf("\n\nThe contents of Object code file :\n\n");
fp4=fopen("OBJCODE.DAT","r");
ch=fgetc(fp4);
while(ch!=EOF)
{
printf("%c",ch);
ch=fgetc(fp4);
}
fcloseall();
getch();
}
Output :-
program To Study the algorithm and development of Pass 2 of Assembler.


Note :- * If these programs are not working please let us know our team will try to solve your problems.Please don't panic and consult your teacher first. Your comments are valuable to us. 



|system programming|computer systems programming| in system programming|c system programming| c | systems programming language| systems program |systems programs|

No comments:

Post a Comment

Your comment is waiting for approval please wait and be patient.