-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcpu.v
More file actions
134 lines (113 loc) · 1.98 KB
/
Copy pathcpu.v
File metadata and controls
134 lines (113 loc) · 1.98 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
module cpu(CLK, RESET, EN_L, Iin, Din, PC, NextPC, DataA, DataB, DataC, DataD, MW);
input CLK;
input RESET;
input EN_L;
input [15:0] Iin;
input [7:0] Din;
output [7:0] PC;
output [7:0] NextPC;
output [7:0] DataA;
output [7:0] DataB;
output [7:0] DataC;
output [7:0] DataD;
output MW;
wire MB;
wire MD;
wire LD;
wire C;
wire V;
wire N;
wire Z;
wire [2:0] DR;
wire [2:0] SA;
wire [2:0] SB;
wire [5:0] IMM;
wire [2:0] FS;
wire [7:0] SEXT;
wire [7:0] MBmuxOUT;
wire BS;
wire OFF;
wire HALT;
reg [7:0] PC;
reg [7:0] NextPC;
wire H;
wire [7:0] whichPC;
signExtend SE (
.IMM(IMM),
.SEXT(SEXT)
);
two_to_one_mux MBmux (
.INA(DataB),
.INB(SEXT),
.SEL(MB),
.OUT(MBmuxOUT)
);
two_to_one_mux MDmux (
.INA(DataD),
.INB(Din),
.SEL(MD),
.OUT(DataC)
);
decoder d1(
.INST(Iin),
.DR(DR),
.SA(SA),
.SB(SB),
.IMM(IMM),
.MB(MB),
.FS(FS),
.MD(MD),
.LD(LD),
.MW(MW),
.BS(BS),
.OFF(OFF),
.HALT(HALT)
);
// comment the two lines out below if you use a submodule to generate PC/NextPC
// ADD YOUR CODE BELOW THIS LINE
alu alu1(
.A(DataA),
.B(MBmuxOUT),
.OP(FS),
.Y(DataD),
.C(C),
.V(V),
.N(N),
.Z(Z)
);
registerFile regfile(
.RESET(RESET),
.LD(LD),
.CLK(CLK),
.SA(SA),
.SB(SB),
.DR(DR),
.DataA(DataA),
.DataB(DataB),
.D_in(DataC)
);
halt_logic haltLogic (
.CLK (CLK),
.HALT (HALT),
.EN_L (EN_L),
.H (H)
);
two_to_one_mux doHalt (
.INA((PC + 2)),
.INB(PC),
.SEL(H),
.OUT(whichPC)
);
always @(*)
begin
if (RESET)
NextPC = 8'd0;
else
NextPC =whichPC;
end
always @ (posedge CLK)
begin
PC<=NextPC;
end
// ADD YOUR CODE ABOVE THIS LINE
endmodule