Monday, April 12, 2010

List of new SP experiments


These 4 new S.P LAB experiments have to be done along with the previous 6 experiments
and PLEASE DON'T WRITE the experiment numbers yet..!!
Q1. Program to implement PASS 1 of ASSEMBLER. 
  • Program to make MACHINE OPCODE TABLE & PSUEDO OPCODE TABLE.
  #include
#include
#include
void main()
  {
     clrscr();
     struct mot
      {
         char mnemonic[15];
         int length;
      };
     char another;
     struct mot m;
     FILE *a;
     a=fopen("aman.dat","a");
     do
      {
         printf("entr mnemonic:");
         scanf("%s",m.mnemonic);
         printf("entr length:");
         scanf("%d",&m.length);
         fwrite(&m,sizeof(m),1,a);
         printf("enter another(y/n):");
         another=getche();
      }while(another=='y');
     fclose(a);
     struct pot
      {
         int memory;
         char pop[15];
      };
     struct pot p;


  FILE *d;
  char more;
  d=fopen("aman1.dat","a");
  do
      {
         printf("\nenter psuedoopcode:");
         scanf("%s",&p.pop);
         printf("entr memory length:");
         scanf(" %d",&p.memory);
         fwrite(&p,sizeof(p),1,d);
         printf("enter more(y/n):");
         scanf("%s",&more);
      } while(more=='y');
     fclose(d);
  }





















 

 
  • Q.2 Program to make SYMBOL TABLE.
  #include
#include
#include
void main()
{
   clrscr();
   struct st
      {
          char  symbol[15];
          int value;
          int length;
      };
   struct st s;
   char another='y';
   FILE *a;
   a=fopen("bih15.cpp","w");
   struct lt l;
   while(another=='y')
      {
          printf("enter symbol");
          scanf("%s",&s.symbol);
          printf("enter value");
          scanf("%s",&s.value);
          getch();
          printf("entr length");
          scanf("%d,",&s.length);
          fwrite(&s,sizeof(s),1,a);
          printf("enter more");
          scanf("%s",&another);
      }
   fclose(a);
}

 
Q3. Program to copy contents of one file into another file.
#include
#include
#include
void main()
   {
     FILE *fp,*fs;
     char ch;
     clrscr();
     fp=fopen("fc.cpp","r");
     if(fp==NULL)
       {
          printf("cannot open source file");
          exit(1);
       }
     fs=fopen("fc1.cpp","w");
     if(fs==NULL)
       {
          printf("cannot open target file");
          fclose(fp);
          exit(1);
       }
     while(1)
       {
          ch=fgetc(fp);
          if(ch==EOF)
             {
             break;
             }
          else
             {
             fputc(ch,fs);
             }
       }
     fclose(fp);
     fclose(fs);
OUTPUT of  Program to copy contents of one file into another file.

Copied file is: -

#include

void main()

{

  printf("file copy");

}
















 
Q4. Program to enter record of student using files. 
#include
#include
#include
struct aman
   {
      char n[10];
      int roll;
   };
void main()
  {
      clrscr();
      FILE *z;
      aman a;
      z=fopen("A1.c","w");
      if(z==NULL)
         {
           printf("cannot open");
           exit(0);
         }
      printf("enter record of students");
      char more='y';
      while(more=='y')
         {
           printf("\nenter name & enter roll 
          no”);
           scanf("%s%s",&a.n,&a.roll);
           fwrite(&a,sizeof(a),1,z);
           printf("any more records y/n");
           scanf("%s",&more);
         }
      fclose(z);
      z=fopen("bih8.cpp","r");
      fread(&a,sizeof(a),1,z);
      printf("name %s \nroll no %d",a.n,a.roll);
  }
 

  OUTPUT of program entering record of student using files
enter record of students
enter name & roll no
aman
104
any more records y/n n
name aman
roll no 104




 

Leave a Reply