Verilog Project: Verilog Code For ALU
Verilog Project: Verilog Code For ALU
Verilog Project: Verilog Code For ALU
);
always @(*)
begin
case(ALU_Sel)
4'b0000: // Addition
ALU_Result = A + B ;
4'b0001: // Subtraction
ALU_Result = A - B ;
4'b0010: // Multiplication
ALU_Result = A * B;
4'b0011: // Division
ALU_Result = A/B;
4'b0100: // Logical shift left
ALU_Result = A<<1;
ALU_Result = A>>1;
ALU_Result = {A[6:0],A[7]};
ALU_Result = {A[0],A[7:1]};
ALU_Result = A & B;
4'b1001: // Logical or
ALU_Result = A | B;
ALU_Result = A ^ B;
ALU_Result = (A>B)?8'd1:8'd0 ;
ALU_Result = (A==B)?8'd1:8'd0 ;
default: ALU_Result = A + B ;
endcase
end
endmodule
module tb_alu;
//Inputs
reg[7:0] A,B;
reg[3:0] ALU_Sel;
//Outputs
wire[7:0] ALU_Out;
wire CarryOut;
integer i;
alu test_unit(
);
initial
begin
A = 8'h0A;
// B = 4'h02;
B = 8'h02;
// ALU_Sel = 4'h0;
ALU_Sel = 4'b0000;
#100
for (i=0;i<=15;i=i+1)
begin
//#10
#10;
end
A = 8'hF6;
B = 8'h0A;
end
endmodule
SIMULATION
1. Another window of simulation will appear. Click “Add wave” as shown in figure to
observe the waveforms results.
2. Run simulation from run button as shown in figure
3. Results of the waveforms of outputs of ALU based on input select lines is shown below:
Timing diagram
.