-
Notifications
You must be signed in to change notification settings - Fork 0
/
ALU.v
70 lines (54 loc) · 1.66 KB
/
ALU.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
//0516016 蘇育劭 、 0516225 蔡坤哲
//Subject: CO project 2 - ALU
//--------------------------------------------------------------------------------
//Version: 1
//--------------------------------------------------------------------------------
//Writer: 0516016 蘇育劭 、 0516225 蔡坤哲
//----------------------------------------------
//Date:
//----------------------------------------------
//Description:
//--------------------------------------------------------------------------------
module ALU(
src1_i,
src2_i,
ctrl_i,
shamt_i,
result_o,
zero_o
);
//I/O ports
input [32-1:0] src1_i;
input [32-1:0] src2_i;
input [4-1:0] ctrl_i;
input [5-1:0] shamt_i;
output [32-1:0] result_o;
output zero_o;
//Internal signals
reg [32-1:0] result_o;
reg zero_o;
//Parameter
//Main function
always @( * ) begin
case (ctrl_i)
0: result_o <= src1_i & src2_i;
1: result_o <= src1_i | src2_i; //or , ori
2: result_o <= src1_i + src2_i;
3: result_o <= src2_i << 16; //lui
6: begin
result_o <= src1_i - src2_i;
zero_o <= (result_o == 0) ? 1 : 0; //beq
end
7: result_o <= src1_i < src2_i ? 1 : 0; //slt
8: result_o <= $signed(src2_i) >>> shamt_i; //sra
9: begin
result_o <= src1_i - src2_i;
zero_o <= (result_o == 0) ? 0 : 1; //bne
end
11: result_o <= $signed(src2_i) >>> src1_i; //srav
12: result_o <= ~(src1_i | src2_i); //result is nor
15: result_o <= src1_i * src2_i;
default: result_o <= 0;
endcase
end
endmodule