#include<iostream>
#include<iomanip>
#include<cstring>
using namespace std;
const int X=7;
const int Y=12;
int p[4]={0,1,2,3};
int L;
char c, q, y;
struct pagetable
{
int pagenum1; //表示页号
int symbol; //表示标志
int blocknum; //表示主存块号
int symbol1; //表示修改标志
int postion; //表示在磁盘中的位置
};
struct sequence
{
char operation; //表示操作
int pagenum2; //表示页号
int unitnum; //表示单元号
};
class PCB
{
private:
pagetable pagenum1[X];
sequence operation[Y];
public:
void deposit1(); //页表的相关信息
void deposit2(); //指令的相关信
void FIFO(); //判断操作
};
void PCB::deposit1()
{
int i=0;
cout<<"输入页表的相关信息:"<<'\n';
for(i=0;i<X;i++)
{
cin>>pagenum1[i].pagenum1>>pagenum1[i].symbol>>pagenum1[i].blocknum>>pagenum1[i].symbol1
>>pagenum1[i].postion;
}
if(i>=X)
cout<<"*********************************************************"<<endl;
}
void PCB::deposit2()
{
int j=0;
cout<<"请输入指令序列的相关信息:"<<endl;
for(j=0;j<Y;j++)
{
cin>>operation[j].operation>>operation[j].pagenum2>>operation[j].unitnum;
}
if(j>=Y)
cout<<"**********************************************************"<<endl;
}
void PCB::FIFO()
{
int k=0;
int j;
int p[4]={0,1,2,3};
int specificaddress;
for(int i=0;i<Y;i++)
{
L=operation[i].pagenum2;
if(pagenum1[operation[i].pagenum2].symbol==1)
{
specificaddress=specificaddress=pagenum1[operation[i].pagenum2].blocknum*128+operation[i].unitnum;
if(operation[i].operation=='c')
{
pagenum1[L].symbol1=1;
cout<<"该指令的绝对地址是"<<specificaddress<<endl;
}
if(operation[i].operation!='c')
{
cout<<"该指令的绝对地址是"<<specificaddress<<endl;
}
}
if(pagenum1[operation[i].pagenum2].symbol==0)
{
cout<<"页"<<L<<"发生缺页中断"<<endl;
{
j=p[k]; //数组元素赋值给j
if(pagenum1[j].symbol1==1)
{
cout<<"调出页:"<<j<<endl;
cout<<"调入第"<<L<<"页"<<endl;
if(operation[i].operation=='c')
{
pagenum1[L].symbol1=1;
}
pagenum1[L].blocknum=pagenum1[j].blocknum;
pagenum1[j].symbol=0;
pagenum1[L].symbol=1;
p[k]=L;
specificaddress=specificaddress=pagenum1[operation[i].pagenum2].blocknum*128+operation[i].unitnum;
cout<<"该指令的绝对地址是"<<specificaddress<<endl;
}
if(pagenum1[j].symbol1==0)
{
cout<<"调入第"<<L<<"页覆盖第"<<j<<"页"<<endl;
if(operation[i].operation=='c')
{
pagenum1[L].symbol1=1;
}
pagenum1[L].blocknum=pagenum1[j].blocknum;
pagenum1[j].symbol=0;
pagenum1[L].symbol=1;
p[k]=L;
specificaddress=specificaddress=pagenum1[operation[i].pagenum2].blocknum*128+operation[i].unitnum;
cout<<"该指令的绝对地址是"<<specificaddress<<endl;
}
k=(k+1)%4;
}
}
}
}
void main()
{
cout<<"请输入页表和指令的相关信息"<<endl;
cout<<"C表示操作存"<<'\t'<<"q表示操作取"<<'\t'<<"y表示操作移位"<<endl;
PCB memory;
memory.deposit1();
memory.deposit2();
memory.FIFO();
}