-
Notifications
You must be signed in to change notification settings - Fork 1
/
load.py
47 lines (35 loc) · 1 KB
/
load.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
40
41
42
43
44
45
46
47
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import sys
__appname__ = ""
__author__ = "Marco Sirabella"
__copyright__ = ""
__credits__ = ["Marco Sirabella"] # Authors and bug reporters
__license__ = "GPL"
__version__ = "1.0"
__maintainers__ = "Marco Sirabella"
__email__ = "[email protected]"
__status__ = "Prototype" # "Prototype", "Development" or "Production"
__module__ = ""
halt = 0b000000
arch = 4
ram = [(halt, 0b00)] * arch ** 2
def load(filename):
file = open(filename, 'r')
contents = file.read()
begin = True
for line in contents.splitlines():
words = line.split()
#print(words[0] + ' : ' + words[1])
addr = int(words[0], 2)
data = words[1]
assert len(data) == arch*2
instruction = int(data[:arch], 2)
pointer = int(data[arch:], 2)
data = (instruction, pointer)
ram[addr] = data
def main():
load(sys.argv[1])
print(ram)
if __name__ == '__main__':
main()