-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
45 lines (34 loc) · 1.37 KB
/
main.py
File metadata and controls
45 lines (34 loc) · 1.37 KB
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
40
41
42
43
44
45
from cpu import CPU
INSTRUCTION_INPUT_FILE = "instruction_input.txt"
DATA_INPUT_FILE = "data_input.txt"
def fetch_instructions():
instruction_file = open(INSTRUCTION_INPUT_FILE, 'r')
instructions = instruction_file.readlines()
instructions = list(map(lambda s: s.strip(), instructions))
return instructions
def fetch_data():
data_file = open(DATA_INPUT_FILE, 'r')
data = data_file.readlines()
data = list(map(lambda s: s.strip(), data))
return data
def initialize_memory_bus(cpu):
data_loaded = fetch_data()
for data in data_loaded:
data_parsed = data.split(",")
cpu.write_memory_bus(data_parsed[0], data_parsed[1])
def send_instructions_to_cpu(cpu):
instructions_loaded = fetch_instructions()
for instruction in instructions_loaded:
cpu.parse_instruction(instruction)
my_cpu = CPU()
print("---------------------------------------------------")
print("Welcome to the Python CPU Simulator!")
print("---------------------------------------------------")
print("Initializing Memory Bus from data input file...")
initialize_memory_bus(my_cpu)
print("Memory Bus successfully initialized")
print("---------------------------------------------------")
print("Sending instructions to CPU...")
send_instructions_to_cpu(my_cpu)
print("---------------------------------------------------")
print("Terminating CPU Processing...")