Assume that a system has a 32-bit virtual address with a 4-KB page size. Write a
ID: 3694723 • 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 decimal) 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<stdio.h>
#include<conio.h>
#include<math.h>
int main(int argc,char *argv[])
{
long int n;
int a;
float b;
clrscr();
sscanf(argv[1],"%ld",&n);
a=n/4096;
b=n%4096;
printf("Offset:::%f ",b);
printf("Number of Blocks::%d",a);
getch();
return 1;
}