-
Notifications
You must be signed in to change notification settings - Fork 1
/
part1.py
39 lines (33 loc) · 1.87 KB
/
part1.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import part2
def checkTLB(pageNumber, physicalMemory, offset, logicalAddress, tlb, i, outputFile):
for j in range(len(tlb)):
if pageNumber == tlb[j][0]:
print("Page Number \"" + str(pageNumber) + "\" found in TLB!!")
frameNumber = tlb[j][1]
data = part2.readPhysicalMemory(frameNumber, offset, physicalMemory)
physicalAddress = "{0:08b}".format(int(frameNumber)) + "{0:08b}".format(offset)
physicalAddress = int(physicalAddress, 2)
outStr = str(i) + " Virtual address: " + str(logicalAddress) + " Physical address: " + str(
physicalAddress) + " Value: " + data + "\n"
print(str(i) + " Virtual address: " + str(logicalAddress) + " Physical address: " + str(
physicalAddress) + " Value: " + data)
outputFile.write(outStr)
part2.updateTLBCounter(j, tlb)
return 1
return 0
def checkPageTable(pageNumber, logicalAddress, offset, i, pageTable, physicalMemory, outputFile):
for k in range(len(pageTable)):
if pageNumber == pageTable[k][0]:
print("Page Number \"" + str(pageNumber) + "\" found in page table!!")
frameNumber = pageTable[k][1]
data = part2.readPhysicalMemory(frameNumber, offset, physicalMemory)
physicalAddress = "{0:08b}".format(int(frameNumber)) + "{0:08b}".format(offset)
physicalAddress = int(physicalAddress, 2)
outStr = str(i) + " Virtual address: " + str(logicalAddress) + " Physical address: " + str(
physicalAddress) + " Value: " + data + "\n"
print(str(i) + " Virtual address: " + str(logicalAddress) + " Physical address: " + str(
physicalAddress) + " Value: " + data)
outputFile.write(outStr)
part2.updatepageTableCounter(k, pageTable)
return 1
return 0