//****///////////////////////////////////////////////////////// //* Main file //* 页式地址变换机构模拟 //* 青小楼 //* 2009-11-19 ///////////////////////////////////////////////////////////// #include "cHead.h" #include <iostream> int main() { int Mypf[P_COUNT]={5,9,10,7,-1,-1,-1,-1}; int AccessArray[7]={3296,2268,1366,1537,9879,6532,7769}; cPageTable MyPT(Mypf); for(int i=0;i<7;i++) { int temp=MyPT.AddrTran(AccessArray[i]); if(SLOPOVER==temp)std::cout<<"越界"<<" "; else if(MISSINGPAGE==temp)std::cout<<"缺页"<<" "; else std::cout<<temp<<" "; } return 0; } //****///////////////////////////////////////////////////////// //* class headfile //* 页式地址变换机构模拟 //* 青小楼 //* 2009-11-19 ///////////////////////////////////////////////////////////// #ifndef CHEAD_H_ #define CHEAD_H_ #define SLOPOVER -1 #define MISSINGPAGE 0 const short int P_COUNT=8; class cPageTable { private: int MyPageframeNum[P_COUNT]; //页面号 bool ioStatus[P_COUNT]; //内外状态 public: int AddrTran(int _inAdd);//return value:address slopover missingpage ~cPageTable(); cPageTable(); cPageTable(int*pf); }; #endif //****///////////////////////////////////////////////////////// //* class file //* 页式地址变换机构模拟 //* 青小楼 //* 2009-11-19 ///////////////////////////////////////////////////////////// #include "cHead.h" cPageTable::cPageTable(){} cPageTable::~cPageTable(){} cPageTable::cPageTable(int*pf) { for(int i=0;i<P_COUNT;++i) { MyPageframeNum[i]=pf[i]; if(-1==pf[i]) ioStatus[i]=false; else ioStatus[i]=true; } } int cPageTable::AddrTran(int _inAddr) { int tempPNum=_inAddr>>10; //取得页号 if(0 > tempPNum || tempPNum > 7) return SLOPOVER; //越界 if(!ioStatus[tempPNum]) return MISSINGPAGE; //缺页 int tempAddr=_inAddr&1023; return MyPageframeNum[tempPNum]*1024+tempAddr; }