-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathALU.v
More file actions
31 lines (31 loc) · 769 Bytes
/
ALU.v
File metadata and controls
31 lines (31 loc) · 769 Bytes
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
module ALU(
input clk,
input [7:0] a,
input [7:0] b,
input [3:0] operation,
input do_operation,
output reg [7:0] result
);
initial
begin
end
always @(posedge clk)
begin
if(do_operation)
begin
case(operation)
4'b0000:result <= a+b;
4'b0001:result <= a-b;
4'b0010:result <= a*b;
4'b0011:result <= a/b;
4'b0100:result <= (a==b?1:0);
4'b0101:result <= (a>b?1:0);
4'b0110:result <= a&b;
4'b0111:result <= a|b;
4'b1000:result <= a^b;
4'b1001:result <= ~a;
default:result <= 0;
endcase
end
end
endmodule