IEEE 1364로 표준화된 베릴로그(Verilog)는 전자 회로 및 시스템에 사용되는 하드웨어 기술 언어로, 회로 설계, 검증, 구현 등 여러 용도로 사용할 수 있다.

베릴로그
Verilog
패러다임구조적
발표일1984년 (1984)
최근 버전IEEE 1364-2005
최근 버전 출시일2005년 11월 9일(18년 전)(2005-11-09)
자료형 체계Static, weak
파일 확장자.v, .vh
방언
Verilog-AMS
영향을 받은 언어
파스칼, 에이다, C, 포트란
영향을 준 언어
SystemVerilog

C 언어와 비슷한 문법을 가져서 사용자들이 쉽게 접근할 수 있도록 만들어졌다. ‘if’나 ‘while’과 같은 제어 구조도 동일하며, 출력 루틴 및 연산자들도 거의 비슷하다. 다만 C 언어와 달리, 블록의 시작과 끝을 중괄호 기호를 사용하지 않고, 대신에 Begin과 End를 사용하여 구분하고, HDL의 특징인 시간에 대한 개념이 포함되었다는 것 등의 일반적인 프로그램과의 다른 점도 존재한다.

예제 편집

hello world 프로그램은 아래와 같다.:

module main;
  initial
    begin
      $display("Hello world!");
      $finish;
    end
endmodule

다음은, 두 개의 플립플롭을 이용한 예제이다.:

module toplevel(clock,reset);
  input clock;
  input reset;

  reg flop1;
  reg flop2;

  always @ (posedge reset or posedge clock)
    if (reset)
      begin
        flop1 <= 0;
        flop2 <= 1;
      end
    else
      begin
        flop1 <= flop2;
        flop2 <= flop1;
      end
endmodule

베릴로그에서 할당 연산자 "<="는 일반적인 언어와는 다른 기능을 수행한다. 이것은 ‘논블로킹’(non-blocking)으로 불리며, 클럭(clock)이 발생할 때, 병렬로 동시에 실행된다는 것을 의미한다. 따라서 이 예제에서 flop1과 flop2는 다음의 ‘클록 주기’(clock cycle) 마다 동시에 서로 바뀌게 될 것이다.

또 다른 할당 연산자 "="는 ‘블로킹’(blocking)이라 불리며, ‘클럭’(clock)이 발생할 때, 순차적으로 대입되며 위의 할당이 아래의 할당에 영향을 순차적으로 주게 된다는 것을 의미한다. 만일 위 예에서, "<=" 이 "=" 로 바뀌어 진다면, flop1과 flop2는 서로 변경되지 않고 그 값을 유지하게 될 것이다.

다음은 카운터 예제이다.:

module Div20x (rst, clk, cet, cep, count, tc);
// TITLE 'Divide-by-20 Counter with enables'
// enable CEP is a clock enable only
// enable CET is a clock enable and
// enables the TC output
// a counter using the Verilog language

parameter size = 5;
parameter length = 20;

input rst; // These inputs/outputs represent
input clk; // connections to the module.
input cet;
input cep;

output [size-1:0] count;
output tc;

reg [size-1:0] count; // Signals assigned
                      // within an always
                      // (or initial)block
                      // must be of type reg

wire tc; // Other signals are of type wire

// The always statement below is a parallel
// execution statement that
// executes any time the signals
// rst or clk transition from low to high

always @ (posedge clk or posedge rst)
  if (rst) // This causes reset of the cntr
    count <= {size{1'b0}};
  else
  if (cet && cep) // Enables both  true
    begin
      if (count == length-1)
        count <= {size{1'b0}};
      else
        count <= count + 1'b1;
    end

// the value of tc is continuously assigned
// the value of the expression
assign tc = (cet && (count == length-1));

endmodule

다음은 지연(delay) 예제이다.:

...
reg a, b, c, d;
wire e;
...
always @(b or e)
  begin
    a = b & e;
    b = a | b;
    #5 c = b;
    d = #6 c ^ e;
  end

외부 링크 편집