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.

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.