NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

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

int main() {
int process_size, page_size, mem_size, num_frames, num_entries;
int phys_addr_bits, log_addr_bits, page_num_bits, offset_bits;
char logical_addr[32];
int page_num, offset, i, is_present;
int page_table[100][3];

printf("Enter size of process (in KB): ");
scanf("%d", &process_size);

printf("Enter page size (in bytes): ");
scanf("%d", &page_size);

printf("Enter size of physical memory (in MB): ");
scanf("%d", &mem_size);

printf("Enter page table for the process (Page no. Frame no. Valid Bit):n");
printf("Page no. Frame no. Valid Bitn");
for (i = 0; i < 100; i++) {
scanf("%d%d%d", &page_table[i][0], &page_table[i][1], &page_table[i][2]);
if (page_table[i][0] == -1) {
break;
}
}
num_entries = i;

num_frames = (float) (mem_size * 1024) / page_size;

phys_addr_bits = log2(num_frames) + log2(page_size);

log_addr_bits = log2(process_size * 1024) + log2(page_size);
page_num_bits = log2(process_size * 1024 / page_size);
offset_bits = log2(page_size);

printf("Total number of frames in memory: %dn", num_frames);
printf("Number of entries in page table: %dn", num_entries);
printf("Number of bits in physical address: %dn", phys_addr_bits);
printf("Number of bits in logical address: %dn", log_addr_bits);
printf("Number of bits for page number: %dn", page_num_bits);
printf("Number of bits for offset: %dn", offset_bits);

printf("Enter logical address in binary form: ");
scanf("%s", logical_addr);

page_num = 0;
offset = 0;
for (i = 0; i < log_addr_bits; i++) {
if (logical_addr[i] == '1') {
if (i < page_num_bits) {
page_num += pow(2, page_num_bits - 1 - i);
} else {
offset += pow(2, offset_bits - 1 - (i - page_num_bits));
}
}
}

if (page_num >= num_entries || page_table[page_num][2] == 0) {
is_present = 0;
} else {
is_present = 1;
}

if (is_present) {
printf("The page corresponding to the logical address is present in memory.n");
} else {
printf("The page corresponding to the logical address is not present in memory.n");
}

return 0;
}
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.