Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Please write a program in C++ to stimulate the internal operation of MMU with single-level page table. Description The virtual address is split into
Please write a program in C++ to stimulate the internal operation of MMU with single-level page table. Description The virtual address is split into a virtual page number (high-order bits) and an offset (low-order bits). With a 16-bit address and a 4-KB page size, the upper 4 bits could specify one of the 16 virtual pages and the lower 12 bits would then specify the byte offset (0 to 4095) within the selected page. The virtual page number is used as an index into the page table to find the entry for that virtual page. From the page table entry, the page frame number (if any) is found. The page frame number is attached to the high-order end of the offset, replacing the virtual page number, to form a physical address that can be sent to the memory. Thus, the purpose of the page table is to map virtual pages onto page frames. Mathematically speaking, the page table is a function, with the virtual page number as argument and the physical frame number as result. Using the result of this function, the virtual page field in a virtual address can be replaced by a page frame field, thus forming a physical memory address. Notice (1) The page table is a single-level page table. (2) The related data structures and the global object pageTable were defined as follows, which can be accessed directly by your code. #define N 16 struct SPageTableEntry { }; unsigned char pageFramNr: 3; bool pa; struct SPageTable { SPageTableEntry pte[N]; SPageTable(); // constructor, already defined by the system to init pageTable. } pageTable; (3) You only need to write the main function in C++. (4) Don't return non-zero value in your main function, or it is regarded as a program error by the OJ system. (5) Input an unsigned short variable as a logical address. If the logical address is greater than 65535, then it is 65535. (6) Check the Present/absent bit, if it is 1, then convert the logical address into the corresponding physical address, or output "Page fault!". (7) Figure 1 explains the principle of converting a logical (virtual) addresse to the physical addresse. The values in the page table in the figure may be different from the values in the object page Table! Page table 10000000000100 15 000 0 14 000 0 13 000 0 12 000 0 11 111 1 10 000 0 9 101 1 8 000 0 000 0 000 0 011 1 4 100 1 3 000 1 2 110 1 1 001 1 0 010 1 7 6 5 110 -Present/ absent bit Virtual page = 2 is used as an index into the page table 12-bit offset copied directly from input to output 0010000000000100 Outgoing physical address (24580) Incoming virtual address (8196) Figure 1. Convert a logical address (virtual address) with 16 bits to the physical address. Please write a program in C++ to stimulate the internal operation of MMU with single-level page table. Description The virtual address is split into a virtual page number (high-order bits) and an offset (low-order bits). With a 16-bit address and a 4-KB page size, the upper 4 bits could specify one of the 16 virtual pages and the lower 12 bits would then specify the byte offset (0 to 4095) within the selected page. The virtual page number is used as an index into the page table to find the entry for that virtual page. From the page table entry, the page frame number (if any) is found. The page frame number is attached to the high-order end of the offset, replacing the virtual page number, to form a physical address that can be sent to the memory. Thus, the purpose of the page table is to map virtual pages onto page frames. Mathematically speaking, the page table is a function, with the virtual page number as argument and the physical frame number as result. Using the result of this function, the virtual page field in a virtual address can be replaced by a page frame field, thus forming a physical memory address. Notice (1) The page table is a single-level page table. (2) The related data structures and the global object pageTable were defined as follows, which can be accessed directly by your code. #define N 16 struct SPageTableEntry { }; unsigned char pageFramNr: 3; bool pa; struct SPageTable { SPageTableEntry pte[N]; SPageTable(); // constructor, already defined by the system to init pageTable. } pageTable; (3) You only need to write the main function in C++. (4) Don't return non-zero value in your main function, or it is regarded as a program error by the OJ system. (5) Input an unsigned short variable as a logical address. If the logical address is greater than 65535, then it is 65535. (6) Check the Present/absent bit, if it is 1, then convert the logical address into the corresponding physical address, or output "Page fault!". (7) Figure 1 explains the principle of converting a logical (virtual) addresse to the physical addresse. The values in the page table in the figure may be different from the values in the object page Table! Page table 10000000000100 15 000 0 14 000 0 13 000 0 12 000 0 11 111 1 10 000 0 9 101 1 8 000 0 000 0 000 0 011 1 4 100 1 3 000 1 2 110 1 1 001 1 0 010 1 7 6 5 110 -Present/ absent bit Virtual page = 2 is used as an index into the page table 12-bit offset copied directly from input to output 0010000000000100 Outgoing physical address (24580) Incoming virtual address (8196) Figure 1. Convert a logical address (virtual address) with 16 bits to the physical address.
Step by Step Solution
★★★★★
3.45 Rating (164 Votes )
There are 3 Steps involved in it
Step: 1
C program that simulates the internal operation of an MMU with a singlelevel ...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