AND OR NOT ゲート
CoddyのVerilogジャーニー「基礎」セクションの一部 — レッスン 40/90。
このレッスンでは、最も基本的な3つの論理ゲートであるAND、OR、およびNOTについて説明します。これらのゲートは、デジタル論理設計の基礎を形成します。
AND ゲート
AND ゲートは、すべての入力が 1 の場合にのみ 1 を出力します。
真理値表 (2入力):
| a | b | out |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 0 |
| 1 | 0 | 0 |
| 1 | 1 | 1 |
Verilog ゲートプリミティブ:
and(out, a, b);継続的代入による同等表現:
assign out = a & b;ORゲート
ORゲートは、少なくとも1つの入力が1のときに1を出力します。
真理値表 (2入力):
| a | b | out |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 1 |
Verilog ゲートプリミティブ:
or(out, a, b);継続的代入による同等表現:
assign out = a | b;NOTゲート
NOTゲートは、単一の入力の反対を出力します。これはインバータとも呼ばれます。
真理値表:
| a | out |
|---|---|
| 0 | 1 |
| 1 | 0 |
Verilog ゲートプリミティブ:
not(out, a);等価な継続的代入:
assign out = ~a;複数の入力
ANDゲートとORゲートは、2つ以上の入力を持つことができます:
and(out, a, b, c); // 3入力AND (out = a & b & c)
or(out, x, y, z, w); // 4入力ORNOTゲートは常にちょうど1つの入力を持ちます。
コード例
module and_or_not (
input a, b,
output and_out,
output or_out,
output not_out
);
and(and_out, a, b); // ANDゲート
or(or_out, a, b); // ORゲート
not(not_out, a); // NOTゲート (インバータ)
endmoduleチャレンジ
タスクに基づいて、不足しているゲートプリミティブを追加してください。
実行すること:
- 出力
and_result、入力pおよびqを持つ AND ゲートを作成してください - 出力
or_result、入力pおよびqを持つ OR ゲートを作成してください - 出力
not_result、入力pを持つ NOT ゲートを作成してください
チートシート
ゲートプリミティブと継続的代入を使用した、Verilogにおける基本論理ゲート:
| ゲート | プリミティブ | 代入 (Assign) | 出力が1になる条件... |
|---|---|---|---|
| AND | and(out, a, b); | assign out = a & b; | すべての入力が1のとき |
| OR | or(out, a, b); | assign out = a | b; | 少なくとも1つの入力が1のとき |
| NOT | not(out, a); | assign out = ~a; | 入力が0のとき |
ANDとORは2つ以上の入力をサポートしますが、NOTは常に1つの入力のみを持ちます:
and(out, a, b, c); // 3入力AND
or(out, a, b, c, d); // 4入力ORmodule example (input a, b, output and_out, or_out, not_out);
and(and_out, a, b);
or(or_out, a, b);
not(not_out, a);
endmodule自分で試してみよう
module gates_challenge (
input p,
input q,
output and_result,
output or_result,
output not_result
);
// TODO: ANDゲートを追加 (and_result = p & q)
// TODO: ORゲートを追加 (or_result = p | q)
// TODO: NOTゲートを追加 (not_result = ~p)
endmoduleこのレッスンには短いクイズがあります。レッスンを始めて解答し、進捗を記録しましょう。