Question

In C++ l. Assume that a system has a 32-bit virtual address with a 4-KB page...

In C++ l. 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.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include<iostream>
#include<stdlib.h>
#define SIZE_OF_PAGE 4096
using namespace std;

int main(int argc, char **argv){
if(argc<2){
cout<<"Please enter the address in command line: ";
return -1;
}
unsigned int addr = atoi(argv[1]);
unsigned int page_number = addr / SIZE_OF_PAGE;
unsigned int Page_offset = addr%SIZE_OF_PAGE;
cout<<"The Address "<<addr<<" contains:\nPage number = "<<page_number<<"\nOffset = "<<Page_offset<<endl;

}

==================================================

akshay@akshay-Inspiron-3537:~$ g++ sys.cpp
akshay@akshay-Inspiron-3537:~$ ./a.out 19986
The Address 19986 contains:
Page number = 4
Offset = 3602

Add a comment
Know the answer?
Add Answer to:
In C++ l. Assume that a system has a 32-bit virtual address with a 4-KB page...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Please use the python to write Assume that a system has a 32-bit virtual address with...

    Please use the python to write 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: ./addresses 19986 Your program would output: The address 19986 contains: page number = 4 offset = 3602 Writing this program will require using...

  • Please give me all necessary screenshot and comments. (I use Eclipse) Thanks Assume a system has...

    Please give me all necessary screenshot and comments. (I use Eclipse) Thanks Assume a system has 32-bit virtual memory address with a 4-KB page size. Write a program that is passed a virtual address (in decimal) and outputs the page number and offset for the given address. The output should look like: The address 19986 contains:       Page number = 4       Offset = 3602 Your driver should pass the program three numbers: 19986, 347892, and 5978. Note the program...

  • Consider a virtual memory system with the following properties: 36 bit virtual byte address, 8 KB...

    Consider a virtual memory system with the following properties: 36 bit virtual byte address, 8 KB pages size, and 32 bit physical byte address. Please explain how you determined your answer. a. What is the size of main memory for this system if all addressable frames are used? b. What is the total size of the page table for each process on this processor, assuming that the valid, protection, dirty, and use bits take a total of 4 bits and...

  • 1) Given a virtual memory system with: virtual address 36 bits physical address 32 bits 32KB...

    1) Given a virtual memory system with: virtual address 36 bits physical address 32 bits 32KB pages (15 bit page offset) Each page table entry has bits for valid, execute, read and dirty (4 bits total) and bits for a physical page number. a) How many bits in the page table? (do not answer in bytes!) Three digit accuracy is good enough. The exponent may be either a power of 2 or a power of 10. b) The virtual address...

  • Given a virtual memory configuration with: • 4 TB virtual memory space • 32 GB physical...

    Given a virtual memory configuration with: • 4 TB virtual memory space • 32 GB physical memory space • 16 KB page size How many bits are needed for the virtual address? Choose... How many bits are needed for the physical address? Choose... How many bits in the address correspond to page offset bits? Choose... - How many bits will the virtual page number (VPN) be? Choose... - How many bits will the physical page number (PPN) be? Choose... →...

  • A computer has 32-bit virtual addresses and the page size is 2^3 KB. Suppose the text,...

    A computer has 32-bit virtual addresses and the page size is 2^3 KB. Suppose the text, data, and stack segments of a process need 5 page(s) each. If the computer uses two-level page tables, with 3 bits for the second-level index, how many page table entries (PTEs) are in each second-level page table?

  • 17. A computer system implements a paged virtual memory system. Assume a 16-bit virtual address space...

    17. A computer system implements a paged virtual memory system. Assume a 16-bit virtual address space and a 24-bit physical address space. Assume that the first 6 bits of a virtual address index the page table and the rest of the bits are the page offset. A process has the following indexed page table. Index Page Table Entry (PTE) 0x3800 0x3600 0x3200 0x1000 2 3 Each page table entry qives a hexadecimal page frame addresses. Translate the following two hexadecimal...

  • The RISC-V 32-bit architecture supports virtual memory with 32-bit virtual addresses mapping to 32-bit physical addresse...

    The RISC-V 32-bit architecture supports virtual memory with 32-bit virtual addresses mapping to 32-bit physical addresses. The page size is 4Kbytes, and page table entries (PTEs) are 4 bytes each. Translation is performed using a 2-level page table structure. Bits 31:22 of a virtual address index the first-level page table. If the selected first-level PTE is valid, it points to a second-level page table. Bits 21:12 of the virtual address then index that second-level page table. If the selected second-level...

  • Paging Questions 1. A page is 1 KB in size. How many bits are required to...

    Paging Questions 1. A page is 1 KB in size. How many bits are required to store the page offset? 2. A page entry has 10 bits. What is the size of the page table? 3. A logical address is 32 bits long. The page size is 4 KB. Divide the address into its page number and offset. 4. The following hexadecimal addresses are used in a system with a 20-bit logical address where the page size is 256 bytes....

  • A certain byte-addressable computer system has 32-bit words, a virtual address space of 4GB, and a...

    A certain byte-addressable computer system has 32-bit words, a virtual address space of 4GB, and a physical address space of 1GB. The page size for this system is 4 KB. Assume each entry in the page table is rounded up to 4 bytes. a) Compute the size of the page table in bytes. b) Assume this virtual memory system is implemented with a 4-way set associative TLB (Translation Lookaside Buffer) with a total of 256 address translations. Compute the size...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT