-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprocessor.v
180 lines (154 loc) · 2.59 KB
/
processor.v
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
169
170
171
172
173
174
175
176
177
178
179
180
module processor (
input clk,
output [15:0]Y
);
wire [15:0] bus;
assign bus = stPC ? next : src2D ? Rsrc : alu2D ? Y : 0;
wire [15:0] A;
reg [15:0] B;
assign A = muxA ? Rsrc : Rdst;
always @(muxB) begin
case (muxB)
0: assign B = Rsrc;
2: assign B = imm_out;
5: assign B = S4;
6: assign B = DS8;
7: assign B = D4;
default:
assign B = 0;
endcase
end
// program_counter wires
wire [15:0] next;
wire [15:0] pc;
always @(pc) begin
$display("Program counter: %d", pc);
end
// rom wires
wire [15:0] instr;
always @(instr) begin
$display("Instruction: %b", instr);
end
// control wires
wire stPC;
wire WE;
wire imm;
wire [1:0] iem;
wire absJmp;
wire [2:0] muxB;
wire src2D;
wire muxA;
wire alu2D;
wire [4:0] aluOp;
wire storeFlags;
wire [2:0] branch_ctrl;
wire ramSt;
wire ramLd;
wire ioW;
wire ioR;
wire Retl;
// register wires
wire [15:0] Rdst;
wire [15:0] Rsrc;
// im_reg wires
wire [15:0] imm_out;
// sign_ext wires
wire [15:0] S4;
wire [15:0] DS8;
wire [15:0] D4;
// alu wires
//wire [15:0] Y;
wire Zero;
wire Neg;
wire Carry;
// flags wires
wire Co;
wire No;
wire Zo;
always @(Co or No or Zo) begin
$display("Co: %d, No: %d, Zo: %d", Co, No, Zo);
end
// branch wires
wire jmp;
program_counter program_counter (
.clk(clk),
.abs(absJmp),
.rel(jmp),
.alu(Y),
.next(next),
.pc(pc)
);
rom rom (
.addr(pc),
.instr(instr)
);
control control (
.op_code(instr[15:8]),
.stPC(stPC),
.WE(WE),
.imm(imm),
.iem(iem),
.absJmp(absJmp),
.muxB(muxB),
.src2D(src2D),
.muxA(muxA),
.alu2D(alu2D),
.aluOp(aluOp),
.storeFlags(storeFlags),
.branch(branch_ctrl),
.ramSt(ramSt),
.ramLd(ramLd),
.ioW(ioW),
.ioR(ioR),
.Retl(Retl)
);
register register (
.src(instr[3:0]),
.dst(instr[7:4]),
.WD(bus),
.clk(clk),
.WE(WE),
.Rsrc(Rsrc),
.Rdst(Rdst)
);
im_reg im_reg (
.en(imm),
.iem(iem),
.clk(clk),
.inst(instr),
.imm(imm_out)
);
sign_ext sign_ext (
.inst(instr),
.S4(S4),
.DS8(DS8),
.D4(D4)
);
alu alu (
.A(A),
.B(B),
.Ci(Co),
.aluOp(aluOp),
.Y(Y),
.Zero(Zero),
.Neg(Neg),
.Carry(Carry)
);
flags flags (
.store(storeFlags),
.clk(clk),
.Ci(Carry),
.Ni(Neg),
.Zi(Zero),
.Co(Co),
.No(No),
.Zo(Zo)
);
branch branch (
.C(Co),
.N(No),
.Z(Zo),
.ctrl(branch_ctrl),
.jmp(jmp)
);
endmodule