Professional Documents
Culture Documents
ETE 419 - Lab7
ETE 419 - Lab7
CODE
Main Module:
module alu(out,select,a,b);
output [4:0]out;
input [3:0] a,b;
input [2:0] select;
reg [4:0]out;
always@(select,a,b)
begin
case(select)
3’b000: out =a;
3’b001: out =a+b;
3’b010: out =a-b;
3’b011: out =a&b;
3’b100: out =a|b;
3’b101: out =a<<b;
3’b110: out =a>>b;
3’b111: out =a>b;
default:$display(“invalid”);
endcase
end
endmodule
Test Bench:
module stimulus;
wire [4:0] out;
reg [3:0] a, b;
reg [2:0] select;
alu a1(out, select, a, b);
initial
begin
$monitor (“out=%d, a=%d, b=%d, select=%b”, out, a, b, select);
end
initial
begin
a=4’d10; b=4’d5; S=3’b000;
#5 S=3’b001;
#5 S=3’b010;
#5 S=3’b011;
#5 S=3’b100;
#5 S=3’b101;
#5 S=3’b110;
#5 S=3’b111;
#5$stop;
end
endmodule