"Operating System" How to Convert Logical Addresses to Physical Addresses

1. Formula

(1) Hexadecimal

Logical address = page number + page address
Physical address = block number + page address

(2) Non-hexadecimal

Physical address = block number * page size + page address
page number = logical address / page size byte = (take an integer)
page address = logical address% page size byte = (take the remainder)

Two, examples

(1) Hexadecimal example

In a paging storage management system, the logical address length is 16 bits, and the page size is 4KB bytes. The existing logical address is 3C20H, and pages 0, 1, 2, and 3 are stored in physical blocks 2, 3, 5, and 6 in sequence. . Find the physical address solution corresponding to the logical address 3C20H 

Step 1: Convert the logical address 3C20H to binary: 0011 1100 0010 0000
Step 2: Since the page size is 4KB, (4KB=2^12). So the last 12 bits of the logical address are the "page address" (also called the page offset). 
Step 3: Since the last 12 bits of the logical address are the page address, the remaining first 4 bits are the page number: ie 0011 is the page number 
Step 3: According to the page table, the page frame number (block) corresponding to 0011 (3 in decimal) is 6 (0110 in binary), so the final 
physical address is: 0110 1100 0010 0000, 
which is 6C20H

(2) Non-hexadecimal example

It is known that a paging system has a page size of 1K (that is, 1024 bytes), and a certain job has 4 pages, which are respectively loaded into the 3rd, 4th, 6th, and 8th blocks of the main memory. Find the corresponding to the logical address 2100 physical address.

Solution:
Step 1: Find the page number of the logical address = 2100 / 1024=2 (divisible)
Step 2: Find its offset within the page = 2100 % 1024 =52 (take the remainder)
Step 3: According to the topic Generate page table:
page number page frame number/frame number
   0 3
   1 4
   2 6 
   3 8
Step 4: find out the page frame number/frame number of the physical address according to the page number of the logical address: 
as shown in the figure above, the second of the logical address The page corresponds to block 6 of the physical address.
Step 5: Find the physical address = 6*1024 + 52 = 6196

Guess you like

Origin blog.csdn.net/Jiang5106/article/details/128445304