操作系统实验-页面地址重定位


页面地址重定位
#include 
#include 
#define PagetableLength 64
using namespace std;
int PageTable[PagetableLength] = {0};
//前提:地址是从0开始的
int main()
{
    int LogicalAddress = 0;
    int PageNum = 0;
    int w = 0;
    int i = 0;
    int num = 0;
    int f;
    int PageSize;
    char flag;
    cout << "请输入页号长度;" << endl;
    cin >> num;
    cout << "请输入页面大小:" << endl;
    cin >> PageSize;
    cout << "请依次输入块号;" << endl;
    for(i = 0; i < num; i++ )
    {
        cin >> PageTable[i];
    }
    cout << "系统页号对应块号情况;\n";
    for (i = 0; i < num; i++)
    {
        cout << setw(2) << i << "-->" << setw(2) << PageTable[i];
        if(i % 8 == 7)
            cout << endl;
    }
    while(f)
    {
    cout << endl << "请输入逻辑地址;\n";
        cin >> LogicalAddress;
    PageNum = LogicalAddress / PageSize;
    w = LogicalAddress % PageSize;//求页内偏移地址


    if(PageNum >= PagetableLength)//判断是否越界
    {
        cout << "本次访问的地址已超出进程的地址空间,错误!;\n";
        return -1;
    }
    cout << "对应的物理地址为;" << endl << PageTable[PageNum] * PageSize + w << endl;
    cout << "你还想继续请求分配吗?是请按Y/y,否按其他键" << endl;
           cin >> flag;
            if(flag == 'Y' || flag == 'y')
                f = 1;
            else
                break;
    }
        return 0;
}


你可能感兴趣的:(操作系统实验课)