Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Assume that a system has a 32-bit virtual address with a 4-KB page size. Write a

ID: 3653383 • Letter: A

Question

Assume that a system has a 32-bit virtual address with a 4-KB page size. Write a C program that is passed a virtual address (in decincal) on the command line and have it output the page number and offset for the given address. As an example, your program would run as follows: ./a.out 19986 Your program would output: The address 19986 contains: page number = 4 offset = 3602 Writing this program will require using the appropriate data type to store 32 bits. We encourage you to use unsigned data types as well.

Explanation / Answer

#include
int main()
{
int lpage[10], pagetab[10], pframe[2][2], I,j;
int size, msize, cnt, t,k,pos,logadd,m=0;
int frameno;
long int l;
int i;
printf(" Enter the memory size:");
scanf("%d", &msize);
printf("Enter the pase size:");
scanf("%d", &size);
cnt=(msize/size);
printf(" Enter the logical page: ");
for(j=0;j
{
scanf("%d", &lpage[j]);
}
t=0;
k=0;
for(j=0;j
{
printf(" ");
if(t
{
printf("%d value is %d ", t,lpage[j]);
t++;
}
else
{
t=0;
printf("%d value is %d ", t,lpage[j]);
t++;
}
}
printf(" Enter the page table value: ");
for(i=0;i
{
scanf("%d", &pagetab[i]);
}
printf(" Enter the logical address: ");
scanf("%d", &logadd);
for(k=0;k
{
if(logadd==lpage[k])
{
pos=(k/size);
m=k%size;
break;
}
else
continue;
}
printf(" Page number : %d", pos);
frameno=pagetab[pos];
printf(" The frame number is %d ", frameno);
printf(" The corresponding physical address is %d", (frameno*size)+m);
}
SAMPLE OUTPUT:

[it65@AntiViruS ~]$ cc paging.c
[it65@AntiViruS ~]$ ./a.out
Enter the memory size:4
Enter the page size:2
Enter the logical page: 2
3
4
5
0 value is 2
1 value is 3
0 value is 4
1 value is 5
Enter the page table value: 101
102
Enter the logical address: 5
Page number : 1
The frame number is 102
The corresponding physical address is 205