This repository has been archived by the owner on Jun 1, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
control.v
52 lines (40 loc) · 1.61 KB
/
control.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
module control (op, funct, zero, sign, sign_ext, shift,
alu_src, mem_write, reg_src, reg_dst, reg_write,
reg_fwd, pc_update, branch, jump, jal, jr);
input [5:0] op, funct;
input zero;
output sign, sign_ext, shift, alu_src, mem_write, reg_src,
reg_dst, reg_write, reg_fwd, pc_update,
branch, jump, jal, jr;
// Parse the instructions
wire r_type = (op == 6'h00);
wire i_add = r_type && (funct == 6'h20);
wire i_sub = r_type && (funct == 6'h22);
wire i_sll = r_type && (funct == 6'h00);
wire i_srl = r_type && (funct == 6'h02);
wire i_sra = r_type && (funct == 6'h03);
wire i_jr = r_type && (funct == 6'h08);
wire i_type = (op >= 6'h08) && (op <= 6'h0f);
wire i_addi = (op == 6'h08);
wire i_lw = (op == 6'h23);
wire i_sw = (op == 6'h2b);
wire i_beq = (op == 6'h04);
wire i_bne = (op == 6'h05);
wire i_j = (op == 6'h02);
wire i_jal = (op == 6'h03);
// Generate control signals
assign sign = i_add || i_sub || i_addi;
assign sign_ext = i_addi || i_lw || i_sw || i_beq || i_bne;
assign shift = i_sll || i_srl || i_sra;
assign alu_src = i_type || i_lw || i_sw;
assign mem_write = i_sw;
assign reg_src = i_lw;
assign reg_dst = r_type;
assign reg_write = r_type || i_type || i_lw || i_jal;
assign reg_fwd = i_beq || i_bne || i_jr;
assign pc_update = branch || jump || jr;
assign branch = (i_beq && zero) || (i_bne && !zero);
assign jump = i_j || i_jal;
assign jal = i_jal;
assign jr = i_jr;
endmodule