1 / 6
文档名称:

NUR面置换算法.pdf

格式:pdf   大小:383KB   页数:6页
下载后只包含 1 个 PDF 格式的文档,没有任何的图纸或源代码,查看文件列表

如果您已付费下载过本站文档,您可以点这里二次下载

分享

预览

NUR面置换算法.pdf

上传人:1781111**** 2024/4/14 文件大小:383 KB

下载得到文件列表

NUR面置换算法.pdf

相关文档

文档介绍

文档介绍:该【NUR面置换算法 】是由【1781111****】上传分享,文档一共【6】页,该文档可以免费在线阅读,需要了解更多关于【NUR面置换算法 】的内容,可以使用淘豆网的站内搜索功能,选择自己适合的文档,以下文字是截取该文章内的部分文字,如需要获得完整电子版,请下载此文档到您的设备,方便您编辑和打印。:..RU页面置换算法1)假设每个页面中可存放10条指令,分配给作业(de))用C语言模拟一个作业(de)执行过程,该作业共有320条指令,即它(de)地址空间为32页,目前它(de),如果所访问(de)指令已在内存,则显示其物理地址,(de)指令还未装入内存,则发生缺页,此时需记录缺页(de)次数,,则需进行页面置换,最后显示其物理地址,,请计算并显示作业运行过程中发生(de))置换算法:最近最不经常使用(NRU)<>include<>include<>defineN4definesize320typedefstructPage{intpage_num;intflag_A;//访问位intflag_M;//修改位intread_or_write;//0表示不被修改,1表示被修改}PAGE;typedefstructBlock{intblock_num;//块号PAGEpage;//所装页(de)信息structBlocknext;}BLOCK,BLOCKLIST;typedefstructinstruct{//指令数据结构intaddress;//指令地址PAGEpage;//对应页(de)信息}INSTRUCTION,INSTRUCTIONLIST;INSTRUCTIONinstructions[size];//定义320个指令BLOCKLISTblock_head;//块(de)头指针intdiseffect=0;//缺页次数intblockSize=0;voidInit_Instructions(){:..for(inti=0;i<320;i++)instructions[i].address=rand()%320;for(intk=0;k<320;k++){instructions[k].=(int)instructions[k].address/10;instructions[k].=0;instructions[k].=rand()%2;if(instructions[k].==0)instructions[k].=0;elseinstructions[k].=1;}}BLOCKLISTInit_block(){BLOCKLISThead=(BLOCKLIST)malloc(sizeof(BLOCK));BLOCKLISTp;for(inti=1;i<=N;i++){if(i==1)p=head;else{p->next=(BLOCKLIST)malloc(sizeof(BLOCK));p=p->next;}p->block_num=i;p->=-1;p->=0;p->=0;}p->next=head;returnhead;}voiddisplay(INSTRUCTIONinstructions){BLOCKLISTp=block_head;do{:..>,p->,p->);p=p->next;}while(p=block_head);}voidshow_physical_address(BLOCKLIST&p,INSTRUCTIONinstructions){intaddress;address=p->block_num1024+%10;//页面大小为1k}//查找四个块中是否有此页面intFind_page_in_block(INSTRUCTIONinstructions,BLOCKLIST&p){p=block_head;do{p->=1;if(p->==0)return1;}p=p->next;}while(p=block_head);return0;}//先将四个块中装满voidloadpage(PAGEpage){BLOCKLISTp;p=block_head;while(p->=-1)p=p->next;p->=;p->=1;p->=;blockSize++;}:..第一次循环扫描A=0M=0intcscanf1(BLOCKLIST&p){p=block_head;do{if(p->==0&&p->==0)return1;p=p->next;}while(p=block_head);return0;}//第二次循环扫描A=0M=1intcscanf2(BLOCKLIST&p){p=block_head;do{//把扫面过后(de)A=1,M=0或A=1,M=1中(de)A置0if(p->==1&&(p->==0||p->==1)){p->=0;p=p->next;continue;}if(p->==0&&p->==1)return1;p=p->next;}while(p=block_head);return0;}//第三次扫描将所有(de)A置为0intcscanf3(BLOCKLIST&p){p=block_head;do{p->=0;p=p->next;}while(p=block_head);return1;}:..用于换进页面voidassignment(BLOCKLIST&p,INSTRUCTIONinstructions){p->=1;}//NRU页面替换算法voidreplace_page(INSTRUCTIONinstructions,BLOCKLIST&p){if(cscanf1(p)){assignment(p,instructions);}elseif(cscanf2(p)){assignment(p,instructions);}elseif(cscanf3(p)){if(cscanf1(p))assignment(p,instructions);else{cscanf2(p);assignment(p,instructions);}}}voidmain(){BLOCKLISTp;Init_Instructions();block_head=Init_block();for(inti=0;i<size;i++){if(Find_page_in_block(instructions[i],p)){display(instructions[i]);show_physical_address(p,instructions[i]);getchar();continue;}elseif(blockSize<N){diseffect++;loadpage(instructions[i].page);:..}else{diseffect++;replace_page(instructions[i],p);}display(instructions[i]);if(diseffect>4)show_physical_address(p,instructions[i]);getchar();}getchar();getchar();getchar();}