0% found this document useful (0 votes)
85 views3 pages

Virtual Memory Simulator: Teacher: Abelardo López

This document describes a virtual memory simulator that reads memory references from a file and simulates memory access. It defines data structures to represent TLB entries and references read from the file. It also defines functions to read references from the file, get the page number from a reference, search and replace entries in the TLB, find the least recently used TLB entry, and get a frame from memory. The algorithm simulates virtual memory using these components.

Uploaded by

Roberto Antelo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
85 views3 pages

Virtual Memory Simulator: Teacher: Abelardo López

This document describes a virtual memory simulator that reads memory references from a file and simulates memory access. It defines data structures to represent TLB entries and references read from the file. It also defines functions to read references from the file, get the page number from a reference, search and replace entries in the TLB, find the least recently used TLB entry, and get a frame from memory. The algorithm simulates virtual memory using these components.

Uploaded by

Roberto Antelo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

!"#$%&' )*+,#- .

"+%'&$,#
1eacher: Abelardo Lpez
[AuLor]
/.0123450/.6
8oberLo AnLelo - A01203237 ---- Marcelo Cmez - A00810922


2*78#"9$",:

;<=*8$">*
This piogiam simulates a viitual memoiy managei, ieauing a file with memoiy
iefeiences.

?#,<'*+ .$&$*+*:$
The simulatoi ieaus a memoiy tiace fiom a file anu then simulates the memoiy access
in the system. It consists of a TLB (Tianslation Lookaheau Buffei), a page table anu a
block of memoiy.
The piogiams output shows the total numbei of TLB misses, page faults of uisk ieaus
anu wiites, total numbei of memoiy fiames useu anu the aveiage access time of the
all tiace.
The fiist line of the file contains thiee numbeis. The fiist one iepiesents the main
memoiy access time, the seconu numbei the TLB access time anu the thiiu one
iepiesents the page fault penalty.
The following lines contain a 16bit auuiess anu the access type (R oi W).

?#,9,7*@ .,'%$",:

2&$& .$#%8$%#*7
Fiist of all, we uefineu the uata stiuctuie that we use to iepiesent the TLB entiy anu
the Refeiences ieau fiom the file. The stiuctuie is uefineu as follows:

// Enum for the different types of access and frame states (write,
read, clean, dirty)
typedef enum accessType {I = -1,V,W,R,C,D} accessType;

// Data structure for the references read from the input file
typedef struct Reference{
int address; //The 16bits address
accessType accessType; //Could be R for Read and W for Write
} Reference;

// Data structure for the entries of the TLB
typedef struct TLBEntry{
int pageNum; //The number of the current page
int frameNum; //The number of the current frame
int lru; //Least recently used number
accessType state; //The state on entry.
} TLBEntry;
A%:8$",:7
Then we uefineu the following functions:
B*$C*D*#*:8*EA3F/ GH
This function ieaus the file anu ietuins the auuiess anu access type encapsulateu in
the stiuctuie iefeience.
B*$?&I*EC*D*#*:8*H
This function ieceives the iefeience anu ietuins the page numbei.
To get the page numbei, we applieu a 9 bits shift on the auuiess containeu in the
iefeience.
373:0&<'*E0FJ/:$#- GK ":$K ":$H
The function ieceives the TLB entiy, an integei with the value anu anothei with the
TLB size.
The function seaich in the table the value anu ietuins the inuex if its founu. If not
founu ietuins -1.
A":@FC1E0FJ/:$#- GK ":$H
This function ieceives the TLB entiy anu the TLB size. It compaies in the TLB the LR0
(Least Resently 0seu numbei) anu ietuins an integei with the smallei LR0.
B*$A#&+*EH
The function ietuins a numbei iepiesenting a fiame. It veiifies that the memoiy can
piopoitionate a fiame anu if not, ietuins -1.
4'I,#"$L+
Then we uefineu the algoiithm to
simulate the viitual memoiy.
The algoiithm is uefineu as follows in
the image:

You might also like