Translate virtual address to physical address

So the physical address is 20 bits, or 16 + 4, or 0x14. In summary, the physical address is 20 bits long, with the lower 9 bits representing the offset within a page, and the upper 11 bits representing the physical page number.
  • #1
naspek
181
0

Homework Statement



A virtual memory system has a page size of 512 bytes, seven virtual pages, and four
physical page frames. The page table is as follows:
VPN...PFN
0.....2
1.....0
2.....-
3.....1
4.....3
5.....-
6.....-
Note: VPN -> Virtual Page Number, PFN -> Page Frame Number


What physical address, if any, would each of the following virtual addresses
correspond to?
i. 0
ii. 2010
iii. 2046
iv. 3030
v. 1026

The Attempt at a Solution



i. 0============ 0000 0000 0000
ii. 2010========= 0111 1101 1010
iii. 2046========= 0111 1111 1110
iv. 3030======== 1011 1101 0110
v. 1026======== 0100 0000 0010

i've translate it to binary number already..
but.. i don't how to proceed..
can someone please guide me..
 
Physics news on Phys.org
  • #2
naspek said:

Homework Statement



A virtual memory system has a page size of 512 bytes, seven virtual pages, and four
physical page frames. The page table is as follows:
VPN...PFN
0.....2
1.....0
2.....-
3.....1
4.....3
5.....-
6.....-
Note: VPN -> Virtual Page Number, PFN -> Page Frame Number


What physical address, if any, would each of the following virtual addresses
correspond to?
i. 0
ii. 2010
iii. 2046
iv. 3030
v. 1026

The Attempt at a Solution



i. 0============ 0000 0000 0000
ii. 2010========= 0111 1101 1010
iii. 2046========= 0111 1111 1110
iv. 3030======== 1011 1101 0110
v. 1026======== 0100 0000 0010

i've translate it to binary number already..
but.. i don't how to proceed..
can someone please guide me..

I don't think converting the virtual address to binary is much help. I'm not certain, but I think what you need to do is to find the virtual page number for each virtual address, and then see which physical page that VPN is mapped to.

To do this, divide the virtual address by 512 using integer division. For example, your second virtual address is 2010. 2010/512 == 3, so the virtual page number is 3. From the information you provided, virtual page 3 maps to physical page 1.
 
  • #3
Mark44 said:
I don't think converting the virtual address to binary is much help. I'm not certain, but I think what you need to do is to find the virtual page number for each virtual address, and then see which physical page that VPN is mapped to.

To do this, divide the virtual address by 512 using integer division. For example, your second virtual address is 2010. 2010/512 == 3, so the virtual page number is 3. From the information you provided, virtual page 3 maps to physical page 1.

thanks for the idea..

now.. i proceed...

ii. 2010===== 2010/512
==========3.93 = 3 , virtual page number 3 maps to physical page 1..
but.. how do i get the physical address then?
 
  • #4
The remainder (or modulus) gives you the offset in the memory page. In C notation, this is 2010 % 512 == 474. In mathematical notation, this is 2010 (mod 512) = 474.
 
  • #5
Mark44 said:
The remainder (or modulus) gives you the offset in the memory page. In C notation, this is 2010 % 512 == 474. In mathematical notation, this is 2010 (mod 512) = 474.
get it.. then i need to change 474 to binary number to get my physical address?
 
  • #6
I don't see why you would need to do that. It's just an address. It could be 474 (decimal) or 1DA (hex) or 111011010 (binary). These all represent the same number, but in different bases.
 
  • #7
Mark44 said:
I don't see why you would need to do that. It's just an address. It could be 474 (decimal) or 1DA (hex) or 111011010 (binary). These all represent the same number, but in different bases.
thanks for the clarification.. but..
why do i need the table if, i can just do the calculation(divide by 512 and get the answer already)..?
 
  • #8
There's an important part you're missing. Rather than me telling you what it is, I will let you figure it out.

If the virtual address is 2010, what is the physical address?
 
  • #9
Mark44 said:
There's an important part you're missing. Rather than me telling you what it is, I will let you figure it out.

If the virtual address is 2010, what is the physical address?

the physical address is 0001 1101 1010.. right?
 
  • #11
Mark44 said:
How did you get that?
2010 mod 512 = 474

