-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathpaging.c
More file actions
30 lines (20 loc) · 832 Bytes
/
Copy pathpaging.c
File metadata and controls
30 lines (20 loc) · 832 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
/* Author : Teja Sasank Gorthi
Email : jet.sasank@gmail.com */
/*Problem : 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.*/
#include <stdio.h>
int main(int argc, char *argv[])
{
unsigned long page;
unsigned long offset;
unsigned long address;
address= atoll(argv[1]);
/* Page Number = quotient of address / 4KB and offset = remainder*/
/*Below is the faster method of calculating the same*/
page = address >> 12; /* Since page size is 4KB => 12 bits holding the virtual address*/
offset = address & 0xfff;
printf("The address %lu contains: \n", address);
printf("page number = %lu\n",page);
printf("offset = %lu\n", offset);
return 0;
}