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

- Let’s say that a system has 32 bit addressing and uses a 4KB page size. Write

ID: 3801614 • Letter: #

Question

- Let’s say that a system has 32 bit addressing and uses a 4KB page size. Write a c program that takes one argument from command line which is the virtual address(in decimal) and gives you the physical page and offset

     Example   is argument 21345

    Output is

  The address 21345 contains: page number = 5 offset = 865

Explanation / Answer

#include 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; }