Continuous Assignment
Coddy Verilog 여정의 기초 섹션에 포함된 레슨. 90개 중 37번째.
하드웨어에서 연결은 회로의 두 지점을 연결하는 물리적인 wire입니다. wire가 제자리에 놓이면 연결은 영구적이며 항상 always 활성 상태입니다. 한쪽 끝이 변경되면 다른 쪽 끝도 즉시 변경됩니다.
Verilog에서는 이 동작을 모델링할 방법이 필요합니다. 값을 wire에 전달하고 영원히 연결된 상태로 유지하려고 합니다. 이를 수행하는 과정을 continuous assignment라고 합니다.
연속 할당은 assign 키워드를 사용하여 wire와 식 사이에 영구적인 연결을 만듭니다. wire는 물리적인 전선과 마찬가지로 식의 값을 지속적으로 가집니다.
값을 한 번 작성하는 것이라기보다 wire를 납땜하는 것으로 생각하세요.
구문
assign wire_name = expression;| 구성 요소 | 의미 |
|---|---|
assign | 연속 할당을 시작하는 키워드 |
wire_name | 구동되는 와이어(reg일 수 없음) |
expression | 와이어를 구동하는 값 |
간단한 예제
wire out;
assign out = a & b;이는 out이 항상 a AND b와 always equal하다는 의미입니다. a 또는 b가 변경될 때마다 out도 즉시 변경됩니다.
작동 방식
값을 저장하는 reg와 달리, continuous assignment가 적용된 wire는 지속적으로 update됩니다:
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가 자동으로 업데이트됩니다.
다중 할당
module에는 여러 개의 연속 할당을 사용할 수 있습니다:
module multiple_assign (
input a, b, c,
output x, y
);
assign x = a & b;
assign y = x | c; // y는 x에 의존합니다
endmoduleall assignment는 병렬로 continuously 실행됩니다.
일반적인 사용
Continuous assignment은 다음과 같은 경우에 사용됩니다:
- 간단한 조합 논리 (AND, OR, XOR)
- wire를 서로 연결
- 3상태 버퍼 생성
- 조합 expression에서 output 구동
챌린지
수행할 작업:
- 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와 같게 만드는 누락된 continuous assignment를 추가하세요
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 컴파일러