-
Notifications
You must be signed in to change notification settings - Fork 2
/
assembler.py
47 lines (32 loc) · 929 Bytes
/
assembler.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
import maplist
import re
import pass1
import translation
import predefExpand
import macroExpand
print "Enter file name: "
file_name = raw_input()
temp = file(file_name)
code = temp.read()
lines = code.split("\n")
temp.close()
for i in range(len(lines)):
lines[i] = lines[i].lstrip().rstrip().upper()
print "Enter language of the file: "
language_input = raw_input ()
lines=macroExpand.macroExpand(lines)
lines=predefExpand.predefExpand(lines)
lines = translation.translate(language_input,lines)
for line in lines:
print line
symboltable, length = pass1.pass1(lines)
lines = pass1.out(symboltable,lines)
print lines
temp1 = file(file_name.split('.')[0]+'1.txt', 'w')
for line in lines:
temp1.write(line+'\n')
temp1.write('#\n')
for key in symboltable:
temp1.write(key + "$" + str(symboltable[key][0]) + "$" +str(symboltable[key][1]) + "\n")
temp1.write("#\n" + str(length) + "\n")
temp1.close()