forked from smith-wsh/MIPS_op
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMicro_control.py
84 lines (62 loc) · 1.87 KB
/
Micro_control.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
CM = bytearray([0] * 4)
def op_cover(a, b):
for i in range(len(a)):
a[i] = b[i]
def op_plus(a, b, c):
global OF
OF = 0
for i in range(len(a)):
temp = b[i] + c[i] + OF
OF = 0
if temp > 255:
OF = 1
a[i] = temp - 256
else:
a[i] = temp
def bin_dec(a):
num = 0
for i in range(len(a)):
num = num + a[i] * (256 ** i)
return num
def dec_bin0(a, num):
for i in range(len(a)):
a[i] = num % 256
num = num >> 8
def mult_collect(K_flag, IR, uIR):
a = bytearray([0] * 4)
if K_flag:
for i in range(len(a)):
a[i] = IR[i]
else:
for i in range(len(a)):
a[i] = uIR[i]
return a
class Micro_control:
def __init__(self):
self.__ready = 0
self.uPC = bytearray([0] * 4)
self.uIR = bytearray([0] * 4)
self.K_flag = 1
def run(self, IR, ALU, SBUS, MMBUS, signal_control_in, signal_control_out):
# 第一步 模拟中断控制,更新uPC,uIR,uAR寄存器
# 第二步 输出状态控制流。并进入准备态
# 第三步 模拟中断控制,更新uPC,uIR,uAR寄存器
self.uAR = mult_collect(self.K_flag, IR, self.uIR)
instruct = CM[bin_dec(self.uAR)]
self.uIR = instruct[0]
signal_control_in['AR'] = 1
signal_control_out['AR'] = 1
SBUS[0].append('AR')
SBUS[0].append('32')
SBUS[0].append('DR')
SBUS[1].append(bytearray([1, 0, 0, 0]))
MMBUS[1].append('DR-MM')
self.__ready = 1
def final(self):
return self.__ready
def final_reset(self):
self.__ready = 0
def K_start(self):
return self.K_flag
def K_start_reset(self):
self.K_flag = 1