Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Hey guys, i\'m having trouble understanding the program im supposed to write in

ID: 3550576 • Letter: H

Question

Hey guys, i'm having trouble understanding the program im supposed to write in C++. I need to read a file of integers that represent virtual memory and then I translate those addresses to physical memory addresses using a page table and translation lookaside buffer. If someone could help me write this code I would lose so much stress!


Im reading in a file containing intergers as follows:

63987

32256

41413

48870

40282

14498

62738

64859

25437

9606

14533

25499

25920

1981

48202

15518

34908

35365

30861

30258


Each of these integers represent a virtual address. I need to write a page table function that translates the virtual adress to a physical address. as shown below

Explanation / Answer

// This program generates the same result except the Value

// I don't know what the Value mean?


#include <iostream>

#include <fstream>


using namespace std;




int main()

{

ifstream infile("H:\toup\chegg\virtual.txt");

int vaddr = 0;

int tlb[256] = {0};

int number = 0;

int missed = 0;

int allocated = 0;


for (int i = 0; i < 256; i++)

tlb[i] = -1;


while (infile >> vaddr)

{

int offset = vaddr % 256;

int left = vaddr / 256;


if (tlb[left] == -1)

{

missed++;

tlb[left] = allocated++;

}

int paddr = (tlb[left] * 256+offset);

cout << "Virtual address: " << vaddr << " Physical address: " << paddr << endl;


number++;

}



cout << "Number of Translated Addresses = " << number << endl;

cout << "Page faults = " << missed << endl;

cout << "Page Fault Rate = " << (missed / (double)number) << endl;

cout << "TLB hits = " << (number-missed) << endl;

cout << "TLB Hit Rate = " << ((number-missed)/(double)number) << endl;

return 0;

}