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

Assume that a system has a 32-bit virtual address with a 4-KB page size (12bits)

ID: 3571908 • Letter: A

Question

Assume that a system has a 32-bit virtual address with a 4-KB page size (12bits).
Write a program that is passed a virtual address (in decimal) via the attached txt
file and have it output the page number and offset for the given address in
the command line. The program should mask page number and offset
from an unsigned 32-bit address by using bitwise operation.

EDIT: I had seen a couple of similar questions previously asked/posted, but none of them addressed the issue of masking using a bitwise operation specifically. That, in particular is what I wanted to know about and see demonstrated.

Explanation / Answer

The program is:

#include <stdio.h>

int main(int argc,char *argv[])

{

unsigned long long int MappedAdress = atoll(argv[1]);

unsigned long long int page = MappedAdress;

unsigned long long int offset = MappedAdress;

printf("The MappedAdress %llu contains: ",MappedAdress);

page = page >> 12;

printf("Page Number : %llu ",page);

offset = offset & 0x1FFF;

printf("Offset = %llu ",offset);

return 0;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote