산업 제조
산업용 사물 인터넷 | 산업자재 | 장비 유지 보수 및 수리 | 산업 프로그래밍 |
home  MfgRobots >> 산업 제조 >  >> Industrial programming >> verilog

Verilog 제어 블록

하드웨어 동작은 조건문 및 논리 흐름을 제어하는 ​​다른 방법 없이는 구현할 수 없습니다. Verilog에는 이를 달성하기 위한 일련의 제어 흐름 블록 및 메커니즘이 있습니다.

if-else-if

조건문 특정 명령문이 실행되어야 하는지 여부를 결정하는 데 사용됩니다. 이것은 if-else-if와 매우 유사합니다. 식이 true로 평가되면 첫 번째 문이 실행됩니다. 표현식이 false로 평가되고 else인 경우 부분이 존재하는 경우 else 부분이 실행됩니다.

구문
  
  
	// if statement without else part
	if (expression) 
		[statement]
	
	// if statment with an else part
	if (expression) 
		[statement]
	else 
		[statement]
	
	// if else for multiple statements should be
	// enclosed within "begin" and "end"
	if (expression) begin
		[multiple statements]
	end else begin
		[multiple statements]
	end
	
	// if-else-if statement
	if (expression)
		[statement]
	else if (expression)
		[statement]
	else 
		[statement]

  

else if-else의 일부는 선택 사항이며 else 중첩된 if 시퀀스에서는 생략됩니다. 이 혼동을 피하기 위해 else가 없는 경우 항상 이전에 else를 연결하는 것이 더 쉽습니다. 또 다른 방법은 명령문을 begin-end 안에 묶는 것입니다. 차단하다. 마지막 else 부분은 위의 항목 중 어느 것도 충족되지 않거나 다른 조건이 충족되지 않는 기본 경우를 처리합니다.

if-else-if에 대한 자세한 내용을 보려면 여기를 클릭하십시오.

루프는 블록 내에서 단일 또는 다중 명령문을 한 번 이상 실행하는 방법을 제공합니다. Verilog에는 4가지 유형의 반복문이 있습니다.

영원한 루프

이렇게 하면 블록 내의 명령문이 계속 실행됩니다.

  
  
	forever 
		[statement]

	forever begin
		[multiple statements]
	end

  

예시

  
  
module my_design;
	initial begin
		forever begin
			$display ("This will be printed forever, simulation can hang ...");
		end
	end
endmodule

  
시뮬레이션 로그
ncsim> run
This will be printed forever, simulation can hang ...
This will be printed forever, simulation can hang ...
...
...
This will be printed forever, simulation can hang ...
This will be printed forever, simulation can hang ...
This will be printed forever, simulation can hang ...
This will be printed forever, simulation can hang ...
Result reached the maximum of 5000 lines. Killing process.

반복 루프

이것은 고정된 횟수만큼 명령문을 실행합니다. 표현식이 X 또는 Z로 평가되면 0으로 처리되어 전혀 실행되지 않습니다.

  
  
	repeat ([num_of_times]) begin
		[statements]
	end
	
	repeat ([num_of_times]) @ ([some_event]) begin
		[statements]
	end

  

예시

  
  
module my_design;
	initial begin
		repeat(4) begin
			$display("This is a new iteration ...");
		end
	end
endmodule

  
시뮬레이션 로그
ncsim> run
This is a new iteration ...
This is a new iteration ...
This is a new iteration ...
This is a new iteration ...
ncsim: *W,RNQUIE: Simulation is complete.

중 루프

표현식이 참인 한 명령문을 실행하고 조건이 거짓이 되면 종료됩니다. 조건이 처음부터 거짓이면 문장이 전혀 실행되지 않습니다.

  
  
	while (expression) begin
		[statements]
	end

  

예시

  
  
module my_design;
  	integer i = 5;
  
	initial begin
      while (i > 0) begin
        $display ("Iteration#%0d", i);
        i = i - 1;
      end
	end
endmodule

  
시뮬레이션 로그
ncsim> run
Iteration#5
Iteration#4
Iteration#3
Iteration#2
Iteration#1
ncsim: *W,RNQUIE: Simulation is complete.

for 루프

  
  
	for ( initial_assignment; condition; increment_variable) begin
		[statements]
	end

  

이것은 3단계 프로세스를 사용하여 명령문을 제어합니다.

예시

  
  
module my_design;
  	integer i = 5;
  
	initial begin
      for (i = 0; i < 5; i = i + 1) begin
        $display ("Loop #%0d", i);
      end
    end
endmodule

  
시뮬레이션 로그
ncsim> run
Loop #0
Loop #1
Loop #2
Loop #3
Loop #4
ncsim: *W,RNQUIE: Simulation is complete.

for 루프에 대한 자세한 내용을 보려면 여기를 클릭하십시오.


verilog

  1. C# 식, 문 및 블록(예제 포함)
  2. Java 표현식, 명령문 및 블록
  3. Verilog 튜토리얼
  4. Verilog 연결
  5. Verilog 할당
  6. Verilog 차단 및 비 차단
  7. Verilog 제어 블록
  8. Verilog 기능
  9. Verilog 작업
  10. Verilog 지연 제어