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

Posted at

概要 

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

練習問題

AtCoderを解け。
N個の整数値を受け取り、一度の操作ですべての数を2で割る。割り切れなくなるまで割っていった時、何回割ることが出来るか?

サンプルコード


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




実行結果

>vvp a.out
3
8 12 40
          2

以上。

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?