You are on page 1of 2

Ex.

No:9 PAGING TECHNIC OF MEMORY MANAGEMENT

#include<stdio.h>
#define MAX 50
int main()
{
int page[MAX],i,n,f,ps,off,pno;
clrscr();
printf("\nEnter the no of pages in memory");
scanf("%d",&n);
printf("\nEnter page size");
scanf("%d",&ps);
printf("\nEnter no of frames");
scanf("%d",&f);
for(i=0;i<n;i++)
page[i]=-1;
printf("\nEnter the page table\n");
printf("(Enter frame no as -1 if that page is not present in any frame)\n\n");
printf("\npageno\tframeno\n-------\t-------");
for(i=0;i<n;i++)
{
printf("\n\n%d\t\t",i);
scanf("%d",&page[i]);
}
printf("\n\nEnter the logical address(i.e,page no & offset):");
scanf("%d%d",&pno,&off);
if(page[pno]==-1)
printf("\n\nThe required page is not available in any of frames");
else
printf("\n\nPhysical address(i.e,frame no & offset):%d,%d",page[pno],off);
getch();
return 1;
}

(OR)

#include<stdio.h>
#include<conio.h>
#include<math.h>
main()
{
int size,m,n,pgno,pagetable[3]={5,6,7},i,j,frameno;
double m1;
int ra=0,ofs;
clrscr();
printf(“Enter process size (in KB of max 12KB):”);/*reading memeory size*/
scanf(“%d”,&size);
m1=size/4;
n=ceil(m1);
printf(“Total No. of pages: %d”,n);
printf(“\nEnter relative address (in hexadecimal notation eg.0XRA) \n”);
//printf(“The length of relative Address is : 16 bits \n\n The size of offset is :12 bits\n”);
scanf(“%d”,&ra);
pgno=ra/1000; /*calculating physical address*/
ofs=ra%1000;
printf(“page no=%d\n”,pgno);
printf(“page table”);
for(i=0;i<n;i++)
printf(“\n %d [%d]”,i,pagetable[i]);
frameno=pagetable[pgno];
printf(“\n Equivalent physical address : %d%d”,frameno,ofs);
getch();
}

You might also like