## Computer Systems/Virtual Memory :: 05-11-2018

### Practice Problem 9.3

For this problem we need the following id's $P = 2^p$ and $VPO = PPO = p$ where $PPO = VPO$ since virtual and physical pages are same size. We know that $n = 64$ and $m = 32$ as these are stated in the assignment.

Furthermore, as seen in Figure 9.12 on page 851, we know that $VPN = n - 1 - (p - 1)$, $VPO = PPO = p - 1 + 1$ (plus one since we index starting at 0), $PPN = m - 1 - (p - 1)$.

P | VPN | VPO | PPN | PPO |

1KB | 64 - 10 = 54 | p = log_{2}(P) = 10 | 32-10 = 22 | 10 |

2KB | 64 - 11 = 53 | p = log_{2}(P) = 11 | 32 - 11 = 21 | 11 |

4KB | 64 - 12 = 52 | p = log_{2}(P) = 12 | 32 - 12 = 20 | 12 |

16KB | 64 - 14 = 50 | p = log_{2}(P) = 14 | 32 - 14 = 18 | 14 |

### Practice Problem 9.4

For this problem we are given a model described through pages 858-860. Furthermore we are given the virtual address $VA = 0x03d7$. To fit this address to our model it might be a good idea to break it down into bits. We have $3 = 0011$, $d = 1101$ and $7 = 0111$. Fitting to the model we get
$$ 00.0011.1101.0111 $$
given that the address is 14 bits long. From that we can extract the values
$$
VPN = 0000.1111 = f \\
VPO = 01.0111 = 17 \\
PPO = VPO = 17 \\
TLBT = 00.0011 = 3 \\
TLBI = 11
$$
Now we can read $set = 3$ and $Tag = 03$ from the TLB in the book (a). This is a hit, we get the value $PPN = 0D$. We insert that into the PA layout: $PA = 0011.0101.0111$. We already know the $PPO$. We can extract the following values
$$
CT = PPN = 1101 = d \\
CI = 0101 = 5 \\
CO = 11 = 3
$$
Translating into the table we have that $Idx = CI = 5$, $Tag = CT = d$ and $Offset = CO = 3$. Since the tag under Idx = 3 matches our CT, we have a hit. And we read with offset 3 the value $1D$.