-
Notifications
You must be signed in to change notification settings - Fork 0
/
Paging.c
63 lines (51 loc) · 1.48 KB
/
Paging.c
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include <stdio.h>
#include <conio.h>
int main()
{
int lmem, psize, pmem, i, j, k, c[10], str;
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("\nEnter physical memory size::");
scanf("%d", &pmem);
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 / psize;
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,\n 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\t %d", i, c[i]);
printf("\n Enter for which data the mapping address to be found::");
scanf("%d", &ch);
for (i = 0; i < lmem; i++)
{
if (ch == a[i])
{
index = i;
page = index / 4;
frame = c[page];
abs = (frame * psize) + (index % psize);
}
}
printf("\n The physical address for %d is::%d", ch, abs);
getch();
return 0;
}