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

Posted at

概要 

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

練習問題

atcoderを解け。
ABC 083 B - Some Sums
1以上N以下の整数のうち、10進法での各桁の和がA以上B以下であるものの総和を求める問題です。
IN
20 2 5
OUT
84

サンプルコード


module test;
	integer stdin = 'h8000_0000;
	integer n,
		a,
		b,
		c,
		ch,
		i,
		v,
		p;
	reg [7:0] pc;
	reg [7:0] str[0:9];
	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
			ch = $fscanf(stdin, "%d", b);
			pc <= 40;
		end
		40:
		begin
			i = i + 1;
			if (i > n)
			begin
				pc <= 80;
			end
			else
			begin
				pc <= 50;
			end
		end
		50:
		begin
			v = i / 10 + i % 10;
			if (v > a - 1 & v < b + 1)
			begin
				//$display(" %d", i);
				p = p + i;
			end
			pc <= 40;
		end
		80:
		begin
			$write("%d", p);
			pc <= 90;
		end
		90:
		begin
			$finish(0);
		end
		endcase
	end
	initial
	begin
		pc <= 10;
		i = 0;
		b = 0;
		p = 0;
	end
endmodule




実行結果

>vvp a.out
20 2 5
         84

以上。

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?