1
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?

Hardware Description LanguageAdvent Calendar 2024

Day 13

windowsでiverilog その159

Last updated at Posted at 2024-12-09

概要 

windowsでiverilogやってみた。
AtCoderやってみた。

参考にしたページ

サンプルコード

整数 a,b,cと、文字列 s が与えられます。 a+b+c の計算結果と、文字列 s を並べて表示しなさい。


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



実行結果

>vvp a.out
1
2 3
test
6 test

以上

1
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
1
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?