Skip to content

Instantly share code, notes, and snippets.

@pythongo1
Created June 22, 2019 12:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pythongo1/2ab858dcfe2c0b9c274a8ba2f41e16c4 to your computer and use it in GitHub Desktop.
Save pythongo1/2ab858dcfe2c0b9c274a8ba2f41e16c4 to your computer and use it in GitHub Desktop.
#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