THINK FIRST·CODE LATER

← All labs

Paging calculator and address translation

Problem

Input: addressBits pageSize pteBytes (page size is a power of two), then the number of entries in a process's page table, the entries (frame number, or −1 if the page is not present), then logical addresses until the end of input.

Print:

Offset bits: 12, page-number bits: 20
Pages in address space: 1048576
Single-level page table: 4 MiB
Entries per page-sized table: 1024 (10 bits)
Levels needed: 2

— the table size in the largest unit (B, KiB, MiB, GiB, TiB, PiB) where the value is ≥ 1 (integer if exact, else 2 decimals); "levels needed" = ceil(page-number bits / bits per level), where one level's table fits in one page.

Then for each address: logical 7700: page 7, offset 532, frame 1 -> physical 1556, or … PAGE FAULT if the entry is −1, or … SEGMENTATION FAULT (page 8 not in table) if the page is beyond the table.

Data for this lab

Your program reads its data from standard input. Download the file, then give it to your program as shown below. Start with data set 1: its expected output is given.

os9-2-data-1.txt

16 1024 2
8
5 -1 2 7 -1 0 3 1
0 1023 1024 2100 5000 7700 9000
What your program must print for os9-2-data-1.txt
Offset bits: 10, page-number bits: 6
Pages in address space: 64
Single-level page table: 128 B
Entries per page-sized table: 512 (9 bits)
Levels needed: 1
logical 0: page 0, offset 0, frame 5 -> physical 5120
logical 1023: page 0, offset 1023, frame 5 -> physical 6143
logical 1024: page 1, offset 0, PAGE FAULT
logical 2100: page 2, offset 52, frame 2 -> physical 2100
logical 5000: page 4, offset 904, PAGE FAULT
logical 7700: page 7, offset 532, frame 1 -> physical 1556
logical 9000: page 8, offset 808, SEGMENTATION FAULT (page 8 not in table)

Run your program first, then open this and compare line by line: your output must contain these lines exactly.

How to give the file to my program

Terminal (macOS, Linux, or Windows Command Prompt), after compiling:

java Main < os9-2-data-1.txt

Windows PowerShell does not understand <:

Get-Content os9-2-data-1.txt | java Main

IntelliJ IDEA: Run → Edit Configurations → Redirect input from. Or simply paste the content of the file into the console when the program waits for input.

Write it here or in your IDE, then paste it. Compile and test it yourself before comparing. Your code stays in your browser — it is never sent to or stored on the server.