-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexecutionModule.sv
More file actions
168 lines (154 loc) · 4.69 KB
/
Copy pathexecutionModule.sv
File metadata and controls
168 lines (154 loc) · 4.69 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
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
`timescale 1ns / 1ps
//////////////////////////////////////////////////////////////////////////////////
// Company:
// Engineer:
//
// Create Date: 10/07/2025 08:54:43 AM
// Design Name:
// Module Name: executionModule
// Project Name:
// Target Devices:
// Tool Versions:
// Description:
//
// Dependencies:
//
// Revision:
// Revision 0.01 - File Created
// Additional Comments:
//
//////////////////////////////////////////////////////////////////////////////////
module Execution(Clk, DataBus, address, nRead, nWrite, nReset);
input logic Clk, nReset;
inout logic [255:0] DataBus;
output logic nRead, nWrite;
output logic [15:0] address;
logic driveEn, passThrough;
logic [3:0][7:0] instruction;
logic [15:0] instructionAddress;
logic [255:0] DataBuffer;
logic [7:0][255:0] InternalReg;
assign DataBus = driveEn ? DataBuffer : 'z;
enum{Rst,RdInst,RdS1,RdS2,WrS1,WrS1_1,WrS2,WrSI,WrSI_1,WfR,RdRs,WrRs} state, nextstate;
enum{iALU,mALU,bALU,STOP} op;
initial begin
nRead = 1;
nWrite = 1;
address = 0;
driveEn = 0;
DataBuffer = 'z;
instruction = 'z;
instructionAddress = 0;
passThrough = 0;
end
always_ff @ (posedge Clk or negedge nReset) begin
if (!nReset)
state = Rst;
else
state = nextstate;
end
always_comb begin
case (state)
Rst: begin
nextstate = RdInst;
instructionAddress = 0;
nRead = 1;
nWrite = 1;
driveEn = 0;
end
RdInst: begin
nWrite = 1;
driveEn = 0;
address = 'h1000+instructionAddress;
nRead = 0;
instruction = DataBus;
nextstate = RdS1;
case (instruction[3][7:4])
'h0: op = mALU;
'h1: op = iALU;
'h2: op = bALU;
'hf: op = STOP;
default: op = op;
endcase
if (op == STOP)
$stop;
end
RdS1: begin
if (instruction[1][7:4])
InternalReg[7] = InternalReg[instruction[1][3:0]];
else begin
address = (instruction[1][6:0] + ( instruction[1][7:6] ? 'h4000 : 0 ));
InternalReg[7] = DataBus;
end
nextstate = RdS2;
end
RdS2: begin
if (instruction[3] == 'h07)
InternalReg[6] = instruction[0];
else if (instruction[0][7:4])
InternalReg[6] = InternalReg[instruction[0][3:0]];
else begin
address = (instruction[0][6:0] + ( instruction[0][7:6] ? 'h4000 : 0 ));
InternalReg[6] = DataBus;
end
nextstate = WrS1;
end
WrS1: begin
nRead = 1;
address = ( op == iALU || op == bALU ? 'h3000 : 'h2000 );
nextstate = WrS1_1;
end
WrS1_1: begin
DataBuffer = InternalReg[7];
driveEn = 1;
nWrite = 0;
nextstate = WrS2;
end
WrS2: begin
address = ( op == iALU || op == bALU ? 'h3001: 'h2001 );
DataBuffer = InternalReg[6];
nextstate = WrSI;
end
WrSI: begin
address = ( ( op == iALU || op == bALU ? 'h3E00 : 'h2E00));
DataBuffer = ( ( op == iALU || op == bALU ? 'h3000 : 'h2000) + ( ( op == bALU ? instruction[3][3:0] + 'hA : instruction[3][3:0] + 1 ) << 8 ) );
nextstate = WfR;
end
WfR: begin
nWrite = 1;
driveEn = 0;
address = ( ( op == iALU || op == bALU ? 'h3F00 : 'h2F00 ) );
nRead = 0;
if (DataBus) begin
nextstate = RdRs;
end else
nextstate = WfR;
end
RdRs: begin
address = ( ( op == iALU || op == bALU ? 'h3D00 : 'h2D00));
InternalReg[5] = DataBus;
nextstate = WrRs;
end
WrRs: begin
if (op != bALU) begin
if (instruction[2][7:4])
InternalReg[instruction[2][3:0]] = InternalReg[5];
else begin
nRead = 1;
address = (instruction[2][6:0]);
DataBuffer = InternalReg[5];
driveEn = 1;
nWrite = 0;
end
instructionAddress = instructionAddress + 1;
end else begin
if (InternalReg[5])
instructionAddress = instructionAddress + instruction[2];
else
instructionAddress = instructionAddress + 1;
end
nextstate = RdInst;
end
endcase
end
endmodule