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

Os Exp6 OS Code6 Merged

The program simulates the paging technique by taking user input for number of pages, frames, page size, frame size and logical addresses. It then calculates the page and offset bits, maps the logical addresses to physical addresses by calculating the page number, frame number and offset and prints the logical and corresponding physical addresses.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views

Os Exp6 OS Code6 Merged

The program simulates the paging technique by taking user input for number of pages, frames, page size, frame size and logical addresses. It then calculates the page and offset bits, maps the logical addresses to physical addresses by calculating the page number, frame number and offset and prints the logical and corresponding physical addresses.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

T

THADOMA

GINEERt GE / 6 G

~f ~:

't i

.
.)IV)

, l '

C.P

um v~

_ ____j__ _ _ '
- - - - u - - - - - - - -_ _ _ _ _ _ _
--
'
II
18

s~ , Ll!e)\ ..

cJru
• •
.to &l~ ~
•u,-1
\
\ 'Z..Q

EQ~ Ont
.. .

' I
-_ l

r( ..
.. 'o'l. '
\'LY
[
tl
~u v(') •
-~ lY)
r
l
-
gi -:%.L 2"· •

7
..\

,t

t 0 5 'M


.t
b "
2. \ 0
C\ •
j
,~ 2.
.3
p

)_ ta.
c~ vQ A "
l\
''L M
Q
a
·\!> ·n b
N 0 C
• ' t

IS ' d

'=t
? -~

\ 0
Tiu:i~--- \ '

iil ,__,___ ,'/

ENGINEERING c

we.

'l •

LA
0

A ILi 'PA )0 .

l
Experiment No. 6

Aim: Write a program to simulate Paging technique.


Code:
#include<stdio.h>
#include<stdlib.h>
#include<math.h>

int calculateBits(int num) {


return (int)ceil(log2(num));
}

void paging(int pages, int frames, int page_size, int frame_size, int
logical_addresses[], int n) {
int page_bits = calculateBits(pages);
int offset_bits = calculateBits(page_size);

printf("\nPage Bits: %d\n", page_bits);


printf("Offset Bits: %d\n", offset_bits);

printf("\nLogical Address\tPhysical Address\n");


for (int i = 0; i < n; i++) {
int page_number = logical_addresses[i] / page_size;
int offset = logical_addresses[i] % page_size;

if (page_number >= pages) {


printf("Invalid logical address: %d\n", logical_addresses[i]);
continue;
}

int frame_number = page_number % frames;

int physical_address = frame_number * frame_size + offset;

printf("%d\t\t%d\n", logical_addresses[i], physical_address);


}
}

int main() {
int pages, frames, page_size, frame_size, n;

printf("Enter the number of pages: ");


scanf("%d", &pages);

printf("Enter the number of frames: ");


scanf("%d", &frames);

printf("Enter the size of each page (in bytes): ");


scanf("%d", &page_size);

printf("Enter the size of each frame (in bytes): ");


scanf("%d", &frame_size);
printf("Enter the number of logical addresses: ");
scanf("%d", &n);

int logical_addresses[n];
printf("Enter the logical addresses: ");
for (int i = 0; i < n; i++) {
scanf("%d", &logical_addresses[i]);
}

paging(pages, frames, page_size, frame_size, logical_addresses, n);

return 0;
}
Output:

You might also like