-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path8to16.py
executable file
·44 lines (36 loc) · 930 Bytes
/
8to16.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
#!/usr/bin/env python3
import sys
import os
def listBig16(input):
array = []
cnt = 0
with open(input, 'r') as f:
l = f.readlines()
for i in l:
a = i.split()
for j in a:
if (cnt % 2 == 0):
array.append(j)
else:
array.insert(-1, j)
cnt += 1
return array
def mifGen(input):
addr = 0x0
array = listBig16(input) # convert to big endian
cnt = 0
buf = ''
for i in array:
if (addr != 0) and ((addr % 8 == 0) and cnt % 2 == 0):
buf += f'\n'
if ((cnt % 2) == 1):
buf += f'{i} '
addr += 1
else:
buf += f'{i}'
cnt += 1
with open(os.path.splitext(os.path.basename(input))[0] + ".mem", 'w') as f:
f.write(buf)
if __name__ == "__main__":
input = sys.argv[1]
mifGen(input)