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 14

windowsでiverilog その160

Last updated at Posted at 2024-12-09

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

練習問題

fizzbuzzを書け。

サンプルコード



module test;
	integer p;
	integer stdin = 'h8000_0000;
	integer i;
	integer ch;
	reg [7:0] pc;
	reg [7:0] str[0:9];
	integer v;
	initial
	begin
		pc <= 10;
		v = 0;
		i = 0;
	end
	always #1
	begin
		case(pc)
		10:
		begin
			i++;
			pc <= 20;
		end
		20:
		begin
			if (i > 100)
			begin
				pc <= 100;
			end
			else
			begin
				pc <= 30;
			end
		end
		30:
		begin
			if (i % 15 == 0)
			begin
				pc <= 70;
			end
			else
			begin
				pc <= 40;
			end
		end
		40:
		begin
			if (i % 5 == 0)
			begin
				pc <= 80;
			end
			else
			begin
				pc <= 50;
			end
		end
		50:
		begin
			if (i % 3 == 0)
			begin
				pc <= 90;
			end
			else
			begin
				pc <= 60;
			end
		end
		60:
		begin
			$write("%0d\n", i);
			pc <= 10;
		end
		70:
		begin
			$write("%s\n", "FizzBuzz");
			pc <= 10;
		end
		80:
		begin
			$write("%s\n", "Buzz");
			pc <= 10;
		end
		90:
		begin
			$write("%s\n", "Fizz");
			pc <= 10;
		end
		100:
		begin
			$finish(0);
		end
		endcase
	end
	initial
	begin
		//$monitor(" %d", pc);
	end
endmodule





実行結果

>vvp a.out
1
2
Fizz
4
Buzz
Fizz
7
8
Fizz
Buzz
11
Fizz
13
14
FizzBuzz
16
17
Fizz
19
Buzz
Fizz
22
23
Fizz
Buzz
26
Fizz
28
29
FizzBuzz
31
32
Fizz
34
Buzz
Fizz
37
38
Fizz
Buzz
41
Fizz
43
44
FizzBuzz
46
47
Fizz
49
Buzz
Fizz
52
53
Fizz
Buzz
56
Fizz
58
59
FizzBuzz
61
62
Fizz
64
Buzz
Fizz
67
68
Fizz
Buzz
71
Fizz
73
74
FizzBuzz
76
77
Fizz
79
Buzz
Fizz
82
83
Fizz
Buzz
86
Fizz
88
89
FizzBuzz
91
92
Fizz
94
Buzz
Fizz
97
98
Fizz
Buzz

以上。

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?