document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. /*
  2. -----------------------------------------------------------------------------------------
  3.  ASSIGNMENT NO : 4
  4.  Title : Write an ALP/Inline Code for displaying file contents
  5.      using root directory and FAT for Floppy Disk.
  6. -----------------------------------------------------------------------------------------
  7. */
  8.  
  9. #include<stdio.h>
  10. #include<conio.h>
  11.  
  12. void main()
  13. {
  14.     char name[20],fname[8],ext[3];
  15.     char buff[513]="\\0";
  16.     char root[512*14],fat[512*9];
  17.     int i,j,k;
  18.     int flag=0;
  19.     unsigned int clust,sector;
  20.     int quo,rem;
  21.  
  22.     clrscr();
  23.  
  24.     for(i=0;i<8;i++)
  25.     {
  26.         fname[i]=\' \';
  27.     }
  28.     for(i=0;i<3;i++)
  29.     {
  30.         ext[i]=\' \';
  31.     }
  32.     printf("\\n\\nEnter the file name .:  ");
  33.     gets(name);
  34.  
  35.     k=strlen(name);
  36.  
  37.     for(i=0;i<k;i++)
  38.     {
  39.         if(name[i]==\'.\')
  40.         break;
  41.         fname[i]=toupper(name[i]);
  42.     }
  43.     i++;
  44.     for(j=0;i<k;i++,j++)
  45.     {
  46.         ext[j]=toupper(name[i]);
  47.     }
  48.     _asm{
  49.         mov al,0                // total 14 file allocation , Root = 512*14
  50.         mov cx,14
  51.         mov dx,19
  52.         lea bx,root
  53.         int 25h
  54.         popf
  55.     }                           // root directory is copied in root
  56.     k=0;
  57.     for(i=0,j=0;i<224;i++)
  58.     {
  59.         if(strncmp(fname,root+k,8)==0)
  60.         {
  61.             if(strncmp(ext,root+k+8,3)==0)
  62.             {
  63.                 flag=1;
  64.                 k=k+26;         // the files contents are stored at 26th position in the cluster
  65.                 _asm{
  66.                     lea si,root     // starting address of root directory
  67.                     add si,k        // address of the strating cluster
  68.                     mov al,[si]
  69.                     inc si
  70.                     mov ah,[si]
  71.                     mov clust,ax    // 16 bit address is stored in cluster
  72.                 }
  73.                 break;
  74.             }
  75.         }
  76.         else
  77.         {
  78.             k=k+32;             // the files info. stored is of 32 bits
  79.         }
  80.     }
  81.     if(flag==0)
  82.     {
  83.         printf("\\n\\tfile is not present:");
  84.         getch();
  85.         exit(0);
  86.     }
  87.     else
  88.     {
  89.         printf("\\n\\nContent of files are .: ");
  90.         _asm{
  91.             mov al,0
  92.             mov cx,9
  93.             mov dx,1
  94.             lea bx,fat
  95.             int 25h
  96.             popf
  97.         }
  98.         while(1)
  99.         {
  100.             printf("\\n\\nStarting cluster is .: %d",clust);
  101.             sector=clust+31;
  102.             printf("\\n\\nStarting sector is .: %d",sector);
  103.             getch();
  104.             _asm{
  105.                 mov al,0
  106.                 mov cx,1
  107.                 mov dx,sector
  108.                 lea bx,buff
  109.                 int 25h
  110.                 popf
  111.             }
  112.             printf("\\n%s",buff);
  113.             getch();
  114.             clust=clust*3;
  115.             quo=clust/2;
  116.             rem=clust%2;
  117.             _asm{
  118.                 lea si,fat
  119.                 add si,quo
  120.                 mov al,[si]
  121.                 inc si
  122.                 mov ah,[si]
  123.                 mov clust,ax
  124.  
  125.             }
  126.             if(rem==0)
  127.             {
  128.                 clust=clust & 0x0fff;
  129.                 if(clust==0x0fff)break;
  130.  
  131.             }
  132.             else if(rem==1)
  133.             {
  134.                 clust=clust>>4;
  135.                 if(clust==0x0fff)break;
  136.             }
  137.         }
  138.     }
  139.     getch();
  140. }
  141.  
  142. /*
  143. -----------------------------------------------------------------
  144.  END OF THE PROGRAM
  145. -----------------------------------------------------------------
  146. */
');