Answered step by step
Verified Expert Solution
Question
1 Approved Answer
/ / Implement LRU page replacement algorithm for the page table / / Implement FIFO page replacement algorithm for the TLB #include #include #include #include
Implement LRU page replacement algorithm for the page table
Implement FIFO page replacement algorithm for the TLB
#include
#include
#include
#include
#define PAGES
#define PAGEMASK
#define PAGESIZE
#define OFFSET
#define OFFSETMASK
#define FRAMESIZE
#define BUFFERSIZE
int main int argc, char argv
FILE addressesFile fopenargvr;
FILE backingStore fopenBACKINGSTORE.bin", rb;
FILE outputFile fopenoutputParttxtw;
int pageTablePAGES;
int tlb;
int totalAddresses pageFault tlbHits frames atoiargv;
char bufferBUFFERSIZE; Buffer for reading logical addresses from file
signed char memoryFRAMESIZE frames; Physical memory
unsigned char freePage ; Free page is the next frame to be used for page replacement in the page table and TLB
Initialize page table
for int i ; i PAGES; i
pageTablei;
Initialize TLB
for int i ; i ; i
tlbi;
tlbi;
Use FirstInFirstOut FIFO for page replacement in the TLB
int fifo ;
Read logical addresses from file
while fgetsbuffer BUFFERSIZE, addressesFile NULL
int logicalAddress atoibuffer;
int pageNumber logicalAddress OFFSET & PAGEMASK;
int offset logicalAddress & OFFSETMASK;
int frameNumber ;
int tlbIndex ;
Check TLB
for int i ; i ; i
if tlbi pageNumber
frameNumber tlbi;
tlbIndex i;
tlbHits;
break;
TLB miss
if frameNumber
Check page table
frameNumber pageTablepageNumber;
Page fault
if frameNumber
pageFault;
Load page from backing store
fseekbackingStore pageNumber PAGESIZE, SEEKSET; Seek to page number in backing store file
freadmemory freePage FRAMESIZE, sizeofsigned char FRAMESIZE, backingStore; Load page into free frame
frameNumber freePage; Update frame number
pageTablepageNumber frameNumber; Update page table
freePage freePage frames; Increment free page
Update TLB
tlbfifo pageNumber;
tlbfifo frameNumber;
fifo fifo ;
int physicalAddress frameNumber OFFSET offset;
signed char value memoryframeNumber FRAMESIZE offset;
fprintfoutputFile "Virtual address: d Physical address: d Value: d
logicalAddress physicalAddress, value;
totalAddresses;
fprintfoutputFile "Number of Translated Addresses d
totalAddresses;
fprintfoutputFile "Page Faults d
Page Fault Rate f
pageFault, floatpageFault totalAddresses;
fprintfoutputFileTLB Hits d
TLB Hit Rate f tlbHits, floattlbHits totalAddresses;
fcloseaddressesFile;
fclosebackingStore;
fcloseoutputFile;
return ;
The code above is meant to take in a logical address and output the physical address and corresponding value using a page table and tlb The page table above uses FIFO.
Please edit the above code so that the page table uses LRU, instead of FIFO and the tlb uses FIFO.
The output should be correct like this when the number of frames :
Virtual address: Physical address: Value:
Virtual address: Physical address: Value:
Virtual address: Physical address: Value:
Virtual address: Physical address: Value:
Virtual address: Physical address: Value:
Virtual address: Physical address: Value:
Virtual address: Physical address: Value:
Virtual address: Physical address: Value:
Virtual address: Physical address: Value:
Virtual address: Physical address: Value:
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started