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 #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 Please modify the code below so that when it takes these inputs;

The address 19986 contains: Page number = 4 Offset = 3602 The address 19986 contains: Page number = 4 Offset = 3602

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!