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

Posted at

概要 

windowsでiverilogやってみた。
8bit ALU、見つけたので、テストベンチ書いてみた。

参考にしたページ

サンプルコード

module test();
	reg signed [7:0] a,
		b;
	reg [2:0] op;
	wire signed [7:0] z;
	wire ov;
	ALU u(.A(a), .B(b), .OP(op), .Z(z), .OV(ov));
	initial
	begin
		$display("// non overflow sum");
		a = 2;
		b = 3;
		op = 0;
		#50
		$display("// overflow sum type 1");
		a = 64;
		b = 64;
		op = 0;
		#50
		$display("// overflow sum type 2");
		a = -60;
		b = -75;
		op = 0;
		#50
		$display("// non overflow subtract");
		a = 7;
		b = 3;
		op = 1;
		#50;
		$display("// overflow subtract type 1");
		a = -100;
		b = 50;
		op = 1;
		#50;
		$display("// overflow subtract type 2");
		a = 100;
		b = -50;
		op = 1;
		#50;
		$display("// max");
		a = 12;
		b = 28;
		op = 2;
		#50;
		$display("// max");
		a = 15;
		b = -28;
		op = 2;
		#50;
		$display("// min");
		a = 64;
		b = 95;
		op = 3;
		#50;
		$display("// min");
		a = 100;
		b = -1;
		op = 3;
		#50;
		$display("// right shift");
		a = 10;
		b = 0;
		op = 4;
		#50;
		$display("// right shift");
		a = -5;
		b = 0;
		op = 4;
		#50;
		$display("// left shift");
		a = 0;
		b = 4;
		op = 5;
		#50;
		$display("// left shift");
		a = 0;
		b = -8;
		op = 5;
		#50;
		$finish;
	end
	initial
	begin
		$display(" op, a, b, z");
		$monitor(" %d  %d  %d %d ", op, a, b, z);
	end
endmodule





実行結果

>vvp a.out
// non overflow sum
 op, a, b, z
 0     2     3    5
// overflow sum type 1
 0    64    64 -128
// overflow sum type 2
 0   -60   -75  121
// non overflow subtract
 1     7     3    4
// overflow subtract type 1
 1  -100    50  106
// overflow subtract type 2
 1   100   -50 -106
// max
 2    12    28   28
// max
 2    15   -28   15
// min
 3    64    95   64
// min
 3   100    -1   -1
// right shift
 4    10     0   40
// right shift
 4    -5     0  -20
// left shift
 5     0     4    0
// left shift
 5     0    -8   -1
alu8.v:122: $finish called at 700 (1s)




以上。

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?