最初のモジュール
CoddyのVerilogジャーニー「基礎」セクションの一部。レッスン 3/90。
module は Verilog における基本的な構成要素です。Verilog コードのすべての部分は module の中にあります。
モジュールを、次の要素を持つコンポーネントとして考えてみましょう:
- 入力(入ってくる信号)
- 出力(出ていく信号)
- Behavior(その動作)
モジュール構文
module module_name ( inputs, outputs );
// ここにあるすべて
endmoduleすべてのモジュールはmoduleで始まり、endmoduleで終わります。
Inputs and Outputs
module and_gate(
input a, // a はモジュールに入ってくる
input b, // b はモジュールに入ってくる
output c // c はモジュールから出ていく
);
// 動作はここに記述
endmodule- input = 信号がモジュールに入る
- output = 信号がモジュールから出る
Behaviorの追加
ここで、moduleに何かをさせます:
module and_gate(
input a,
input b,
output c
);
assign c = a & b; // c は a と b がともに 1 のときのみ 1 になる
endmoduleassignは右辺を左辺に継続的に接続します&は Verilog で AND を意味します
チャレンジ
このチャレンジでは、OR演算を実行するシンプルな module を作成する必要があります。
行うこと:
- module の名前は
or_gateにします xという名前の input を持つ必要がありますyという名前の input を持つ必要がありますzという名前の output を持つ必要があります- module の inside で、
assignを使ってzをx OR yと等しくします
module のヘッダーとその3つの ports はすでにエディターにあります。追加する必要がある行は、module inside の assign 文です。
注:Verilog では、OR はパイプ記号 | で記述します。inputs の少なくとも1つが1(true)の場合、1(true)を出力します。
自分で試してみよう
// モジュールのヘッダーとそのポートはすでに記述されています
module or_gate(
input x,
input y,
output z
);
// あなたの番です: assign を使って z を x OR y に設定してください
// Verilog では、OR は | と書きます
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オンラインコンパイラ