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


页面地址重定位
#include <iostream>
#include <iomanip>
#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;
}


  • 2
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值