-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathControl_Unit.v
More file actions
50 lines (50 loc) · 2.15 KB
/
Copy pathControl_Unit.v
File metadata and controls
50 lines (50 loc) · 2.15 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
// field | width
// -----------|----
// BranchBeq | 1b
// BranchJal | 1b
// BranchJalr | 1b
// RegWrite | 1b
// MemToReg | 1b
// MemWrite | 1b
// ALUControl | 4b
// ALUSrc | 1b
// immControl | 3b
// -----------|----
// total: | 14 bits => out_control is 14 bits wide
module ControlUnit(input [31:0] instruction, output reg [13:0] out_control);
always @(instruction) begin
case(instruction[6:0]) // bits 6:0 contain the opcode
7'b0000011: out_control = 14'b00011000001000; // lw
7'b0100011: out_control = 14'b00000100001001; // sw
7'b0110011: begin
case(instruction[14:12]) // func3
3'b000: begin
case (instruction[31:25]) // func7, add or sub
7'b0000000: out_control = 14'b00010000000000; // add
7'b0100000: out_control = 14'b00010000010000; // sub
default: out_control = 0;
endcase
end
3'b010: out_control = 14'b00010001010000; // slt
3'b110: begin
case (instruction[31:25]) // func7, 'or' or rem
7'b0000000: out_control = 14'b00010001000000; // or
7'b0000001: out_control = 14'b00010001100000; // rem
default: out_control = 0;
endcase
end
3'b111: out_control = 14'b00010000110000; // and
3'b100: out_control = 14'b00010000100000; // div
default: out_control = 0;
endcase
end
7'b1100010: out_control = 14'b10000000010010; // beq
7'b1101111: out_control = 14'b01010000000100; // jal
7'b1100111: out_control = 14'b00110000001000; // jalr
7'b0010011: out_control = 14'b00010000001000; // addi
7'b0110111: out_control = 14'b00010001111011; // lui
7'b1100011: out_control = 14'b10000001010010; // blt
default: out_control = 0;
endcase
end
endmodule