module latch(clk,d,q);
input clk,d;
output q;
if(clk==1)
assign q = d;
endmodule
Why am I getting error in the above code?
module latch(clk,d,q);
input clk,d;
output q;
if(clk==1)
assign q = d;
endmodule
Why am I getting error in the above code?
if is not a top level block inside a module. It should be used inside an always, or initial (if for simulation purposes) block, or other legal blocks. While assign is. (generate is not taken into consideration, for simplicity)
I guess what you want to achieve is:
module latch(clk, d, q);
input clk, d;
output q;
reg q;
always@(*)begin
if(clk)begin
q = d;
end
end