實驗三、頁式地址重定位模擬
實驗三、頁式地址重定位模擬
一、實驗目的:
1、 用高級語言編寫和調試模擬實現頁式地址重定位。
2、 加深理解頁式地址重定位技術在多道程序設計中的作用和意義。
二、實驗原理:
當進程在CPU上運行時,如指令中涉及邏輯地址時,操作系統自動根據頁長得到頁號和頁內偏移,把頁內偏移拷貝到物理地址寄存器,再根據頁號,查頁表,得到該頁在內存中的塊號,把塊號左移頁長的位數,寫到物理地址寄存器。
三、實驗內容:
1、 設計頁表結構
2、 設計地址重定位算法
3、 有良好的人機對話界面
三、程序調試:
調試數據一:
系統頁號對應塊號情況(頁號——>塊號):
0--> 0 1-->42 2-->29 3-->15 4-->45 5-->31 6-->44 7-->43
8-->41 9-->28 10--> 1 11-->30 12-->12 13-->24 14--> 6 15-->32
16-->14 17-->27 18-->13 19-->46 20--> 7 21-->33 22-->10 23-->22
24-->40 25--> 2 26-->51 27-->11 28-->39 29-->23 30-->49 31-->50
32-->26 33-->16 34-->25 35--> 4 36-->47 37-->17 38--> 3 39-->48
40-->52 41-->36 42-->58 43-->35 44-->57 45-->34 46-->21 47-->63
48--> 5 49-->37 50-->18 51--> 8 52-->62 53-->56 54-->20 55-->54
56-->60 57-->19 58-->38 59--> 9 60-->61 61-->55 62-->59 63-->53
請輸入邏輯地址(十進制):
2500
對應的物理地址為(十進制):
30148
Press any key to continue
調試數據二:
系統頁號對應塊號情況(頁號——>塊號):
0--> 0 1-->42 2-->29 3-->15 4-->45 5-->31 6-->44 7-->43
8-->41 9-->28 10--> 1 11-->30 12-->12 13-->24 14--> 6 15-->32
16-->14 17-->27 18-->13 19-->46 20--> 7 21-->33 22-->10 23-->22
24-->40 25--> 2 26-->51 27-->11 28-->39 29-->23 30-->49 31-->50
32-->26 33-->16 34-->25 35--> 4 36-->47 37-->17 38--> 3 39-->48
40-->52 41-->36 42-->58 43-->35 44-->57 45-->34 46-->21 47-->63
48--> 5 49-->37 50-->18 51--> 8 52-->62 53-->56 54-->20 55-->54
56-->60 57-->19 58-->38 59--> 9 60-->61 61-->55 62-->59 63-->53
請輸入邏輯地址(十進制):
765497
本次訪問的地址已超出進程的地址空間,系統將產生越界中斷!
Press any key to continue
// PageMessage.cpp : 定義控制臺應用程序的入口點。 // #include "stdafx.h" #include<iostream> #include<iomanip> using namespace std; #define pagesize 1024 #define pagetablelength 64 /*系統頁表*/ const int pagetable[pagetablelength]={0,42,29,15,45,31,44,43, 41,28,1,30,12,24,6,32, 14,27,13,46,7,33,10,22, 40,2,51,11,39,23,49,50, 26,16,25,4,47,17,3,48, 52,36,58,35,57,34,21,63, 5,37,18,8,62,56,20,54, 60,19,38,9,61,55,59,53}; int _tmain(int argc, _TCHAR* argv[]) { int logicaladdress=0; int pagenum=0; int w=0; cout<<"系統頁號對應塊號情況(頁號——>塊號):\n"; for(int i=0;i<64;i++) { cout<<setw(2)<<i<<"-->"<<setw(2)<<pagetable[i]<<" "; if(i%8==7) cout<<endl; } cout<<endl<<"請輸入邏輯地址(十進制):\n"; cin>>logicaladdress; /*公式: 物理地址=頁號對應的頁塊*頁面大小+頁內偏移 頁內偏移=邏輯地址-頁面大小*頁面數*/ pagenum=logicaladdress/pagesize; //頁面數 w=logicaladdress-pagenum*pagesize; //頁面偏移 if((logicaladdress/pagesize)>pagetablelength) { cout<<"本次訪問的地址已超出進程的地址空間,系統將產生越界中斷!\n"; return 0; } cout<<"對應的物理地址為(十進制):\n"<<pagetable[pagenum]*pagesize+w<<endl; system("pause"); return 0; }
實驗三、頁式地址重定位模擬