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 その206

Posted at

概要 

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

練習問題

2bit、cpuを書け。

サンプルコード



module cpu2(input clk, input rst, output [1:0] outport);
	reg [1:0] a,
		c;
	reg [1:0] pc;
	reg [1:0] mem[1:0];
	wire [1:0] code;
	assign code = mem[pc];
	always @(posedge clk, negedge rst)
	begin
		if (!rst)
		begin
			mem[0] <= 2'h0; //a++
			mem[1] <= 2'h1; //if (a > 0) pc = 0
			a <= 0;
			c <= 0;
			pc <= 0;
		end
		else
		begin
			case (code)
			2'h0:
			begin
				a <= a + 1;
			end
			2'h1:
			begin
				if (a > 0)
				begin
					a <= 0;
					pc <= 0;
				end
			end
			endcase
			pc = pc + 1;
		end
	end
	initial
	begin
		$monitor("%d %d %d", a, c, pc);
	end
endmodule

module test;
	reg clk,
		rst;
	wire [1:0] outport;
	cpu2 u(.clk(clk), .rst(rst), .outport(outport));
	initial
	begin
		clk = 0;
		rst = 1;
	#2
		rst = 0;
	#2
		rst = 1;
	#20
		$finish;
	end
	always
	#1
		clk = ~clk;
	initial
	begin
		//$monitor("%d", outport);
	end
endmodule





実行結果

>vvp a.out
x x x
0 0 0
1 0 1
0 0 0
1 0 1
0 0 0
1 0 1
0 0 0
1 0 1
0 0 0
1 0 1
0 0 0
cpu20.v:59: $finish called at 24 (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?