-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathALU.v
27 lines (22 loc) · 936 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
module ALU(A,B,Result,ALUControl,OverFlow,Carry,Zero,Negative);
input [31:0]A,B;
input [2:0]ALUControl;
output Carry,OverFlow,Zero,Negative;
output [31:0]Result;
wire Cout;
wire [31:0]Sum;
assign {Cout,Sum} = (ALUControl[0] == 1'b0) ? A + B :
(A + ((~B)+1)) ;
assign Result = (ALUControl == 3'b000) ? Sum :
(ALUControl == 3'b001) ? Sum :
(ALUControl == 3'b010) ? A & B :
(ALUControl == 3'b011) ? A | B :
(ALUControl == 3'b101) ? {{31{1'b0}},(Sum[31])} :
(ALUControl == 3'b111) ? A ^ B : {32{1'b0}};
assign OverFlow = ((Sum[31] ^ A[31]) &
(~(ALUControl[0] ^ B[31] ^ A[31])) &
(~ALUControl[1]));
assign Carry = ((~ALUControl[1]) & Cout);
assign Zero = &(~Result);
assign Negative = Result[31];
endmodule