-
Notifications
You must be signed in to change notification settings - Fork 0
/
getType.py
96 lines (88 loc) · 1.83 KB
/
getType.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# This function looks at the opCode and returns the type of the function.
from printColor import printColor
from writeToFile import writeToFile
def getType(inst):
rType = [
"AND",
"SUBU",
"MFLO",
"MFHI",
"SLTU",
"ADDU",
"XOR",
"SUB",
"ADD",
"NOR",
"SRLV",
"SRAV",
"DIVU",
"MULT",
"SRA",
"SLT",
"SLLV",
"SRL",
"SLL",
"MTLO",
"MTHI",
"DIV",
"OR",
"MULTU",
"MOVE",
"NEGU",
"NOT",
"MOVN",
"MOVZ",
]
iType = [
"ADDI",
"LW",
"SW",
"SUBI",
"SLTI",
"BLEZ",
"MULTI",
"BNE",
"BEQ",
"BGTZ",
"BLT",
"LI",
"ORI",
"ANDI",
"XORI",
]
opcode = {
# R - TYPE
# ALL THE R TYPE HAVE 000000 OPCODE.
# I - TYPE
"ADDI": "001000",
"SLTI": "001010",
"LW": "100011",
"SW": "101011",
"BEQ": "000100",
"BGTZ": "000111",
"BNE": "000101",
"BLEZ": "000110",
"BLT": "100011",
"BLTZ": "000001",
"LI": "001001",
"ORI": "001101",
"ANDI": "001100",
"XORI": "001110",
"SUBI": "001000",
"CLO": "",
# J - TYPE
"J": "000010",
}
if inst.upper() in rType:
printColor("000000", "yellow")
writeToFile("000000")
return "R"
if inst.upper() in iType:
printColor(opcode[inst.upper()], "yellow")
writeToFile(opcode[inst.upper()])
return "I"
if inst.upper() == "J":
printColor(opcode["J"], "yellow")
writeToFile(opcode["J"])
return "J"
raise Exception("Invalid OpCode : {0}".format(inst))