Question
Need help understanding what a couple of lines of code are doing here, I have highlighted the 3 lines I don't understand. what are the
Need help understanding what a couple of lines of code are doing here, I have highlighted the 3 lines I don't understand. what are the highlighted lines defining at the start? What does the hex value correspond to? And how is the page number calculated in the last highlighted line? What is the "(address & PAGE_NUMBER)" doing along with the >> 12?
The input of the program is a virtual address such as 19955 with the output being the page number and offset.
Program:
#include
#define PAGE_NUMBER 0XFFFFF000 #define OFFSET 0x00000FFF
int main(int argc, char *argv[]) { int pageNumber, offset; unsigned int address; address = (unsigned int)atoi(argv[1]); if(argc != 2) { printf("Error number of arguments is less that 2. "); return -1; } printf("The address %d contains: ", address); pageNumber = (address & PAGE_NUMBER) >> 12; offset = address & OFFSET; printf("Page Number = %d ", pageNumber); printf("Offset = %d ", offset); return 0; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started