I am looking to calculate the physical address corresponding to a logical address in a paging memory management scheme. I just want to make sure I am getting the calculation right, as I fear I could be wrong somewhere.

So, the data I have is as follows:

• Logical memory size: 1024 bytes (4 pages)

• Page Table (Page number - Frame number):

(0 - 5), (1 - 2), (2 - 7), (3 - 0)

• Physical memory: 16 frames

So, with 1024 bytes in the logical memory, and 4 pages, then each page is 256 bytes.

Therefore, the size of the physical memory must be 4,096, right? (256*16).

Then, to calculate the logical address offset:

1024 mod 717 = 307

Is that how we calculate the offset?

And, we can assume that 717 is in page 2 (1024 / 717 = 2.8)?

So, according to the page table, the corresponding frame number is 3.

And so to get the physical address, we multiply the frame number and page size?

2 * 256 = 768

Then, do we add the offset, like so:

768 + 307 = 1,075

Thank you for taking the time to read. If I don't quite have this correct, would you be able to advise on the correct protocol to calculating this?

-
Better for the main stackexchange. – Yuval Filmus Jan 4 '13 at 0:08
StackOverflow? Their FAQ states that questions should be about code, and should be unique to the profession. I wouldn't regard this question as unique. This site's FAQ says questions are welcome from students of computer science, so this seems appropriate here. – Ciaran Gallagher Jan 4 '13 at 0:11

You are correct in your reasoning that the pages are 256 bytes and that the physical memory capacity is 4096 bytes.

However, there are errors after that.

The offset is the distance (in bytes) relative to the start of the page. I.e., logical_address mod page_size. The bits for this portion of the logical address are not translated (given power of two page size).

The logical (virtual) page number is number of (virtual) page counting from zero. I.e., logical_address / page_size.

As you noted, the physical page is determined by the translation table, indexed using the logical (virtual) address.

Once the physical page number had been found, the physical address of the start of that page is found by multiplying the physical page number by the page size. The offset is then added to determine the precise physical address. I.e., (physical_page_number * page_size) + offset.

So a logical address of, e.g., 508, with 256 byte pages would have an offset of 508 mod 256 = 252. The logical/virtual page number would be 508 / 256 = 1. With the given translation table, logical page 1 translates to the physical page number 2. The physical address would then be physical_page_number * page_size + offset = 2 * 256 + 252 = 764.

-
thanks u sir,it helped me :) – Sudip Das May 31 at 19:39
bt i don't understand how to make page table...can u please explain it ?? page table means (page_no,frame_no)...if it is no given then how do i find frame no?? – Sudip Das May 31 at 20:58
• offset = 717%256 = 205
• page no = 717/256 = 2.__ = 2
• frame no = 7
• physical address = 7*256 + 205
-
Um, maybe. Your answer would be more useful if you explained where these numbers come from. – Gilles Nov 19 '13 at 9:58