Professional Documents
Culture Documents
8 Bit Alu
8 Bit Alu
8 BIT ALU
input carryin;
output [7:0] Y;
reg [7:0] Y;
begin: ALU_Processing
// Logical Unit
case (sel(1:0))
2’d0: Logic_Unit=A&B;
2’d1: Logic_Unit=A | B;
2’d2: Logic_Unit=A ^ B;
2’d3: Logic_Unit=!A;
endcase
2’d0: Arith_Unit=A;
2’d1: Arith_Unit=A+1;
2’d2: Arith_Unit=A+B;
2’d3: Arith_Unit=A+B+1;
2’d4: Arith_Unit=A+!B;
2’d5: Arith_Unit=A-B;
2’d6: Arith_Unit=A-1;
2’d7: Arith_Unit=A;
Endcase
// Multiplexing
if (sel[2])
Alu_Shift=Logic_Unit;
else
Alu_Shift=Arith_Unit;
// Shift Operations
case (sel[4:3])
2’d0: Y=ALU_Shift;
endcase
end
endmodule
input [3:0] A;
input [3:0] B;
output [3:0] Y;
input [2:0] S;
output F;
reg[3:0] Y;
reg F;
always @(A,B,S)
begin
case(S)
3'b000:
{F,Y} = A+B;
3'b001:
{F,Y} = A-B;
3'b010:
Y = A*B;
3'b011:
Y = A>>2;
3'b100:
Y = A & B;
3'b101:
Y = A | B;
3'b110:
Y = A^B;
3'b111:
Y = ~(A^B);
default:
Y = 4'b0000;
endcase
end
endmodule