0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

windowsでiverilog その181

Posted at

概要 

windowsでiverilogやってみた。
練習問題やってみた。

練習問題

Dフリップフロップで4bitシフトレジスタを書け。

サンプルコード

module dff(input D, clk, output reg Q);
	always@(posedge clk)
		Q = D;
endmodule

module sr8(input wire _in, input wire clk, output wire _out);
	wire q0,
		q1,
		q2,
		q3,
		q4,
		q5,
		q6,
		q7;
	wire clk_;
	assign _out = q7;
	assign clk_ = ~clk;
	dff u0(.D(_in), .clk(clk), .Q(q0));
	dff u1(.D(q0), .clk(clk_), .Q(q1));
	dff u2(.D(q1), .clk(clk), .Q(q2));
	dff u3(.D(q2), .clk(clk_), .Q(q3));
	dff u4(.D(q3), .clk(clk), .Q(q4));
	dff u5(.D(q4), .clk(clk_), .Q(q5));
	dff u6(.D(q5), .clk(clk), .Q(q6));
	dff u7(.D(q6), .clk(clk_), .Q(q7));
endmodule

module test;
	reg i,
		c;
	output o;
	sr8 u(i, c, o);
	initial
	begin
		$dumpfile("test.vcd");
		$dumpvars(0, u);
		$display("i c o");
		$monitor("%b %b %b", i, c, o);
		i = 0;
		c = 0;
		#10;
			i = 1;
			c = 1;
		#10;
			i = 0;
			c = 0;
		#10;
			i = 0;
			c = 1;
		#10;
			i = 0;
			c = 0;
		#10;
			i = 0;
			c = 1;
		#10;
			i = 0;
			c = 0;
		#10;
			i = 0;
			c = 1;
		#10;
			i = 0;
			c = 0;
		#10;
			i = 0;
			c = 1;
		#10;
			i = 0;
			c = 0;
		#10;
			i = 0;
			c = 1;
		#10;
			i = 0;
			c = 0;
		#10;
			i = 0;
			c = 1;
		#10;
			i = 0;
			c = 0;
		#10;
			i = 0;
			c = 1;
		#10;
			i = 0;
			c = 0;
		#10;
			i = 0;
			c = 1;
		#10;
			i = 0;
			c = 0;
		#10;
			i = 0;
			c = 1;
		#10;
			$finish;
	end
endmodule

実行結果

>vvp a.out
VCD info: dumpfile test.vcd opened for output.
i c o
0 0 x
1 1 x
0 0 x
0 1 x
0 0 x
0 1 x
0 0 x
0 1 x
0 0 1
0 1 1
0 0 0
0 1 0
0 0 0
0 1 0
0 0 0
0 1 0
0 0 0
0 1 0
0 0 0
0 1 0
dff5.v:102: $finish called at 200 (1s)

以上。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?