Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

// Before I post this question but answer does not work. I need this answer in C

ID: 3694877 • Letter: #

Question

// Before I post this question but answer does not work. I need this answer in C program and also please upload the programming output. Previous answer #include gives fatal error. Thanks // Assume that a system has a 32-bit virtual address with a 4-KB page size. Write a C program that is passed a virtual address (in decimal) on the command line and have it output the page number and offset for the given address. As an example, your program would run as follows: ./a.out 19986 Your program would output: The address 19986 contains: page number = 4 offset = 3602 Writing this program will require using the appropriate data type to store 32 bits.We encourage you to use unsigned data types as well.

Explanation / Answer


#include <stdio.h>

int main(int argc, char *argv[])
{
unsigned long page;
unsigned long offset;
unsigned long address;


address= atoll(argv[1]);
/* Page Number = quotient of address / 4KB and offset = remainder*/
/*Below is the faster method of calculating the same*/

page = address >> 12; /* Since page size is 4KB => 12 bits holding the virtual address*/
offset = address & 0xfff;

printf("The address %lu contains: ", address);
printf("page number = %lu ",page);
printf("offset = %lu ", offset);


return 0;
}