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?

More than 5 years have passed since last update.

windowsでiverilog その34

Posted at

概要

windowsでiverilogやってみた。
負数、書いてみる。

サンプルコード


module mul(input clk, rst, input signed [3:0] a, input signed [3:0] b, output signed [7:0] out);
	reg signed [7:0] out;
	always @(posedge clk or negedge rst)
	begin
		if (!rst)
		begin
			out <= 0;
		end
		else
		begin
			out <= a * b;
		end
	end
endmodule

module test();
	reg clk;
	reg rst;
	reg signed [3:0] a;
	reg signed [3:0] b;
	wire signed [7:0] out;
	mul u(.clk(clk), .rst(rst), .a(a), .b(b), .out(out));
	integer i,
		j;
	initial
	begin
		$monitor("%d %d %d", a, b, out);
		clk = 0;
		rst = 1;
		#10
			rst = 0;
		#10
			rst = 1;
		#10
			a = -5;
			b = -5;
		#10
			$finish;
	end
	always
	begin
		#5
			clk = 1;
		#5
			clk = 0;
	end
endmodule




実行結果



 x  x    x
 x  x    0
 x  x    x
-5 -5    x
-5 -5   25


以上。

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?