Question
Please modify the code below so that when it takes these inputs; address-space (eg, v = 32-bit), page-size (eg, s = 4KB), and address (eg,
Please modify the code below so that when it takes these inputs; address-space (eg, v = 32-bit), page-size (eg, s = 4KB), and address (eg, a = 19986), and returns the page number and offset number of the input address (eg, p = 4 and d = 3602)
v and s should be powers of 2 s v, s, a) and please show the results
CODE TO MODIFY
#include
int main(int argc, char *argv[]) { //declare variable to hold the computed page number of given address unsigned long page; //declare variable to hold the computed offset of given address unsigned long offset; //declare variable to hold the address (command line argument) unsigned long address;
//check wheather the number of arguements passed are less than 2 if (argc
//exits program return -1; }
//reads the value from the command line, converts into integer and stores in address variable address = atoll(argv[1]); //page number= quotient of address/ 4KB and offset = remainder //below is the faster method of calculating the same
//compute the page number by using the formula; page number = address/page size page = address >> 12; // since page size if 4KB => 12 bits holding the virtual address //compute offset by using the formula; offset = address % page size offset = address & 0x1FFF;
//displays address, page number and offset printf("The address %lu contains: ", address); printf("Page number = %lu ",page); printf("Offset = %lu ",offset);
//exits function return 0; }
// sample run of this code . / a.out
Step by Step Solution
There are 3 Steps involved in it
Step: 1
![blur-text-image](https://dsd5zvtm8ll6.cloudfront.net/includes/images/document_product_info/blur-text-image.webp)
Get Instant Access with AI-Powered Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
![blur-text-image](https://dsd5zvtm8ll6.cloudfront.net/includes/images/document_product_info/blur-subtext-image.webp)
Step: 3
![blur-text-image](https://dsd5zvtm8ll6.cloudfront.net/includes/images/document_product_info/blur-subtext-image.webp)
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started