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

Last updated at Posted at 2025-01-12

概要 

windowsでiverilogやってみた。
2bitCPU、書いてみた。

cpuの仕様

レジスタマシン

  • レジスタ
    アキュムレータa-2bit
    プログラムカウンタ2bit
    キャリー1bit
  • メモリー
    2bit2アドレス
  • 命令2bit
    h0--a = a + 1
    h1--if (c > 0) pc = 0

サンプルコード


module cpu2(input clk, input rst, output [1:0] outport);
	reg [1:0] a;
	reg c;
	reg [1:0] pc;
	reg [1:0] mem[1:0];
	wire [1:0] code;
	assign code = mem[pc];
	assign op = code[3:2];
	always @(posedge clk, negedge rst)
	begin
		if (!rst)
		begin
			mem[0] <= 4'h0; //a++
			mem[1] <= 4'h1; //if (c > 0) pc = 0
			a <= 2'h0;
			c <= 0;
			pc <= 2'h0;
		end
		else
		begin
			case (op)
			2'h0://a++
			begin
			end
			2'h1://if (c > 0) pc = 0
			begin
				if (c > 0)
					pc = 0;
			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
0 0 1
0 0 2
0 0 3
0 0 0
0 0 1
0 0 2
0 0 3
0 0 0
0 0 1
0 0 2
cpu20.v:56: $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?