From 604f8e208790f7dda06e8bada7f58255962cbb75 Mon Sep 17 00:00:00 2001 From: Ronan Souza Date: Tue, 28 May 2019 12:10:34 -0300 Subject: [PATCH 1/2] Implements script to generate random virtual addresses --- lab_mem/memory_management/genAddrs.py | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 lab_mem/memory_management/genAddrs.py diff --git a/lab_mem/memory_management/genAddrs.py b/lab_mem/memory_management/genAddrs.py new file mode 100644 index 0000000..fcf9215 --- /dev/null +++ b/lab_mem/memory_management/genAddrs.py @@ -0,0 +1,9 @@ +import sys, os + +n = int(sys.argv[1]) + +for i in range(n): + addr = os.urandom(4).hex() + sys.stdout.write(addr+"\n") + +sys.stdout.write("-1") From 94a7837c2225696b1cd1fe3842b5b407ac1cfb17 Mon Sep 17 00:00:00 2001 From: Ronan Souza Date: Tue, 28 May 2019 12:14:05 -0300 Subject: [PATCH 2/2] Implements a mapper with a function to process all addresses --- lab_mem/memory_management/Mapper.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 lab_mem/memory_management/Mapper.py diff --git a/lab_mem/memory_management/Mapper.py b/lab_mem/memory_management/Mapper.py new file mode 100644 index 0000000..a409d25 --- /dev/null +++ b/lab_mem/memory_management/Mapper.py @@ -0,0 +1,14 @@ +import sys + +class Mapper: + + def processAddrs(self): + for line in sys.stdin: + v_addr = int(line, 16) + if v_addr < 0: + return + address, n_page_faults = self.map(v_addr) + sys.stdout.write(str(address)+" "+str(n_page_faults)+"\n") + + def map(self, addr): + return (addr, 0)