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

Can someone help with this code? I have no idea on how to even begin :( It can b

ID: 3576357 • Letter: C

Question

Can someone help with this code? I have no idea on how to even begin :(
It can be either in C++ or Python. Thanks in advance, I really apreciate it!

Assume that a system has a 32-bit virtual address with a 4-KB page size. Write a 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 As an example, your program would run as follows: yourprogram 19986 Your program would output: The address 19986 contains Page number 4 Offset 3602 Writing this program will require using the appropriate data type to store 32 bits. Use unsigned data type types as well.

Explanation / Answer

A virtual is composed of page number and offset.

Since the page size is 4KB, the page size is represent using 16bit.(2^16=4KB)

So, the first 16 bits in the virtual address represents page number, and remaining 16 bits represents

the offset within that page.

Please see below python program to get the page number , and offset .

###############


import sys

print (sys.argv)

virtualAddress= int (sys.argv[1])

pagenumber= int ( virtualAddress & 0xFFFF0000 ) >> 16;
Offset = ( virtualAddress & 0xFFFF);

print "Page number = ", pagenumber
print "Offset", Offset

###############