-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathalu.v
55 lines (42 loc) · 865 Bytes
/
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
`timescale 1ns / 1ps
//////////////////////////////////////////////////////////////////////////////////
// //
// CMPEN 331 Spring 2017 //
// Code by John Huddleston (Section 2) //
// Arithmetic logic unit //
// Overflow and zero outputs not yet implemented //
// //
//////////////////////////////////////////////////////////////////////////////////
module ALU(
input [31:0] a, b,
input [3:0] contr,
output reg [31:0] out
);
always @ (*) begin
case(contr)
4'b0000: begin
out = a & b;
end
4'b0001: begin
out = a | b;
end
4'b0010: begin
out = a + b;
end
4'b0110: begin
out = a - b;
end
4'b0111: begin
if(a < b) begin
out = 32'd1;
end
else begin
out = 32'd0;
end
end
4'b1100: begin
out = ~(a | b);
end
endcase
end
endmodule