-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnewAssembler.py
More file actions
41 lines (26 loc) · 1.46 KB
/
newAssembler.py
File metadata and controls
41 lines (26 loc) · 1.46 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
###################
#Faisal Alnahhas #
# Assembler #
# CSO 2016 #
###################
symbols={"SP": 0, "LCL": 1, "ARG": 2, "THIS":3, "THAT": 4,
"R0":0, "R1" : 1, "R2":2, "R3":3, "R4":4, "R5":5,
"R6":6, "R7":7, "R8":8, "R9":9, "R10":10, "R11":11,
"R12":12, "R13":13, "R14":14, "R15":15,
"SCREEN": 16384, "KBD": 24576}
comp_a0_a1 = { '0':'0101010', '1':'0111111', '-1':'0111010', 'D':'0001100',
'A':'0110000', '!D':'0001101', '!A':'0110001', '-D':'0001111',
'-A':'0110011', 'D+1':'0011111','A+1':'0110111','D-1':'0001110',
'A-1':'0110010','D+A':'0000010','D-A':'0010011','A-D':'0000111',
'D&A':'0000000','D|A':'0010101',
'M':'1110000', '!M':'1110001','-M':'1110011',
'M+1':'1110111','M-1':'1110010','D+M':'1000010','D-M':'1010011','M-D':'1000111',
'D&M':'1000000', 'D|M':'1010101' }
dest = {"null":'000', "M":'001', "D":'010', "MD":'011', "A":'100', "AM":'101', "AD":'110', "AMD":'111'}
jump = {"null":'000', "JGT":'001', "JEQ":'010', "JGE":'011', "JLT":'100',
"JNE":'101', "JLE":'110', "JMP":'111'}
def readfile():
fin = open(input("""Choose a .asm file that you want to translate. Make sure
that both files are in the same directory """))
asmFile = fin.readlines()
fin.close()