forked from csc-mec/SS_LAB
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbasicpg.c
55 lines (47 loc) · 978 Bytes
/
basicpg.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
#include<stdio.h>
#include<stdlib.h>
#define page_size 4096 // page size is 4kb ---- not used practically in the code
#define memory_size 16384 // memory size is 16kb ---- not used practically in the code
#define pagenum 10
#define framenum 10
int pagetable[pagenum];
void initialize()
{
for(int i=0; i<pagenum; i++)
{
pagetable[i] = -1;
}
}
void loadpage(int pgnum, int frnum)
{
if(pgnum < pagenum)
{
pagetable[pgnum] = frnum;
}
else
{
printf("Page number out of bounds\n");
}
}
int printfr(int pgnum)
{
if(pagetable[pgnum] != -1)
{
return pagetable[pgnum];
}
else
return -1;
}
void main()
{
initialize();
loadpage(0,7);
loadpage(3,4);
for(int i=0; i<pagenum; i++)
{
if(printfr(i) != -1)
{
printf("The page %d has been assigned to frame %d\n",i,printfr(i));
}
}
}