-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsegment.cpp
55 lines (43 loc) · 1.2 KB
/
segment.cpp
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<iostream>
#include<string>
using namespace std;
const int Max = 100;
struct segment{
int segmentno;
int segmentsize;
string content[Max];
};
struct segmenttable{
segment seg;
int baseaddress;
};
int main(){
segmenttable st[Max];
int noofsegments,size;
string physicalmemory[Max];
int addindex = 0;
cout<<"\nenter the no of segments : ";
cin>>noofsegments;
for(int i =0;i<noofsegments;i++){
st[i].seg.segmentno = i;
st[i].baseaddress = addindex;
cout<<"\nenter "<<i<<"'s segment content size:";
cin>>size;
st[i].seg.segmentsize = size;
cout<<"\nenter "<<i<<"'s segment content(s):";
for(int j =0;j<size;j++){
cin>>st[i].seg.content[j];
}
addindex += size;
}
for(int i = 0 ; i < noofsegments ; i++){
for(int j = 0 ; j < st[i].seg.segmentsize ; j++){
physicalmemory[st[i].baseaddress + j] = st[i].seg.content[j];
}
}
cout<<"\n physical memory : \n";
for(int i = 0 ; i < addindex;i++){
cout<<"index "<<i<<" : "<<physicalmemory[i]<<"\n";
}
return 0;
}