Practical - 5: Aim: Assuming That A System Has A 32-Bit Virtual Address, Write A Java Program That
Practical - 5: Aim: Assuming That A System Has A 32-Bit Virtual Address, Write A Java Program That
no:90
Practical -5
Aim : Assuming that a system has a 32-bit virtual address, write a Java program that
is passed (1) the size of a page and (2) the virtual address. Your program will report
the page number and offset of the given virtual address with the specified page size.
Page sizes must be specified as a power of 2 and within the range 1024 —16384
(inclusive). Assuming such a program is named Address, it would run as follows: java
Address 4096 19986 and the correct output would appear as: The address 19986
contains: page number = 4 offset = 3602.
Code :
Prac55.java
import java.io.BufferedReader;
import java.io.InputStreamReader;
int pageBits = 0;
int pageMask = 0;
int offsetMask = 0;
switch (pageSize) {
case 1024:
pageBits = 10;
offsetMask = 0x000003ff;
pageMask = 0xfffffc00;
break;
case 2048:
pageBits = 11;
offsetMask = 0x000007ff;
pageMask = 0xfffff800;
break;
case 4096:
pageBits = 12;
offsetMask = 0x00000fff;
pageMask = 0xfffff000;
break;
case 8192:
pageBits = 13;
offsetMask = 0x00001fff;
pageMask = 0xffffe000;
break;
case 16384:
pageBits = 14;
offsetMask = 0x00003fff;
pageMask = 0xffffcfff;
break;
}
}
}
Output :