《模拟分页式虚拟存储管理中硬件的地址转换和缺页中断选择页面调度算法处理缺页中断》由会员分享,可在线阅读,更多相关《模拟分页式虚拟存储管理中硬件的地址转换和缺页中断选择页面调度算法处理缺页中断(12页珍藏版)》请在金锄头文库上搜索。
1、操作系统实验二(第一题)一. 实验内容模拟分页式虔拟存储管理中硬件的地址转换和缺页中断,以及选择页面调度算法处理缺页中断。二. 实验目的在计算机系统总,为了提高主存利用率,往往把辅助存储器作为主存储器的扩充,使多道运行的作业的全部逻辑地址空间综合可以超出主存的绝对地址空间。用这种办法扩充的主存储区成为虚拟存储器。三. 实验题目模拟分页式存储管理中硕件的地址转换和产生缺页中断。四. 程序清单/操作实验二.cpp:定义控制台应用程序的入I】点。/#includeHstdafx.hn# mclude# iiiclude# mcludeusingnamespacestd;classinsprivate
2、:stimgope;longiiitpage;longiiitunit;public:ms()ins(striiigojongiiitpjongmtu):ope(o).page(p)Aimt(u)voidsetope(stringo)ope=o;voidsetpage(longintp)page=p;voidsetunit(longiiitu)unit=u;stiiiiggetope()returnope;longmtgetpageQreturnpage;longmtgetunit()returnunit;classworkprivate:longintPage;iiitsym;longint
3、inum;longintonum;public:work()work(longintP,intsjongmtijongmto):Page(P),sym(s).muni(i),onum(o)voidsetPage(longiiitP)Page=P;voidsetsym(iiits)svm=s;voidsetiiium(longinti)mum=i;voidsetonum(longinto)onum=o;longmtgetPageQreturnPage;intgetsym()returnsym;longmtgetmum()returninum;longmtgetonum()returnonum;v
4、oiddiaodu(work*w,ins*i.iiitnumofins)fbr(intj=0jnumofiiisJ+)longmttempofk;longmta=ij.getpageQ;for(mtk=0;k7;k+)7是页表的页数if(wk.getPageO!=a)continue;elsetempofk=k;break;if(wtempofk.getsym()=1)coutH绝对地址:w忙mpofkgeiii】m()*128+ijgE】iHt()”磁盘地址为:,rwtempofk.getonum()H操作为:ni|j.getope()endl;elsecout,*HM发生缺页中断Hendl
5、;mtmam()ins*INS=newiiis12;INS0.setopeINS0.setpage(0);INS0.setumt(70);INSl.setopeINSl.setpage(l);INSl.setumt(50);INS2.setope(nXH);INS2.setpage(2);INS2.setumt(15);INS3.setope(”存”);INS3.setpage(3);INS3.setumt(21);INS4.setope(”取”);INS4.setpage(0);INS4.setmiit(56);INS5.setope();INS5.setpage(6);INS5.setum
6、t(40);INS6.setope(“移位”);INS6.setpage(4);INS6.setmiit(53);INS7.setope(”+”);INS7.setpage(5);INS7.setumt(23);INS8.setope(”存”);INS8.setpage(l);INS8.setumt(37);INS9.setope(”取”);INS刃.setpage(2);INS9.setumt(78);INS10.setope(”+”);INS10.setpage(4);INS10.setunit(l);INSll.setope(”存”);INSll.setpage(6);INS11.set
7、miit(84);work*W=newwork7;ifstreamm(Hg:/operatellongiiitp;ints;longmti;longinto;for(intjj=0;jj32cd.exe:存:取磁盘地址为:11磁盘地址为:12磁盘地址为:13磁盘地址为:21磁盘地址为:11w:100741674996断断断061230断鬆7111&操作系统实验二(第二题)一.用先进先出(FIFO)九.程序清单/操作系统实验二.cpp:定义控制台应用程序的入II点。/#includeHstdafx.hn# iiiclude# mclude# iiicludeusingnamespacestd;c
8、lassinsprivate:stiiiigope;longmtpage;longiiitunit;public:ms()ins(striiigojongmtpjongmtu):ope(o).page(p)jmit(u)voidsetope(stringo)ope=o;voidsetpage(longintp)page=p;voidsetunit(longmtu)unit=u;stimggetope()returnope;longmtgetpageQreturnpage;longmtgetumt()returnunit;classworkprivate:longintPage;iiitsym;
9、longintinum;intchange;longintonum;public:work()work(longiiitRiiitsjongo):Page(P),sym(s).mum(i),chaiige(c).onum(o)voidsetPage(longiiitP)Page=P;voidsetsym(iiits)svm=s;mteJongintvoidsetmum(longinti)mum=i;voidsetchange(intc)change=c;voidsetonum(longinto)onum=o;longmtgetPageQreturnPage;intgetsym()returns
10、ym;longmtgetmum()returninum;mtgetchangeQreturnchange;longmtgetonum()ieturnonum;;voiddiaodu(work*w,ins*i.iiitnumofins)constintm=4;intpm=0,1,2,3;mtk=0;inttempofiiis=12;fbr(intu=0;iitempofins;ii+)mtL=ih.getpage();iii=0;iii7;iii+)if(wm.getPage()!=L)continue;elseif(wiii.getsym()=1)if(iii.getope()=”存)wiii
11、.setchange(1);coutn绝对地址谓:yvwiHgetimim()*128+iiigW】mt()w”wiug亡,ih.getunit()endl;elsecoutH产生中断Hu*nendl;mtj=pk;wj.setsym(0);wj.setmum(-l);wL.setsym(l);wL.setmum(iandQ%20+10);if(wj.getchange0=1)cout第Hj页需要重新写入磁盘中第HLn页被调入主存Hendl;pk=L;k=(k=mJ)P(k+l);coutvv”调入主存的页fbr(intiiii=O;iiiim;iui+)mtkk=piiii;coutwkk.
12、getPage()Hendl;coutendl,mtmam()ins*INS=newiiis12;INS0.setope(H+M);INSO.setpage(O);INS0.setunit(70);INSl.setope(H+M);INSl.setpage(l);INS1.setunit(5O);EIS2.setope(nXM);INS2.setpage(2);INS2.setunit(15);INS3.setope(”存”);INS3.setpage(3);INS3.setunit(21);INS4.setope(”取”);INS4.setpage(0);INS4.setunit(56);INS5.setope();INS5.setpage(6);INS5.setunit(40);INS6.setope(”移位”);INS6.setpage(4);INS6.setunit(53);INS7.setope(”+”);INS7.setpage(5);INS7.setunit(23);INS8.setope(”存”);INS8.setpage(l);INS8.setunit(37);INS9.setope(”取”);INS9.setpage(2);INS