0% found this document useful (0 votes)
3 views

OS 10

The document presents a C program that implements a paging technique for translating logical addresses to physical addresses using a page table. Users input frame numbers for each page and the program calculates the corresponding physical address based on the logical address provided. The output includes details such as logical address, page number, offset, frame number, and physical address.

Uploaded by

jayaprakash9223
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

OS 10

The document presents a C program that implements a paging technique for translating logical addresses to physical addresses using a page table. Users input frame numbers for each page and the program calculates the corresponding physical address based on the logical address provided. The output includes details such as logical address, page number, offset, frame number, and physical address.

Uploaded by

jayaprakash9223
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Sprno:9223

10 IMPLEMENT THE PAGING TECHNIQUE


PROGRAM:
#include <stdio.h>
#include <stdlib.h>
#define PAGE_SIZE 512
#define PAGE_COUNT 8
#define FRAME_COUNT 16
int main() {
int page_table[PAGE_COUNT];
int i, num_addresses;
printf("Enter the frame numbers for each page (0 to %d):\n",
FRAME_COUNT - 1);
for (i = 0; i < PAGE_COUNT; i++) {
printf("Page %d -> Frame: ", i);
scanf("%d", &page_table[i]);
if (page_table[i] < 0 || page_table[i] >= FRAME_COUNT) {
printf("Invalid frame number!\n");
return 1;
}
}
printf("\nEnter number of logical addresses to translate: ");
scanf("%d", &num_addresses);
int logical_address;
for (i = 0; i < num_addresses; i++) {
printf("\nEnter logical address %d (0 - %d): ", i + 1, (PAGE_COUNT *
PAGE_SIZE) - 1);
scanf("%d", &logical_address);
if (logical_address < 0 || logical_address >= PAGE_COUNT *
PAGE_SIZE) {
printf("Invalid logical address!\n");
continue;
Sprno:9223

}
int page_number = logical_address / PAGE_SIZE;
int offset = logical_address % PAGE_SIZE;
int frame_number = page_table[page_number];
int physical_address = (frame_number * PAGE_SIZE) + offset;
printf("Logical Address: %d\n", logical_address);
printf("Page Number: %d\n", page_number);
printf("Offset: %d\n", offset);
printf("Frame Number: %d\n", frame_number);
printf("Physical Address: %d\n", physical_address);
}
return 0;
}
OUTPUT:
Enter the frame numbers for each page (0 to 15):
Page 0 -> Frame: 3
Page 1 -> Frame: 7
Page 2 -> Frame: 5
Page 3 -> Frame: 2
Page 4 -> Frame: 10
Page 5 -> Frame: 8
Page 6 -> Frame: 1
Page 7 -> Frame: 0
Enter number of logical addresses to translate: 2
Enter logical address 1 (0 - 4095): 1300
Logical Address: 1300
Page Number: 2
Offset: 276
Frame Number: 5
Physical Address: 276 + (5 * 512) = 2816
Sprno:9223

Enter logical address 2 (0 - 4095): 3600


Logical Address: 3600
Page Number: 7
Offset: 16
Frame Number: 0
Physical Address: 16

You might also like