i change 474 into 12 bits binary number.. so.. i get 0001 1101 1010.. right?
 
  • #12
The 474 is just the offset within the page, but which page are we talking about? And by that, I mean, which physical page?
 
  • #13
Mark44 said:
The 474 is just the offset within the page, but which page are we talking about? And by that, I mean, which physical page?

ok... so..

VPN...PFN
3.....1

it's on physical page 1.. right?

is it 1 is my physical address? can't be.. too odd...
 
  • #14
Yes, physical page 1. That's where the table comes in, so that you can translate a virtual page number to a physical page number.

OK, you have physical page 1, and an offset of 447. What's the physical address?
 
  • #15
Mark44 said:
Yes, physical page 1. That's where the table comes in, so that you can translate a virtual page number to a physical page number.

OK, you have physical page 1, and an offset of 447. What's the physical address?

ok... physical page number constitutes the upper portion of the physical address, while the page offset, constitutes the lower portion

so.. my physical address is...

1 | 0001 1101 1010

correct?
 
  • #16
No, that's too big. It would be helpful if you didn't change the numbers into binary. Your physical address is calculated using this formula:
physical address = (physical page number) * 512 + offset
 
  • #17
Mark44 said:
No, that's too big. It would be helpful if you didn't change the numbers into binary. Your physical address is calculated using this formula:
physical address = (physical page number) + offset

ok.. thanks for the formula..

*got question here.. is it [(physical page number)*512] + offset or..
....... (physical page number) * (512 + offset)
the first one or the second formula is correct?

physical address = (1) * 512 + 474
......= 986 @ 0011 1101 1010
now.. this is the correct one?
 
  • #18
It's this one: (physical page number)*512 + offset

And 986 is the correct address.

To check: 986 / 512 = 1
and 986 (mod 512) = 474
 
  • #19
geez! thanks mark44!
but.. if I'm going to answer it in binary number format..
how should i know the number of bits of the physical address?
 
  • #20
The offset is 0 - 511, or 0 - 0x1ff, or 1 1111 1111, so that takes 9 bits.

The physical page number is a multiple of 512 (0, 1, 2, or 3 times 512), so the largest physical address will be 3*512 + 511 = 2047 = 0x7ff, which fits in 11 bits.
 

1. What is the purpose of translating virtual address to physical address?

The purpose of translating virtual address to physical address is to enable the operating system to access and manage the physical memory of a computer. Virtual addresses are used by applications, while physical addresses refer to the actual location of data in the computer's physical memory. Translating virtual addresses to physical addresses allows the operating system to efficiently manage memory and allocate resources to different applications.

2. How does the translation process work?

The translation process involves the use of a memory management unit (MMU), which is a hardware component that maps virtual addresses to physical addresses. The MMU uses a technique called address translation, which involves converting virtual addresses into physical addresses using a page table. The page table is a data structure that contains information about the virtual-to-physical address mappings for a particular process.

3. What happens if there is a translation error?

If there is a translation error, it means that the virtual address being accessed does not have a corresponding physical address. This could occur if the virtual address is invalid or if the page containing the virtual address has been swapped out to disk. In this case, the MMU will generate a page fault, which is an exception that is handled by the operating system. The operating system will then either retrieve the missing page from disk or terminate the process if the virtual address is invalid.

4. Can virtual addresses and physical addresses be the same?

No, virtual addresses and physical addresses cannot be the same. Virtual addresses are used by applications and are managed by the operating system, while physical addresses refer to the actual location of data in the computer's physical memory. The purpose of translating virtual addresses to physical addresses is to ensure that there is no conflict between different applications using the same physical memory.

5. How does virtual memory affect the translation of addresses?

Virtual memory is a memory management technique that allows the operating system to allocate more memory to applications than is physically available. This means that not all virtual addresses will have a corresponding physical address at any given time. The translation process takes this into account by using techniques such as paging and swapping to manage the allocation of physical memory to virtual addresses. This helps to optimize the use of physical memory and allows for more efficient management of resources.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
1
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
5
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
2
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
976
  • Engineering and Comp Sci Homework Help
Replies
3
Views
4K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
2K
  • Programming and Computer Science
Replies
19
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
2
Views
4K
  • Programming and Computer Science
Replies
2
Views
3K
Back
Top