简单的Verilog HDL例子(一)

例1 数据选择器

简单的Verilog HDL例子(一)_第1张图片

module MUX(out,in0,in1,sel);
	parameter N=8;
	output [N:1] out;
	input [N:1] in0,in1;
	input sel;
	assign out=sel?in1:in0;
endmodule
)

例2 四位二进制加法计数器(带同步清零)

简单的Verilog HDL例子(一)_第2张图片

module counter(q,count,reset,cin,clk);
	parameter N=4;
	output [N:1] q;
	output count;
	input reset,cin,clk;
	reg [N:1] count;//寄存器型(有保持功能)
	//逻辑功能描述
	always@(posedge clk)
		begin
			if (reset) q<=0;
			else
			q <= q + cin;//计数或保持
		end
	assign count = &q && cin;//进位,&q=q[1]·q[2]...q[N]
endmodule

你可能感兴趣的:(IC设计)