XOR XNOR Gates
CoddyのVerilogジャーニー「基礎」セクションの一部。レッスン 41/90。
このレッスンでは、2つの追加の論理ゲート、XOR(排他的論理和)とXNOR(排他的否定論理和)について学びます。これらのゲートは、ビットの比較やパリティチェックに役立ちます。
XORゲート
XORゲートは、入力が異なるときに1を出力します。
真理値表(2入力):
| a | b | out |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |
Verilog ゲートプリミティブ:
xor(out, a, b);連続代入に相当するもの:
assign out = a ^ b;XNORゲート
XNORゲートは、inputがsameのときに1をoutputします。これはXORの反対です。
真理値表(2入力):
| a | b | out |
|---|---|---|
| 0 | 0 | 1 |
| 0 | 1 | 0 |
| 1 | 0 | 0 |
| 1 | 1 | 1 |
Verilog ゲートプリミティブ:
xnor(out, a, b);連続代入に相当する表現:
assign out = a ~^ b; // または ~(a ^ b)複数の入力
XORゲートとXNORゲートは、2つを超える入力を持つことができます。出力は次のとおりです。
- XOR:入力の奇数個が1の場合は1
- XNOR:入力の偶数個が1の場合は1
xor(out, a, b, c); // 3入力XOR
xnor(out, p, q, r, s); // 4入力XNOR例(3入力 XOR):
| a | b | c | out |
|---|---|---|---|
| 0 | 0 | 0 | 0 |
| 0 | 0 | 1 | 1 |
| 0 | 1 | 0 | 1 |
| 0 | 1 | 1 | 0 |
| 1 | 0 | 0 | 1 |
| 1 | 0 | 1 | 0 |
| 1 | 1 | 0 | 0 |
| 1 | 1 | 1 | 1 |
一般的な用途
| 用途 | 例 |
|---|---|
| 2つのビットが異なるか比較する | xor(diff, a, b) |
| 2つのビットが同じか比較する | xnor(same, a, b) |
| パリティ生成(1 が奇数個) | xor(parity, data[0], data[1], data[2], data[3]) |
| パリティチェック(1 が偶数個) | xnor(parity, data[0], data[1], data[2], data[3]) |
コード例
module xor_xnor_demo (
input a, b,
output xor_out,
output xnor_out
);
xor(xor_out, a, b);
xnor(xnor_out, a, b);
endmodule概要表
| ゲート | 出力が 1 になる条件 | 基本操作 | 演算子 |
|---|---|---|---|
| XOR | input が異なる | xor(out, a, b) | ^ |
| XNOR | input が同じ | xnor(out, a, b) | ~^ |
チャレンジ
タスクに基づいて、不足しているゲートプリミティブを追加してください。
実行すること:
- 出力
xor_result、入力xおよびyを持つ XOR ゲートを作成してください - 出力
xnor_result、入力xおよびyを持つ XNOR ゲートを作成してください
自分で試してみよう
module xor_xnor_challenge (
input x,
input y,
output xor_result,
output xnor_result
);
// TODO: XORゲートを追加 (xor_result = x ^ y)
// TODO: XNORゲートを追加 (xnor_result = x ~^ 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オンラインコンパイラ