Blocking Assignment
Coddy Verilog 여정의 기초 섹션에 포함된 레슨. 90개 중 49번째.
Verilog에는 두 가지 유형의 절차적 할당이 있습니다: 블로킹(=)과 논블로킹(<=)입니다. 이 레슨에서는 블로킹 할당에 초점을 맞춥니다.
Blocking assignment는 = 연산자를 uses합니다. 현재 assignment가 완료될 때까지 다음 문장의 실행을 차단하기 때문에 “블로킹”이라고 합니다. 코드는 step 단위로 순서대로 실행됩니다.
구문:
variable = expression;Blocking Assignment를 사용하는 경우
Blocking assignment(=)는 조합 논리에 사용됩니다. 조합 논리란 입력이 변경될 때 출력이 즉시 변경되며, 클록과 메모리가 없는 회로입니다.
조합 논리의 예:
- AND / OR / XOR 게이트
- 가산기와 감산기
- 멀티플렉서
- 디코더
Verilog 예제:
always @(*) begin
sum = a + b; // 블로킹 할당
carry = a & b; // 블로킹 할당
endAlways 블록에서의 Blocking (조합 논리)
always @(*) begin
temp = a & b; // 1단계
out = temp | c; // 2단계 (1단계의 temp 사용)
end순서가 중요합니다. 조합 논리에서는 문제가 없습니다.
Blocking 대 Non-Blocking
Blocking (=) | Non-Blocking (<=) | |
|---|---|---|
| 실행 | 차례대로 | 동시에 |
| 다음 줄이 기다리는가? | 예 | 아니요 |
| Uses | 조합 논리 | 순차 논리 (플립플롭) |
중요: 플립플롭에는 Blocking을 사용하지 마세요
챌린지
임시 변수를 사용하여 x와 y의 값을 교환하도록 누락된 blocking assignments를 추가하세요.
수행할 작업:
- Assign
x의 값을temp에 대입하세요 (x를temp에 저장) - Assign
y의 값을x에 대입하세요 (y를x로 이동) - Assign
temp의 값을y에 대입하세요 (savedx를y로 이동)
직접 해보기
module swap;
reg x, y;
reg temp;
initial begin
x = 1;
y = 0;
$display("Before swap: x=%d, y=%d", x, y);
// TODO: 1단계 - x를 temp에 할당
// TODO: 2단계 - y를 x에 할당
// TODO: 3단계 - temp를 y에 할당
$display("After swap: x=%d, y=%d", x, y);
$finish;
end
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 컴파일러