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 にはできない) |
expression | wire を駆動する値 |
簡単な例
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=1a または 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ステートバッファーの作成
- 組み合わせ式からの出力の駆動
チャレンジ
実行内容:
- Add the missing continuous assignment that makes
zequal tox AND y。
自分で試してみよう
module continuous_challenge (
input x,
input y,
output z
);
// TODO: z を x AND y と等しくする欠けている連続代入を追加してください
endmoduleこのレッスンには短いクイズがあります。レッスンを始めて解答し、進捗を記録しましょう。
基礎のすべてのレッスン
4Operators Part 1
Arithmetic OperatorsModulo OperatorComparison OperatorsRecap - Simple MathBitwise Operators7Assign And Gates
Continuous AssignmentAssign With OperatorsBuilt In Gate PrimitivesAND OR NOT GatesXOR XNOR GatesRecap - Logic Gate Circuit10Decision Making
If StatementIf - ElseRecap - Simple ComparatorCase StatementCasex And CasezRecap - ALU Design5Operators Part 2
Logical OperatorsReduction OperatorsShift OperatorsConcatenation OperatorConditional OperatorRecap - Operator Challenge3Number System
Binary RepresentationSized NumbersUnsized NumbersNegative NumbersSpecial Values X And ZRecap - Number Formats6Modules
Module StructureInput And Output PortsInout PortsModule InstantiationPort Mapping By NamePort Mapping By OrderRecap - Build A Module9Procedural Blocks
Always BlockInitial BlockSensitivity ListBlocking AssignmentNon Blocking AssignmentRecap - Always vs Initial15Traffic Light Controller
Defining The StatesState Machine Logic自分で練習してみよう: Verilogオンラインコンパイラ