Operating system exercises-virtual address to memory address calculation

Reference link: https://blog.csdn.net/weixin_39928544/article/details/90049798

step:

If the virtual address (logical address, program address) is given in the form of hexadecimal, octal, and binary, the
first step is to convert the virtual address into a binary number; in the
second step, the page number and the Displacement (lower part is the displacement and higher part is the page number); the
third step is to generate a page table according to the title and copy the displacement directly to the lower part of the memory address register; the
fourth step is to check the page table by the page number , Get the block number of the corresponding page into memory, and convert the block number into a binary number to fill in the high-order part of the address register, thereby forming a memory address.

 

Examples:
1. A system uses paged storage management. One job has a size of 8KB and a page size of 2KB. It is loaded into the 7th, 9th, A, and 5th blocks of the memory in sequence, and attempts to convert the virtual address 0AFEH into a memory address.
Solution:
| Page number | block number |
| 0 |. 7 |
|. 1 |. 9 |
| 2 | A |
|. 3 |. 5 |
virtual address is converted to a binary number 0AFEH: 0,000,101,011,111,110 ( note the virtual address hexadecimal, The last H flag is a hexadecimal number . The
known page size is 2kb ( that is, there are 11 bits, 2 ^ 11 = 2kb ), so the lower part is 11 bits, so, w = 010 1111 1110, p = 0000 1 = 1 (the lower part is the page address, and the higher part is the page number )


According to the arrangement of page number and block number, when p = 1, the block number is 9, the binary number of 9 is 1001, and the first address of the table is 0.
Therefore, MR = (first 0) 0100 1010 1111 1110 (binary) = 4AFEH (16 System) ( According to the step-by-step procedure, we have to move the lower part of the page number to the address register, and then 1001 is regarded as the upper part, not enough to fill 0 in front )

 

example:

A request page system allows 32 user pages (1KB per page) and 16KB of main memory. If a user program is 10 pages long, the page table of the process at a certain time is as follows: Is the
virtual page number physical block number in a TLB
0. 8 is a
1 7
24 No
3 10 No
45 No
53 is
62 is
otherwise invalid
Q: (1) calculate the virtual address 0AC5H, 1AC5H corresponding physical address.
(2) The page table is stored in the main memory. One access to the main memory requires 1.5ns, and the search time for the TLB table is ignored as 0. How much time does the two accesses take?

 

answer:

(1) 32 pages need to be distinguished by 5 bits, and the address within the page needs 10 bits. The page number of the virtual address 0AC5H is 2, and the address in the page is 1011000101. As can be seen from the page table, its physical block number is 4, so its physical address is 1001011000101 = 12C5H. The page number of the virtual address 1AC5H is 6, and the address on the page is 1011000101. According to the page table, the physical block number corresponding to the virtual address is 2, and the physical address is 101011000101 = 0AC5H.
(2) The first access to the TLB did not hit, so you need to look up the page table and access the main memory again for a total time of 3ns. The second virtual address in the TLB requires only one memory access, with a total time of 1.5ns.

Guess you like

Origin www.cnblogs.com/kongbursi-2292702937/p/12710249.html