samcheetah
Advanced Member level 2
i have written a small code in verilog and it seems to be not working. the aim is to build a logic block that would AND or OR two inputs depending upon a third control input. actually im debugging a code for an ALU that would ADD or SUBTRACT depending upon a control input but i think im doing something wrong in the always and if blocks so if someone can point my mistake in this code, i can debug the original code im working on.
EDIT: one thing i forgot to mention is that i am working on the gate-level
Code:
module and_or( out, in1, in2, ctrl );
output out;
input in1, in2, ctrl;
reg out;
always @(in1 or in2 or ctrl)
begin
if(ctrl)
and (out, in1, in2);
else
or (out, in1, in2);
end
endmodule
module stimulus;
reg IN1, IN2;
reg CTRL;
wire OUT;
and_or MOD(OUT, IN1, IN2, CTRL);
initial
begin
$monitor($time," IN1= %b, IN2=%b, CTRL = %b, --- OUT= %b\n",
IN1, IN2, CTRL, OUT);
end
// Stimulate inputs
initial
begin
IN1 = 1'b1; IN2 = 1'b0; CTRL = 1'b0;
#5 IN1 = 1'b1; IN2 = 1'b0; CTRL = 1'b1;
end
endmodule
EDIT: one thing i forgot to mention is that i am working on the gate-level