-
Notifications
You must be signed in to change notification settings - Fork 0
/
ALU.v
60 lines (46 loc) · 1.36 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
// Alden Rivera 0416329
// Jorge Pineda 0416330
`timescale 1ns / 1ps
//Subject: CO project 2 - ALU
//--------------------------------------------------------------------------------
//Version: 1
//--------------------------------------------------------------------------------
//Writer:
//----------------------------------------------
//Date:
//----------------------------------------------
//Description:
//--------------------------------------------------------------------------------
module ALU(
src1_i,
src2_i,
ctrl_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;
output reg [32-1:0] result_o;
output zero_o;
//Internal signals
//reg [32-1:0] result_o;
//wire zero_o;
//Parameter
//Main function
assign zero_o = (result_o == 0);
always@(*)
begin
case(ctrl_i)
0: result_o <= src1_i & src2_i;
1: result_o <= src1_i | src2_i;
2: result_o <= src1_i + src2_i;
6: result_o <= src1_i - src2_i;
7: result_o <= src1_i < src2_i ? 1 : 0;
12: result_o <= ~(src1_i | src2_i);
15: result_o <= src1_i * src2_i;
default: result_o <= 0;
endcase
end
endmodule