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

//*** Before I post this question but answer does not work. I need this answer i

ID: 3695020 • Letter: #

Question

//*** Before I post this question but answer does not work. I need this answer in C program and also I want see the programming output. With answer gives the programming output. 1st time answer #include gives fatal error. 2nd time answer running output showing core dump. Thanks ***// 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. As an example, your program would run as follows: ./a.out 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.We encourage you to use unsigned data types as well.

Explanation / Answer

The below program works. check with your example:

#include <stdio.h>

int main()
{
unsigned int logical_address = 0;
unsigned int offset = 0;
unsigned int page_num = 0;
printf("Enter logical address: ");
scanf("%d", &logical_address);

/* offset is Least Significant 12 bits (4KB) of logical address */
offset = logical_address & 0xFFF;

/* Remaining 20 bits represents Page number */
page_num = logical_address >> 12;

printf("The address %d contains: page number = %d offset = %d ", logical_address, page_num, offset);

}