You are on page 1of 3

PROGRAM

module alu(out,a,b,select);
input [7:0] a;
input [7:0] b;
input [4:0] select;
output [8:0] out;
reg [8:0] out;
always @(select or a or b)
begin
case (select)
5'b00000 : out = 00000000;
5'b00001 : out = a + b;
5'b00010 : out = a - b;
5'b00011 : out = a * b;
5'b00100 : out = ~^a;
5'b00101 : out = ~|b;
5'b00110 : out = a ^ b;
5'b00111 : out = a | b;
5'b01000 : out = a & b;
5'b01001 : out = ~a;
5'b01010: out = ~&b;
5'b01011 : out = ~|a;
5'b01100 : out = !a;
5'b01101 : out = b << 2;
5'b01110 : out = a && b;
5'b01111 : out = a || b;
default : out = 11111111;
endcase
end
endmodule
TEST BENCH
module zap1;
// Inputs
reg [7:0] a;
reg [7:0] b;
reg [4:0] select;
// Outputs
wire [8:0] out;
// Instantiate the Unit Under Test (UUT)
zap uut (
.out(out),
.a(a),

.b(b),
.select(select)
);
initial begin
// Initialize Inputs
a = 0;
b = 0;
select = 0;
// Wait 100 ns for global reset to finish
#50;
a = 8'd9;
b = 8'd8;
select = 5'd1;
#50;
a = 8'd3;
b = 8'd4;
select = 5'd2;
#50;
a = 8'd5;
b = 8'd4;
select = 5'd3;
#50;
a = 8'd5;
select = 5'd4;
#50;
b = 8'd4;
select = 5'd5;
#50;
a = 8'd5;
b = 8'd4;
select = 5'd6;
#50;
a = 8'd5;
b = 8'd4;
select = 5'd7;
#50;
a = 8'd5;
b = 8'd4;
select = 5'd8;
#50;
a = 8'd5;
select = 5'd9;
#50;
b = 8'd4;

select = 5'd10;
#50;
a = 8'd5;
select = 5'd11;
#50;
a = 8'd5;
select = 5'd12;
#50;
a = 8'd5;
b = 8'd4;
select = 5'd13;
#50;
a = 8'd5;
b = 8'd4;
select = 5'd14;
#50;
a = 8'd5;
b = 8'd4;
select = 5'd15;
#50;

// Add stimulus here


end
endmodule

You might also like