Simulation of Address Translation in Paging Scheme
Simulation of Address Translation in Paging Scheme
Aim
To simulate the address translation mechanism in the paging memory management scheme by converting a given virtual address into its corresponding physical address using a page table.
Problem Statement
Write a program to simulate paging-based address translation with the following inputs provided as command-line arguments:
-
Size of the virtual address space (in megabytes)
-
Page size (in kilobytes)
-
Virtual address (in decimal notation)
The program should output the physical address in the format:
Assume that:
-
The page table is implemented as an array indexed by page number
-
If the page number is not present in the page table, declare a page table miss
Description / Theory
Paging is a memory management technique in which:
-
Virtual memory is divided into fixed-size blocks called pages
-
Physical memory is divided into fixed-size blocks called frames
Each process maintains a page table that maps page numbers to frame numbers.
A virtual address consists of:
-
Page Number (p) – used as an index into the page table
-
Offset (d) – position within the page
Address Translation Formula:
The physical address is represented as:
If the page number does not exist in the page table, a page table miss occurs.
Algorithm
-
Read the command-line arguments:
-
Virtual address space size (MB)
-
Page size (KB)
-
Virtual address
-
-
Convert:
-
Virtual address space → bytes
-
Page size → bytes
-
-
Compute the number of pages.
-
Create a page table with identity mapping:
-
Validate the virtual address.
-
Extract:
-
Page number
-
Offset
-
-
If the page number is valid:
-
Display physical address as
<frame number, offset>
-
-
Else:
-
Display Page Table Miss
-
Flowchart
Program (C Implementation)
Sample Input
Input Explanation:
-
Virtual Address Space = 16 MB
-
Page Size = 4 KB
-
Virtual Address = 12345
Sample Output
Result
Thus, the given virtual address was successfully translated into its corresponding physical address using paging. The simulation demonstrates the working of a page table–based address translation mechanism.
Comments
Post a Comment