Menu
Coddy logo textTech

Continuous Assignment

CoddyのVerilogジャーニー「基礎」セクションの一部。レッスン 37/90。

ハードウェアでは、connectionは回路内の2つの点をつなぐ物理的なwireです。wireが配置されると、connectionは永続的になり、alwaysアクティブです。一方の端が変化すると、もう一方の端も直ちに変化します。

Verilogでは、この動作をモデル化する方法が必要です。値をwireに渡し、それを永続的に接続したままにしたいと考えています。これを行う処理はcontinuous assignmentと呼ばれます。

continuous assignment は assign キーワードを使用して、wire と expression の間に永続的な接続を作成します。wire は物理的な wire と同じように、expression の値を continuously 取得します。

一度値を書き込むのではなく、wireをはんだ付けするようなものだと考えてください。

構文

assign wire_name = expression;
部分意味
assign連続代入を開始するキーワード
wire_name駆動される wire(reg にはできない)
expressionwire を駆動する値

簡単な例

wire out;
assign out = a & b;

これは、out が常に a AND b と等しいことを意味します。a または b が変化すると、out は直ちに変化します。

仕組み

値を格納する reg とは異なり、連続代入を使用する wire は常に更新されます。

module continuous_demo;
  reg a, b;
  wire c;
  
  assign c = a & b;   // c は常に a AND b に従う
  
  initial begin
    a = 0; b = 0;
    #10 $display("a=%d, b=%d, c=%d", a, b, c);  // c=0
    
    a = 1;
    #10 $display("a=%d, b=%d, c=%d", a, b, c);  // c=0 (1&0=0)
    
    b = 1;
    #10 $display("a=%d, b=%d, c=%d", a, b, c);  // c=1 (1&1=1)
    
    $finish;
  end
endmodule

出力:

a=0, b=0, c=0
a=1, b=0, c=0
a=1, b=1, c=1

a または b が変わるたびに、c は自動的に更新されます。

複数の代入

モジュール内に複数のcontinuous assignmentsを記述できます:

module multiple_assign (
  input a, b, c,
  output x, y
);
  assign x = a & b;
  assign y = x | c;   // y は x に依存する
endmodule

すべての assignment は並列で、continuously 実行されます。

一般的な用途

Continuous assignments は次の用途に使用されます:

  • 単純な組み合わせ論理(AND、OR、XOR)
  • wire 同士の接続
  • 3ステートバッファーの作成
  • 組み合わせ式からの出力の駆動
challenge icon

チャレンジ

実行内容:

  1. Add the missing continuous assignment that makes z equal to x AND y

自分で試してみよう

module continuous_challenge (
  input x,
  input y,
  output z
);
  
  // TODO: z を x AND y と等しくする欠けている連続代入を追加してください
  

endmodule
quiz icon腕試し

このレッスンには短いクイズがあります。レッスンを始めて解答し、進捗を記録しましょう。

基礎のすべてのレッスン

自分で練習してみよう: Verilogオンラインコンパイラ