This repository has been archived by the owner on May 9, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fetch.py
140 lines (118 loc) · 2.7 KB
/
fetch.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
from declarations import *
from bitstring import BitArray
def fetch():
#Control Signals
global Branch
global MemRead
global MemtoReg
# ALUOp
global MemWrite
global ALUSrc1
global ALUSrc2
global PCSrc
global PCReg #Signal if the PC is updated by the Register value
#Register File inputs and Outputs
global RegWrite
global ReadData1
global ReadData2
global ReadRegister1
global ReadRegister2
global WriteRegister
global WriteDataRegFile
#Immediate Generation
global ImmGenOutput
#ALU Control
global ALUControl
#ALUinputs
global ALU_input1
global ALU_input2
#PC
global PC
#Instruction Memory
global ReadAddress
global Instruction
#ALU output
global Zero
global LessThan
global GE
global ALUResult
#Data Memory
global Address
global WriteData
global ReadData
#Registers
global reg_file
#clock
global clock
#TempMem
global TempMem
#Exit
global EXIT
if(PCReg == 1):
PC = ALUResult
elif(PCSrc == 0):
PC = PC + 4
elif(PCSrc == 1):
PC = PC + ImmGenOutput << 1
ReadAddress = PC
Instruction = "{:032b}".format(int(read_word(ReadAddress),16))
print("ReadAddress " + str(ReadAddress))
print("Instruction " + '0x' + read_word(ReadAddress))
def execute():
#Control Signals
global Branch
global MemRead
global MemtoReg
# ALUOp
global MemWrite
global ALUSrc1
global ALUSrc2
global PCSrc
global PCReg #Signal if the PC is updated by the Register value
#Register File inputs and Outputs
global RegWrite
global ReadData1
global ReadData2
global ReadRegister1
global ReadRegister2
global WriteRegister
global WriteDataRegFile
#Immediate Generation
global ImmGenOutput
#ALU Control
global ALUControl
#ALUinputs
global ALU_input1
global ALU_input2
#PC
global PC
#Instruction Memory
global ReadAddress
global Instruction
#ALU output
global Zero
global LessThan
global GE
global ALUResult
#Data Memory
global Address
global WriteData
global ReadData
#Registers
global reg_file
#clock
global clock
#TempMem
global TempMem
#Exit
global EXIT
if(PCReg == 1):
PC = ALUResult
elif(PCSrc == 0):
PC = PC + 4
elif(PCSrc == 1):
PC = PC + ImmGenOutput << 1
ReadAddress = PC
Instruction = "{:032b}".format(int(read_word(ReadAddress),16))
print("ReadAddress " + str(ReadAddress))
print("Instruction " + '0x' + read_word(ReadAddress))