Page Table Simulation

This program will take as input a file containing a page table and memory requests. Call your program PageTableSim. You may write it in any language you would like, but I have to be able to run it.

File Format

The input file will consist of a page table and memory requests. The table starts with a single decimal integer, s, on its own line which is the number of entries in the table. s will be a power of two between 2 and 216 inclusive. We will use the letter p to indicate this power, so s = 2p. Recall, this means we can represent the index to the page table with p bits.

Next, there are s 32-bit hexadecimal integers, each on its own line, representing page table entries. The format for the 32 bits are as follows:

Bit3130...1918171615...0
Data0ignoredvalidread onlysharedframe number
Example
00061234
0000 0000 0000 0110 0001 0010 0011 0100

The example shows how to break down the bits of the value 00061234. Bits 18, 17 and 16 indicate that the page is valid, read only, or shared, respectively.

The page table is followed by logical memory requests. On the first line after the table is a number, n in decimal indicating the number of memory accesses. This is followed by n 32-bit hexadecimal numbers, one for each request. The format is below.

Bit 31...8+p 8 + (p-1)...8 7...0
Data ignored page number offset
Example
0000 0607
s = 8 = 23, so p = 3
0000 0000 0000 0000 0000 0 110 0000 0111

Output Format

Your program will read each request number and determine the page number and the offset. In this example the page number is 6 and the offset is 07 (in hex). It will use the page number as an index in the page table to determine the frame number. Suppose the entry at location 6 is 00061234. Your program will determine if the entry is valid (using bit 18) and if it is, calculate the physical address, which will be: 123407 (the frame number put together with the offset). It should also indicate if the page is read-only or shared, based on the other flag bits.

Sample Input File

The following is a sample input file. In this case the page table has 8 entries and there are 8 logical addresses to decode.
8
00001AB8
0001BEEF
00028080
0003ABCD
0004FFFF
00050003
0006000A
00070000
8
000000A1
000001B2
000002C3
000003D4
080004E5
000005F6
00000607
00000718
    

Sample Output

This program prompts for the filename an then produces the following output, in this case the user typed "table.txt". Your output does not need to be formatted exactly like the example, but you should produce the same information.

Enter a page table file: table.txt
            Request: 0x000000A1
   Page table entry: 0x00001AB8
             INVALID

            Request: 0x000001B2
   Page table entry: 0x0001BEEF
             INVALID

            Request: 0x000002C3
   Page table entry: 0x00028080
             INVALID

            Request: 0x000003D4
   Page table entry: 0x0003ABCD
             INVALID

            Request: 0x080004E5
   Page table entry: 0x0004FFFF
   Physical Address: 0x00FFFFE5
       Frame Number: 0xFFFF
             Offset: 0xE5
          Read only: FALSE
             Shared: FALSE

            Request: 0x000005F6
   Page table entry: 0x00050003
   Physical Address: 0x000003F6
       Frame Number: 0x0003
             Offset: 0xF6
          Read only: FALSE
             Shared: TRUE

            Request: 0x00000607
   Page table entry: 0x0006000A
   Physical Address: 0x00000A07
       Frame Number: 0x000A
             Offset: 0x07
          Read only: TRUE
             Shared: FALSE

            Request: 0x00000718
   Page table entry: 0x00070000
   Physical Address: 0x00000018
       Frame Number: 0x0000
             Offset: 0x18
          Read only: TRUE
             Shared: TRUE
      

Suggestions