-
Notifications
You must be signed in to change notification settings - Fork 0
/
ControlUnit.py
84 lines (73 loc) · 2.03 KB
/
ControlUnit.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
import opcodes
class MainControl:
def __init__(self):
self.PCSrc = '00'
self.RegDst = 0
self.ALUSrc = 0
self.MemtoReg = 0
self.RegWrite = 0
self.MemRead = 0
self.MemWrite = 0
self.Branch = 0
self.Jump = 0
self.IFFlush = 0
self.IDFlush = 0
self.EXFlush = 0
self.aluop = ''
def update(self, opcode):
self.PCSrc = '00'
if opcode == opcodes.RFORMAT:
self.PCSrc = '00'
self.RegDst = 1
self.ALUSrc = 0
self.MemtoReg = 0
self.RegWrite = 1
self.MemRead = 0
self.MemWrite = 0
self.Jump = 0
self.aluop = '1x'
elif opcode == opcodes.LW:
self.PCSrc = '00'
self.RegDst = 0
self.ALUSrc = 1
self.MemtoReg = 1
self.RegWrite = 1
self.MemRead = 1
self.MemWrite = 0
self.Branch = 0
self.Jump = 0
self.aluop = '00'
elif opcode == opcodes.SW:
self.PCSrc = '00'
self.ALUSrc = 1
self.RegWrite = 0
self.MemRead = 0
self.MemWrite = 1
self.Jump = 0
self.aluop = '00'
elif opcode == opcodes.BEQ:
self.PCSrc = '10'
self.ALUSrc = 0
self.RegWrite = 0
self.MemRead = 0
self.MemWrite = 0
self.IFFlush = 1
self.Jump = 0
self.aluop = 'x1'
elif opcode == opcodes.SLT:
self.PCSrc = '00'
self.RegDst = 1
self.ALUSrc = 0
self.MemtoReg = 0
self.RegWrite = 1
self.MemRead = 0
self.MemWrite = 0
self.Jump = 0
self.aluop = '1x'
elif opcode == opcodes.J:
self.PCSrc = '10'
self.RegWrite = 0
self.MemRead = 0
self.MemWrite = 0
self.Branch = 0
self.Jump = 1