Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

convert this code to java language /*C-Preprocessor*/ #include #include #include #include #include #include #include /* constants*/ #define PAGES 256 #define PAGE_MASK 255 #define PAGE_SIZE 256

convert this code to java language

/*C-Preprocessor*/ #include #include #include #include #include #include #include

/* constants*/ #define PAGES 256 #define PAGE_MASK 255 #define PAGE_SIZE 256 #define OFFSET_BITS 8 #define OFFSET_MASK 255 #define MEMO_SIZE PAGES * PAGE_SIZE #define BUF_SIZE 10

/* physicall page number*/ int pagetable[PAGES];

signed char main_Memo[MEMO_SIZE]; signed char *backing_ptr;

int main(int argc, const char *argv[]) { /*check if the user entered 3 arguments otherwise exit*/ if (argc != 3) { printf( "Please enter 3 args: <./file_exe_name> "); exit(0); }

/* This will fill all the page table with -1*/ for (int i = 0; i < PAGES; i++) { pagetable[i] = -1; } int total_addr = 0,pageFault = 0; const char *file_name = argv[1]; const char *input_file = argv[2]; const char *output_file = "output.txt"; int backing_ptr_fd = open(file_name, O_RDONLY); backing_ptr = mmap(0, MEMO_SIZE, PROT_READ, MAP_PRIVATE, backing_ptr_fd, 0); FILE *input_fp = fopen(input_file, "r"); FILE *output_fp=fopen(output_file, "w"); char buf[BUF_SIZE]; /* represent the number of the next unallocated physical page inside the main memory*/ unsigned char freePage = 0; while (fgets(buf, BUF_SIZE, input_fp) != NULL) { int logical_addr = atoi(buf); int offset = logical_addr & OFFSET_MASK; int logical = (logical_addr >> OFFSET_BITS) & PAGE_MASK; int physical = pagetable[logical]; total_addr++; /*page fault*/ if (physical == -1) { pageFault++;

physical = freePage; freePage++;

memcpy(main_Memo + physical * PAGE_SIZE, backing_ptr + logical * PAGE_SIZE, PAGE_SIZE);

pagetable[logical] = physical; }

/*The signed byte value stored at the translated physicall address*/ int physicall_addr = (physical << OFFSET_BITS) | offset; signed char value = main_Memo[physical * PAGE_SIZE + offset];

fprintf(output_fp,"Logical address: %d physicall address: %d Value: %d ", logical_addr, physicall_addr, value); }

printf("Number of Translated Addresses = %d ", total_addr); printf("Page faults = %d ", pageFault); printf("Page Fault Rate = %.1f % ", (pageFault / (total_addr*1.))*100);

return 0; }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Design Application Development And Administration

Authors: Michael V. Mannino

4th Edition

0615231047, 978-0615231044

More Books

Students also viewed these Databases questions

Question

Step by step formatbsolution correct

Answered: 1 week ago

Question

f. Did they change their names? For what reasons?

Answered: 1 week ago