Tuesday, 18 March 2014

c program for implement paging technique

#include<stdio.h>
int  main()
{
    int lmem,psize,pmem,i,j,k,c[10],str,pno,off;
    int a[20],b[35],ch,page,index,abs,frame;
    printf("\n enter page size::");
    scanf("%d",&psize);
    printf("\nenter logical memory size::");
    scanf("%d",&lmem);
    printf("\n%d",lmem);
    printf("\n enter data::");
    for(i=0;i<lmem;i++)
        scanf("%d",&a[i]);
    for(i=0;i<32;i++)
        b[i]=-1;
    for(i=0;i<lmem/psize;i++)
    {
        printf("\nenter starting location for page::%d",i);
        scanf("%d",&str);
        if(str%4==0)
        {
            c[i]=str/4;
            for(j=str,k=i*4;j<j+psize,k<i*4+psize;j++,k++)
            {
            b[j]=a[k];
            }
        }
        else
                {
                 printf("\n wrong entry for page the page address shud
be multiples of 4");
                }
        }
    printf("\n the page table is::");
    printf("\n page \t\t frame");
    for(i=0;i<lmem/psize;i++)
        printf("\n %d\t %d",i,c[i]);
    printf("enter the pageno and offset\n");
    scanf("%d%d",&pno,&off);
    abs=c[pno]*4+off;
    printf("\n the physical address %d is::%d",b[abs],abs);
    return 0;
}

No comments:

Post a Comment