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

Posted at

概要 

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

練習問題

AtCoderを解け。
文字列内の、'1' の個数をカウントする

サンプルコード


module test;
	integer stdin = 'h8000_0000;
	integer a,
		b,
		c,
		ch,
		v,
		p;
	reg [7:0] pc;
	reg [7:0] str[0:9];
	initial
	begin
		pc <= 10;
		v = 0;
		p = 0;
	end
	always #1
	begin
		case(pc)
		10:
		begin
			ch = $fgetc(stdin);
			pc <= 20;
		end
		20:
		begin
			str[v] = ch;
			if (ch == 'ha)
			begin
				pc <= 30;
			end
			else
			begin
				v++;
				pc <= 10;
			end
		end
		30:
		begin
			ch = str[v];
			if (ch == 'h31)
			begin
				p++;
			end
			pc <= 40;
		end
		40:
		begin
			if (v == 0)
			begin
				pc <= 50;
			end
			else
			begin
				v--;
				pc <= 30;
			end
		end
		50:
		begin
			$write("%d", p);
			pc <= 60;
		end
		60:
		begin
			$finish(0);
		end
		endcase
	end
	initial
	begin
		//$monitor(" %d", pc);
	end
endmodule




実行結果

>vvp a.out
111
          3

以上。

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?