AND OR NOT 게이트
Coddy Verilog 여정의 기초 섹션에 포함된 레슨 — 90개 중 40번째.
이 레슨에서는 가장 기본적인 세 가지 논리 게이트인 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을 출력합니다.
진리표 (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);연속 할당문(Continuous assignment) 방식:
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챌린지
작업 내용에 따라 누락된 게이트 프리미티브(gate primitives)를 추가하세요.
수행할 작업:
- 출력이
and_result이고 입력이p와q인 AND 게이트를 생성하세요. - 출력이
or_result이고 입력이p와q인 OR 게이트를 생성하세요. - 출력이
not_result이고 입력이p인 NOT 게이트를 생성하세요.
치트 시트
게이트 프리미티브(gate primitives)와 연속 할당(continuous assignment)을 사용한 Verilog의 기본 로직 게이트:
| 게이트 | 프리미티브 | 할당(Assign) | 출력이 1이 되는 경우... |
|---|---|---|---|
| AND | and(out, a, b); | assign out = a & b; | 모든 입력이 1일 때 |
| OR | or(out, a, b); | assign out = a | b; | 최소 하나의 입력이 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이 레슨에는 짧은 퀴즈가 포함되어 있습니다. 레슨을 시작해 문제를 풀고 진행 상황을 기록하세요.