Created
June 22, 2019 12:06
-
-
Save pythongo1/2ab858dcfe2c0b9c274a8ba2f41e16c4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<stdio.h> | |
#include<stdlib.h> | |
//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. | |
int main(int argc, char *argv[]) | |
{ | |
unsigned long page_number; | |
unsigned long page_offset; | |
unsigned long address; | |
address = atol(argv[1]); | |
page_offset = address%4096; | |
page_number = (address-page_offset)/4096; | |
printf("The addree %lu contains:\n", address); | |
printf("page number = %lu\n", page_number); | |
printf("offset = %lu\n", page_offset); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment