Disable Statement
Coddy Verilog 여정의 기초 섹션에 포함된 레슨. 90개 중 62번째.
disable 문은 named block의 실행을 중지합니다(forever 루프, begin-end 블록 또는 작업 등). 그렇지 않으면 무한히 실행될 루프에서 빠져나오는 데 유용합니다.
구문:
disable block_name;블록에는 이름이 지정되어 있어야 합니다.
Disable을 사용한 무한 루프
initial begin : counter // counter는 블록에 counter라는 이름을 부여합니다.
forever begin
#10 count = count + 1;
if (count == 5) begin
disable counter; // disable counter는 해당 이름의 전체 블록을 중지합니다.
end
end
endforever 루프는 named 블록 counter 안에 있습니다. disable counter 문은 루프 내부에 배치됩니다. count가 5에 도달하면 disable counter가 실행되어 전체 블록 counter를 중지하고, 이로 인해 forever 루프도 즉시 중지됩니다.
별도의 블록에서 Disable
initial begin : counter
forever begin
#10 count = count + 1;
end
end
initial begin
#50;
disable counter; // 외부에서 counter 블록을 중지합니다
end여기서 forever 루프는 이름이 counter인 블록 내부에서 계속 실행됩니다. disable counter 문은 별도의 initial 블록에 배치됩니다. 50 time units 후에 disable counter가 실행되어 counter 블록을 중지하고, 이로써 forever 루프가 외부에서 종료됩니다.
중요 규칙
| 규칙 | 설명 |
|---|---|
| Block은 이름을 지정해야 함 | begin : block_name |
| Disable은 실행을 즉시 중지함 | 코드는 그 시점에서 중지됨 |
| 어디서든 사용할 수 있음 | module의 모든 block에서 |
forever 루프를 중지하는 데 유용함 | 그렇지 않으면 절대 중지되지 않음 |
챌린지
영원히 실행되는 counter가 있는 module이 주어집니다.
할 일:
각 주석을 올바른 코드로 바꾸어 빈 block을 완성하세요:
#50;을 추가하여 50 time units 동안 기다리세요disable counter;를 추가하여 counter block을 중지하세요$display("Counter stopped");를 추가하여 메시지를 출력하세요$finish;를 추가하여 simulation을 종료하세요
직접 해보기
module disable_challenge;
integer count;
initial begin
count = 0;
fork
begin : counter
forever begin
#10 count = count + 1;
$display("count = %d", count);
end
end
begin
// 1단계: 50 시간 단위 대기
// 2단계: counter 블록 비활성화
// 3단계: "Counter stopped" 출력
// 4단계: 시뮬레이션 종료
end
join
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 컴파일러