2
$\begingroup$

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:

  • The logical address: $717$

  • Logical memory size: $1024$ bytes ($4$ pages)

  • Page Table:

\begin{array}{| c | c |} \hline Page\ Number & Frame\ Number\\ \hline 0 & 5\\ \hline 1 & 2\\ \hline 2 & 7\\ \hline 3 & 0\\ \hline \end{array}

  • 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 $4096$, right? ($256 \times 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$ ($\frac{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 \times 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?

$\endgroup$
  • $\begingroup$ Better for the main stackexchange. $\endgroup$ – Yuval Filmus Jan 4 '13 at 0:08
  • $\begingroup$ 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. $\endgroup$ – Ciaran Gallagher Jan 4 '13 at 0:11
6
$\begingroup$

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., $$\frac{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 \times 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 $$\frac{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 \times page\_size + offset = 2 \times 256 + 252 = 764$$

$\endgroup$
  • $\begingroup$ 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?? $\endgroup$ – Sudip Das May 31 '16 at 20:58
-1
$\begingroup$
  • offset = 717%256 = 205
  • page no = 717/256 = 2.__ = 2
  • frame no = 7
  • physical address = 7*256 + 205
$\endgroup$
  • 7
    $\begingroup$ Um, maybe. Your answer would be more useful if you explained where these numbers come from. $\endgroup$ – Gilles Nov 19 '13 at 9:58
-1
$\begingroup$

page no =717/256=2._ (page no 2. since logical memory is divided into 4 pages (0-3))

offset = 717%256=205 (205th byte in page no 2)

frame no=7 (from page table)

physical memory also is divided into 16 equal frames of size 256 bytes

physical address=(7*256)+205=1997

$\endgroup$
  • $\begingroup$ This is only some calculations without any explanation; I don't think that makes for a helpful answer. $\endgroup$ – Raphael Nov 8 '16 at 17:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.