-
Notifications
You must be signed in to change notification settings - Fork 1
/
ALU.v
43 lines (43 loc) · 851 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
module ALU #(parameter Width = 32)(
input [3:0] controlsignal, input [Width-1:0] A1,A2,
output reg [Width-1:0] Y, output zero);
//wire [63:0] B;
always @(*)
begin
if (controlsignal == 4'b0000)
Y = A1 & A2;
else if (controlsignal == 4'b0001)
Y = A1 | A2;
else if(controlsignal == 4'b0010)
Y = A1 + A2;
else if(controlsignal == 4'b0110)
Y = A1 - A2;
else if(controlsignal == 4'b0011)
Y = A1 << A2;
else if(controlsignal == 4'b0100)
begin
//A1 = ~A1 + 1;
//A2 = ~A2 + 1;
if((~A1+1) < (~A2+1))
Y = 1;
else
Y = 0;
end
else if(controlsignal == 4'b0101)
begin
if(A1 < A2)
Y = 1;
else
Y = 0;
end
else if(controlsignal == 4'b0111)
Y = A1 ^ A2;
else if(controlsignal == 4'b1000)
Y = A1 >> A2;
else if(controlsignal == 4'b1010)
Y = A1 >>> A2;
else
Y = {Width{1'bx}};
end
assign zero = (Y == 0) ? 1 : 0;
endmodule