1
votes

I'm writing an address translator for my operating system class. I know i'm reading in the virtual address correctly, and that the page number i get is correct (i access the right data) but when i try to figure out what the physical address is I get the wrong physical address.

specs:

  • 2^8 entries in the page table
  • Page size = 2^8 bytes
  • Frame size = 2^8 bytes
  • 256 frames
  • Physical memory = 65,536 bytes (256 frames × 256-byte frame size)

Here's a correct output:

Virtual address: 12107 Physical address: 2635 Value: -46

Here's what i'm getting:

Virtual address: 12107 Physical address: 12107 Value: -46

from my understanding the physical address is equal to (pageNumber * pageSize + pageOffset) everything i have read has said this.

When i get the page number from 12107, i get 47 (left most 8 bits) When i get the offset from 12107, i get 75 (right most 8 bits) (47 * 256 + 75) gets me 12107.

to get the correct output (physical address) the page number needs to be 10 (10 * 256 + 75) gets the correct output 2635.

I have poured over my book and have spent the last few days trying to find out where the heck i've gone wrong but i can't seem to figure it out.

1

1 Answers

0
votes

I figured out what was happening, I had a misunderstanding in my implementation of page tables. I had a page table but no frame table it would be pointing to, the page table was actually completely bypassing that step, so in effect my physical and logical address were the same.

Once i implemented a frame table, and a proper method for populating the frame table i began generating the physical address correctly.