您好,欢迎访问三七文档
当前位置:首页 > 行业资料 > 其它行业文档 > 模拟分页式虚拟存储管理中硬件的地址转换和缺页中断--选择页面调度算法处理缺页中断
操作系统实验二(第一题)一.实验内容模拟分页式虚拟存储管理中硬件的地址转换和缺页中断,以及选择页面调度算法处理缺页中断。二.实验目的在计算机系统总,为了提高主存利用率,往往把辅助存储器作为主存储器的扩充,使多道运行的作业的全部逻辑地址空间综合可以超出主存的绝对地址空间。用这种办法扩充的主存储区成为虚拟存储器。三.实验题目模拟分页式存储管理中硬件的地址转换和产生缺页中断。是否开始取一条指令取指令中访问的页号查页表该也标志=1?输出“*”页号表示发生缺页中断形成绝对地址输出绝对地址有后继指令?取下一条指令结束四.程序清单////操作实验二.cpp:定义控制台应用程序的入口点。//#includestdafx.h#includeiostream#includestring#includefstreamusingnamespacestd;classins{private:stringope;longintpage;longintunit;public:ins(){}ins(stringo,longintp,longintu):ope(o),page(p),unit(u){}voidsetope(stringo){ope=o;}voidsetpage(longintp){page=p;}voidsetunit(longintu){unit=u;}stringgetope(){returnope;}longintgetpage(){returnpage;}longintgetunit(){returnunit;}};classwork{private:longintPage;intsym;longintinum;longintonum;public:work(){}work(longintP,ints,longinti,longinto):Page(P),sym(s),inum(i),onum(o){}voidsetPage(longintP){Page=P;}voidsetsym(ints){sym=s;}voidsetinum(longinti){inum=i;}voidsetonum(longinto){onum=o;}longintgetPage(){returnPage;}intgetsym(){returnsym;}longintgetinum(){returninum;}longintgetonum(){returnonum;}};voiddiaodu(work*w,ins*i,intnumofins){for(intj=0;jnumofins;j++){longinttempofk;longinta=i[j].getpage();for(intk=0;k7;k++)//7是页表的页数if(w[k].getPage()!=a)continue;else{tempofk=k;break;}if(w[tempofk].getsym()==1)cout绝对地址:w[tempofk].getinum()*128+i[j].getunit()磁盘地址为:w[tempofk].getonum()操作为:i[j].getope()endl;elsecout*发生缺页中断endl;}}intmain(){ins*INS=newins[12];INS[0].setope(+);INS[0].setpage(0);INS[0].setunit(70);INS[1].setope(+);INS[1].setpage(1);INS[1].setunit(50);INS[2].setope(×);INS[2].setpage(2);INS[2].setunit(15);INS[3].setope(存);INS[3].setpage(3);INS[3].setunit(21);INS[4].setope(取);INS[4].setpage(0);INS[4].setunit(56);INS[5].setope(-);INS[5].setpage(6);INS[5].setunit(40);INS[6].setope(移位);INS[6].setpage(4);INS[6].setunit(53);INS[7].setope(+);INS[7].setpage(5);INS[7].setunit(23);INS[8].setope(存);INS[8].setpage(1);INS[8].setunit(37);INS[9].setope(取);INS[9].setpage(2);INS[9].setunit(78);INS[10].setope(+);INS[10].setpage(4);INS[10].setunit(1);INS[11].setope(存);INS[11].setpage(6);INS[11].setunit(84);work*W=newwork[7];ifstreamin(g://operate1.txt);longintp;ints;longinti;longinto;for(intjj=0;jj7;jj++){inp;ins;ini;ino;W[jj].setPage(p);W[jj].setsym(s);W[jj].setinum(i);W[jj].setonum(o);}diaodu(W,INS,12);}五.结果显示操作系统实验二(第二题)一.用先进先出(FIFO)是否是否否是是否开始取一条指令取指令中访问的页号--L查页表该页标志=1?形成绝对地址是存指令?置L页修改标志为“1”输出绝对地址有后继指令?取下一条指令结束j=p[k]J页修改标志为1?输出j,修改L页的标志及在内存中的地址,输出LP[k]=L,k=(k==m-1)?0:(k+1)修改页表九.程序清单/操作系统实验二.cpp:定义控制台应用程序的入口点。//#includestdafx.h#includeiostream#includestring#includefstreamusingnamespacestd;classins{private:stringope;longintpage;longintunit;public:ins(){}ins(stringo,longintp,longintu):ope(o),page(p),unit(u){}voidsetope(stringo){ope=o;}voidsetpage(longintp){page=p;}voidsetunit(longintu){unit=u;}stringgetope(){returnope;}longintgetpage(){returnpage;}longintgetunit(){returnunit;}};classwork{private:longintPage;intsym;longintinum;intchange;longintonum;public:work(){}work(longintP,ints,longinti,intc,longinto):Page(P),sym(s),inum(i),change(c),onum(o){}voidsetPage(longintP){Page=P;}voidsetsym(ints){sym=s;}voidsetinum(longinti){inum=i;}voidsetchange(intc){change=c;}voidsetonum(longinto){onum=o;}longintgetPage(){returnPage;}intgetsym(){returnsym;}longintgetinum(){returninum;}intgetchange(){returnchange;}longintgetonum(){returnonum;}};voiddiaodu(work*w,ins*i,intnumofins){constintm=4;intp[m]={0,1,2,3};intk=0;inttempofins=12;for(intii=0;iitempofins;ii++){intL=i[ii].getpage();for(intiii=0;iii7;iii++)if(w[iii].getPage()!=L)continue;elseif(w[iii].getsym()==1){if(i[ii].getope()==存)w[iii].setchange(1);cout绝对地址谓:w[iii].getinum()*128+i[ii].getunit()w[iii].getinum()i[ii].getunit()endl;}else{cout产生中断*endl;intj=p[k];w[j].setsym(0);w[j].setinum(-1);w[L].setsym(1);w[L].setinum(rand()%20+10);if(w[j].getchange()==1)cout第j页需要重新写入磁盘中第L页被调入主存endl;p[k]=L;k=(k==m-1)?0:(k+1);}cout调入主存的页:;for(intiiii=0;iiiim;iiii++){intkk=p[iiii];coutw[kk].getPage();}coutendl....................................................endl;}}intmain(){ins*INS=newins[12];INS[0].setope(+);INS[0].setpage(0);INS[0].setunit(70);INS[1].setope(+);INS[1].setpage(1);INS[1].setunit(50);INS[2].setope(×);INS[2].setpage(2);INS[2].setunit(15);INS[3].setope(存);INS[3].setpage(3);INS[3].setunit(21);INS[4].setope(取);INS[4].setpage(0);INS[4].setunit(56);INS[5].setope(-);INS[5].setpage(6);INS[5].setunit(40);INS[6].setope(移位);INS[6].setpage(4);INS[6].setunit(53);INS[7].setope(+);INS[7].setpage(5);INS[7].setunit(23);INS[8].setope(存);INS[8].setpage(1);INS[8].setunit(37);INS[9].setope(取);INS[9].setpage(2);INS[9].setunit(78);INS[10].setope(+);INS[10].setpage(4);INS[10].setunit(1);INS[11].setope(存);INS[11].setpage(6);INS[11].setunit(84);work*W=newwork[7];ifstreamin(g://operate.txt);longintp;ints;longinti;intc;longinto;for(intjj=0;jj7;jj++){inp;ins;ini;inc;ino;W[jj].setPage(p);W[jj].setsym(s);W[jj].setinum(i);W[jj].setchange(c);W[jj].setonum(o);}diaodu(W,INS,12);}十.程序结果
本文标题:模拟分页式虚拟存储管理中硬件的地址转换和缺页中断--选择页面调度算法处理缺页中断
链接地址:https://www.777doc.com/doc-5469410 .html