109
Verilog HDL을 이용한 디지털시스템 설계 및 실습 1 V il HDL 개요 1. Verilog HDL 개요 Ver1.0 (2008) 1 한국기술교육대학교 정보기술공학부

1 1. VilVerilog HDL 개요Verilog HDL의역사 Verilog HDL 1983년GatewayDesignAutomationGateway Design Automation사에서하드웨어기술언어인 HiLo와C 언어의특징을기반으로개발

  • Upload
    others

  • View
    117

  • Download
    2

Embed Size (px)

Citation preview

Page 1: 1 1. VilVerilog HDL 개요Verilog HDL의역사 Verilog HDL 1983년GatewayDesignAutomationGateway Design Automation사에서하드웨어기술언어인 HiLo와C 언어의특징을기반으로개발

Verilog HDL을이용한디지털시스템설계및실습

1 V il HDL 개요1. Verilog HDL 개요

Ver1.0 (2008)1한국기술교육대학교 정보기술공학부

Page 2: 1 1. VilVerilog HDL 개요Verilog HDL의역사 Verilog HDL 1983년GatewayDesignAutomationGateway Design Automation사에서하드웨어기술언어인 HiLo와C 언어의특징을기반으로개발

Verilog HDL의역사 Verilog HDL

1983년 Gateway Design Automation사에서하드웨어기술언어인 1983년 Gateway Design Automation사에서하드웨어기술언어인HiLo와 C 언어의특징을기반으로개발

1991년 Cadence Design Systems가 Open Verilog International 1991년 Cadence Design Systems가 Open Verilog International (OVI)라는조직을구성하고 Verilog HDL을공개

1993년 IEEE Working Group이구성되어표준화작업을진행 1993년 IEEE Working Group이구성되어표준화작업을진행 1995년 12월 IEEE Std. 1364-1995로표준화 2001년에 IEEE Std 1364-2001로개정 2001년에 IEEE Std. 1364-2001로개정 Verilog HDL의확장형태인 SystemVerilog가개발되어 IEEE 표준화를추진표준화를추진

Ver1.0 (2008)2한국기술교육대학교 정보기술공학부

Page 3: 1 1. VilVerilog HDL 개요Verilog HDL의역사 Verilog HDL 1983년GatewayDesignAutomationGateway Design Automation사에서하드웨어기술언어인 HiLo와C 언어의특징을기반으로개발

Verilog 어휘규칙어휘토큰 (lexical tokens)

여백(white space)여백(white space)주석(comment)연산자(operator)연산자(operator)수(number)문자열(string)문자열(string)식별자(identifier)키워드(keyword)키워드(keyword)

Ver1.0 (2008)3한국기술교육대학교 정보기술공학부

Page 4: 1 1. VilVerilog HDL 개요Verilog HDL의역사 Verilog HDL 1983년GatewayDesignAutomationGateway Design Automation사에서하드웨어기술언어인 HiLo와C 언어의특징을기반으로개발

Verilog 어휘규칙여백(white space)

빈칸(space) 탭(tab) 줄바꿈빈칸(space), 탭(tab), 줄바꿈어휘토큰들을분리하기위해사용되는경우를제외하고는무시

공백(blank)과탭은문자열에서의미있게취급공백(blank)과탭은문자열에서의미있게취급

주석(comment) HDL소스코드의설명을위해사용되며 컴파일과정에서무시됨 HDL 소스코드의설명을위해사용되며, 컴파일과정에서무시됨단일라인주석문; // 로시작되어해당라인의끝까지블록주석문 /* */로표시블록주석문; /* ~ */ 로표시

블록주석문은내포(nested)될수없음

연산자(operator)연산자(operator)단항연산자, 2항연산자, 3항연산자

Ver1.0 (2008)4한국기술교육대학교 정보기술공학부

Page 5: 1 1. VilVerilog HDL 개요Verilog HDL의역사 Verilog HDL 1983년GatewayDesignAutomationGateway Design Automation사에서하드웨어기술언어인 HiLo와C 언어의특징을기반으로개발

Verilog 어휘규칙수표현 (number representation)

정수형(integer) ; 10진수, 16진수, 8진수, 2진수정수형(integer) ; 10진수, 16진수, 8진수, 2진수

형식 : [size_constant]'<base_format> <number_value>

[size_constant]: 값의비트크기를나타내는상수 0이아닌 unsigned 10진수가사용되며, 생략될수있음 unsized수 (즉,단순 10진수또는비트크기가지정되지않은수)는unsized 수 (즉, 단순 10진수또는비트크기가지정되지않은수)는

32비트로표현됨 상위비트가 x(unknown) 또는 z(high-impedance)인 unsized unsigned 상수는그상수가사용되는수식의비트크기만큼확장됨상수는그상수가사용되는수식의비트크기만큼확장됨

'base_format : 밑수(base)를지정하는문자(d, D, h, H, o, O, b, B) signed를나타내기위해문자 s 또는 S가함께사용될수있음

b l unsigned숫자를사용하여값을표현 number_value : unsigned 숫자를사용하여값을표현 'base_format에적합한숫자들로구성

base_format과 number_value사이에+또는-부호사용불가

Ver1.0 (2008)5한국기술교육대학교 정보기술공학부

Page 6: 1 1. VilVerilog HDL 개요Verilog HDL의역사 Verilog HDL 1983년GatewayDesignAutomationGateway Design Automation사에서하드웨어기술언어인 HiLo와C 언어의특징을기반으로개발

Verilog 어휘규칙수표현 (number representation)

비트크기와밑수를갖지않는단순 10진수는 signed정수로취급비트크기와밑수를갖지않는단순 10진수는 signed 정수로취급부호지정자없이밑수만지정되면 unsigned 정수로취급밑수지정자와부호지정자 s가함께사용되면 signed 정수로취급g

부호지정자 s는비트패턴에는영향을미치지않으며, 비트패턴의해석에만영향을미침

’음수는 2의보수(2’s complementary) 형식으로표현됨지정된비트크기보다 unsigned 수의크기가작은경우

MSB왼쪽에 0이삽입 MSB 왼쪽에 0이삽입 MSB가 x 또는 z이면, x 또는 z가왼쪽에삽입

값에물음표( ? )가사용되면 z로취급에물 ( )가사용되 취급

첫번째문자를제외하고는밑줄(underscore)이사용될수있으며, 이는수의가독성(readability)을좋게함

Ver1.0 (2008)6한국기술교육대학교 정보기술공학부

Page 7: 1 1. VilVerilog HDL 개요Verilog HDL의역사 Verilog HDL 1983년GatewayDesignAutomationGateway Design Automation사에서하드웨어기술언어인 HiLo와C 언어의특징을기반으로개발

Verilog 어휘규칙

10 32 Decimal 10 00....01010

Number # of Bits Base Dec. Equiv. Stored

2’b10 2 Binary 2 103’d5 3 Decimal 5 1018’o5 8 Octal 5 00000101’h8’ha 8 Hex 10 00001010

3’b5 Invalid!3’b01x 3 Binary - 01x

’h12’hx 12 Hex - xxxxxxxxxxxx8’b0000_0001 8 Binary 1 000000018’bx01 8 Binary - xxxxxx01’b d (32b )’bz Unsized Binary - zz...zz(32bits)8’HAD 8 Hex 173 10101101

Ver1.0 (2008)7한국기술교육대학교 정보기술공학부

Page 8: 1 1. VilVerilog HDL 개요Verilog HDL의역사 Verilog HDL 1983년GatewayDesignAutomationGateway Design Automation사에서하드웨어기술언어인 HiLo와C 언어의특징을기반으로개발

Verilog 어휘규칙

659 // a decimal number'h837FF // a hexadecimal numberh837FF // a hexadecimal number'o7460 // an octal number4af // illegal (hexadecimal format requires 'h)

4'b1001 // a 4-bit binary number5'D3 // a 5-bit decimal number3'b01x // a 3-bit number with the LSB unknown//12'hx // a 12-bit unknown number16'hz // a 16-bit high-impedance number

Ver1.0 (2008)8한국기술교육대학교 정보기술공학부

Page 9: 1 1. VilVerilog HDL 개요Verilog HDL의역사 Verilog HDL 1983년GatewayDesignAutomationGateway Design Automation사에서하드웨어기술언어인 HiLo와C 언어의특징을기반으로개발

Verilog 어휘규칙

8'd-6 // illegal syntax-8'd6 // this defines the two’s complement of -6,

// held in 8 bits, equivalent to -(8'd6)4' hf // thi d t th 4 bit b '1111' t4'shf // this denotes the 4-bit number '1111', to

// be interpreted as a 2's complement number,// or '-1'. This is equivalent to -4'h1

-4'sd15 // this is equivalent to -(-4'd1), or '0001'q ( ),-'d12 // 4294967284-'sd12 // -12

27 195 00027_195_00016'b0011_0101_0001_111132'h 12ab_f001

Ver1.0 (2008)9한국기술교육대학교 정보기술공학부

Page 10: 1 1. VilVerilog HDL 개요Verilog HDL의역사 Verilog HDL 1983년GatewayDesignAutomationGateway Design Automation사에서하드웨어기술언어인 HiLo와C 언어의특징을기반으로개발

Verilog 어휘규칙

reg [11:0] a, b, c, d;initial beging

a = 'hx; // yields xxxb = 'h3x; // yields 03xc = 'hz3; // yields zz3d 'h0 3 // i ld 0 3d = 'h0z3; // yields 0z3

end

Ver1.0 (2008)10한국기술교육대학교 정보기술공학부

Page 11: 1 1. VilVerilog HDL 개요Verilog HDL의역사 Verilog HDL 1983년GatewayDesignAutomationGateway Design Automation사에서하드웨어기술언어인 HiLo와C 언어의특징을기반으로개발

Verilog 어휘규칙실수형(real) ; IEEE Std. 754-1985(IEEE standard for double-

precision floating-point number)p g p )

1 21.22394.263311.2E121.30e-20.1e-029E-2236.123_763_e-12 (underscores are ignored)

문법적오류

.129.4.E32e-7

Ver1.0 (2008)11

.2e-7

한국기술교육대학교 정보기술공학부

Page 12: 1 1. VilVerilog HDL 개요Verilog HDL의역사 Verilog HDL 1983년GatewayDesignAutomationGateway Design Automation사에서하드웨어기술언어인 HiLo와C 언어의특징을기반으로개발

Verilog 어휘규칙문자열(string)

이중인용부호(“ ”)사이에있는일련의문자들이중인용부호(“ ”) 사이에있는일련의문자들단일라인에존재해야하며, 여러라인에걸친문자열은사용불가 8비트 ASCII값으로표현되는 unsigned정수형상수로취급 8비트 ASCII 값으로표현되는 unsigned 정수형상수로취급문자열변수는 reg형의변수이며, 문자열내의문자수에 8을곱한크기의비트폭을가짐크기의비트폭을가짐

reg [8*12:1] string_var;

initial beginstring_var = "Hello world!";

end

Ver1.0 (2008)12한국기술교육대학교 정보기술공학부

Page 13: 1 1. VilVerilog HDL 개요Verilog HDL의역사 Verilog HDL 1983년GatewayDesignAutomationGateway Design Automation사에서하드웨어기술언어인 HiLo와C 언어의특징을기반으로개발

Verilog 어휘규칙

module string_test;reg [8*14:1] stringvar;

initial beginstringvar = "Hello world";$display("%s is stored as %h", stringvar, stringvar);stringvar = {stringvar "!!!"};stringvar = {stringvar,"!!!"};$display("%s is stored as %h", stringvar, stringvar);

endendmodule

Hello world is stored as 00000048656c6c6f20776f726c64Hello world!!! is stored as 48656c6c6f20776f726c64212121

Ver1.0 (2008)13한국기술교육대학교 정보기술공학부

Page 14: 1 1. VilVerilog HDL 개요Verilog HDL의역사 Verilog HDL 1983년GatewayDesignAutomationGateway Design Automation사에서하드웨어기술언어인 HiLo와C 언어의특징을기반으로개발

Verilog 어휘규칙특수문자앞에확장문자(escaped character)를사용하면일부특수문자를문자열에포함시킬수있음특수문자를문자열에포함시킬수있음

확장문자를이용한특수문자의표현

확장문자열 확장문자열에의해생성되는특수문자

\n New line character

\t T b h t\t Tab character

\\ \ character

\" " character\ character

\ddd A character specified in 1~3 octal digits (0≤d≤7)

Ver1.0 (2008)14한국기술교육대학교 정보기술공학부

Page 15: 1 1. VilVerilog HDL 개요Verilog HDL의역사 Verilog HDL 1983년GatewayDesignAutomationGateway Design Automation사에서하드웨어기술언어인 HiLo와C 언어의특징을기반으로개발

Verilog 어휘규칙식별자(identifier)

객체에고유의이름을지정하기위해사용객체에고유의이름을지정하기위해사용

대소문자를구별하여인식

가독성을위해밑줄사용가능가독성을위해밑줄사용가능

단순식별자; 일련의문자, 숫자, 기호 $, 밑줄등으로구성 첫번째문자는숫자나기호 $사용불가 문자또는밑줄만사용 첫번째문자는숫자나기호 $ 사용불가, 문자또는밑줄만사용

확장식별자(escaped identifier); \ (back slash)로시작되며,여백(빈칸,탭,줄바꿈)등으로끝남 \ (back slash)로시작되며, 여백(빈칸, 탭, 줄바꿈) 등으로끝남 프린트가능한 ASCII 문자들을식별자에포함시키는수단을제공

키워드(keyword)키워드(keyword) Verilog 구성요소를정의하기위해미리정의된식별자확장문자가포함된키워드는키워드로인식되지않음

Ver1.0 (2008)15

확장문자가포함된키워드는키워드로인식되지않음

한국기술교육대학교 정보기술공학부

Page 16: 1 1. VilVerilog HDL 개요Verilog HDL의역사 Verilog HDL 1983년GatewayDesignAutomationGateway Design Automation사에서하드웨어기술언어인 HiLo와C 언어의특징을기반으로개발

Verilog 어휘규칙

유효한식별자의예

shiftreg_abusa_indexerror_conditionmerge_ab_bus3n$657

\busa+index\-clock\***error-condition***\net1/\net2\{a,b}\a*(b+c)

Ver1.0 (2008)16한국기술교육대학교 정보기술공학부

Page 17: 1 1. VilVerilog HDL 개요Verilog HDL의역사 Verilog HDL 1983년GatewayDesignAutomationGateway Design Automation사에서하드웨어기술언어인 HiLo와C 언어의특징을기반으로개발

Verilog 어휘규칙

l if l

Verilog keyword (일부)alwaysandassignautomaticbegin

ififnoneincdirincludeinitial

releaserepeatrnmosrpmosrtranbegin

bufbufif0bufif1case

initialinoutinputinstanceinteger

rtranrtranif0rtranif1scalaredshowcancelled

casexcasezcellcmosconfig

joinlargeliblistlibrarylocalparam

signedsmallspecifyspecparamstrong0config

deassigndefaultdefparamdesign

localparammacromodulemediummodulenand

strong0strong1supply0supply1table

disableedgeelseendendcase

negedgenmosnornotnotif0

tasktimetrantranif0tranif1

Ver1.0 (2008)17

endcase notif0 tranif1

한국기술교육대학교 정보기술공학부

Page 18: 1 1. VilVerilog HDL 개요Verilog HDL의역사 Verilog HDL 1983년GatewayDesignAutomationGateway Design Automation사에서하드웨어기술언어인 HiLo와C 언어의특징을기반으로개발

Verilog HDL 개요

Verilog HDLVerilog HDL

논리합성 Simulation

assign,if~else,

논리합성

initial,$finish

Simulation

case, foralways

$finish$fopen

specifyp y$widthtable

Library

Verilog HDL구문

Ver1.0 (2008)18

Verilog HDL 구문

한국기술교육대학교 정보기술공학부

Page 19: 1 1. VilVerilog HDL 개요Verilog HDL의역사 Verilog HDL 1983년GatewayDesignAutomationGateway Design Automation사에서하드웨어기술언어인 HiLo와C 언어의특징을기반으로개발

Verilog HDL의모듈

module module name (port list); Semicolonmodule module_name (port_list);

port 선언reg선언

Semicolon

reg 선언wire 선언parameter 선언

하위모듈호출

always, initial 문function, task 정의문assign 문function task호출문

endmodule

function, task 호출문

No Semicolon

Ver1.0 (2008)19한국기술교육대학교 정보기술공학부

Page 20: 1 1. VilVerilog HDL 개요Verilog HDL의역사 Verilog HDL 1983년GatewayDesignAutomationGateway Design Automation사에서하드웨어기술언어인 HiLo와C 언어의특징을기반으로개발

Verilog HDL의모듈wire, reg wire wire

input

wire

inout output

wire, reg

Module_instance_A

wire

Module_instance_B

wire,regi

wire

Primitiveinstantiation

wire, reg

regwirewire wire

wire

alwaysbegin. . . endContinuous

assignment

initialbegin. . .

Behavior_1assignment

assign wire_A = C | D;end

Behavior_2reg reg_A, reg_B, . . .integer int A

register variables

d l ti

Ver1.0 (2008)20

integer int_A, . . . declarations

한국기술교육대학교 정보기술공학부

Page 21: 1 1. VilVerilog HDL 개요Verilog HDL의역사 Verilog HDL 1983년GatewayDesignAutomationGateway Design Automation사에서하드웨어기술언어인 HiLo와C 언어의특징을기반으로개발

Verilog 모델링예 게이트프리미티브를이용한모델링예 (반가산기회로)

module half add1 (a b sum cout);

Module Name Module Portsa b cout sum0 0 0 0module half_add1 (a, b, sum, cout);

input a, b;output sum, cout;wire cout bar;

Declaration of d

0 1 0 11 0 0 11 1 1 0wire cout_bar;

xor (sum, a, b);d ( t b b)

port modes

Declaration of l l

1 1 1 0

nand (cout_bar, a, b);not (cout, cout_bar);

endmodule

internal signalsHalf_ Adder

sum = a ^ bcout = a & b

a

b

sum

cout

Instantiation of Primitive gatesVerilog keyword

cout a & b

Ver1.0 (2008)21한국기술교육대학교 정보기술공학부

Page 22: 1 1. VilVerilog HDL 개요Verilog HDL의역사 Verilog HDL 1983년GatewayDesignAutomationGateway Design Automation사에서하드웨어기술언어인 HiLo와C 언어의특징을기반으로개발

Verilog 모델링예연속할당문을이용한모델링

module half_adder2(a, b, sum, cout);input a, b;p ,output sum, cout;

assign cout = a & b;assign sum a ^ b;assign sum = a ^ b;

endmodule

Ver1.0 (2008)22한국기술교육대학교 정보기술공학부

Page 23: 1 1. VilVerilog HDL 개요Verilog HDL의역사 Verilog HDL 1983년GatewayDesignAutomationGateway Design Automation사에서하드웨어기술언어인 HiLo와C 언어의특징을기반으로개발

Verilog 모델링예행위수준모델링 (조합논리회로)

module mux2b_if(in0, in1, sel, out);input [1:0] in0, in1;input sel;output [1:0] out;reg [1:0] out;

MUXin0

out2

2

always @(sel or in0 or in1) beginif (sel ==0)

out = in0;

MUXin1

out2

elseout = in1;

endendmodule

sel

endmodule

Ver1.0 (2008)23한국기술교육대학교 정보기술공학부

Page 24: 1 1. VilVerilog HDL 개요Verilog HDL의역사 Verilog HDL 1983년GatewayDesignAutomationGateway Design Automation사에서하드웨어기술언어인 HiLo와C 언어의특징을기반으로개발

Verilog 모델링예행위수준모델링 (순차회로)

module flip-flop (q, din, clk, rst);input din, clk, rst;output q;output q;reg q;

always @(posedge clk or posedge rst)always @(posedge clk or posedge rst)begin

if (rst == 1) q <= 0;

else q <= din;

endendmodule

Ver1.0 (2008)24한국기술교육대학교 정보기술공학부

Page 25: 1 1. VilVerilog HDL 개요Verilog HDL의역사 Verilog HDL 1983년GatewayDesignAutomationGateway Design Automation사에서하드웨어기술언어인 HiLo와C 언어의특징을기반으로개발

Verilog 모델링예하위모듈인스턴스를이용한구조적모델링

module full_add (a, b, cin, sum, cout);( )input a, b, cin;output sum, cout;wire w1, w2, w3; //생략가능, , ; //

half_add1 U1 (a, b, w1, w2);half add2 U2 (w1, cin, sum, w3);half_add2 U2 (w1, cin, sum, w3);or U3 (cout, w2, w3);

endmodule

Module instantiation

Ver1.0 (2008)25한국기술교육대학교 정보기술공학부

Page 26: 1 1. VilVerilog HDL 개요Verilog HDL의역사 Verilog HDL 1983년GatewayDesignAutomationGateway Design Automation사에서하드웨어기술언어인 HiLo와C 언어의특징을기반으로개발

Verilog 모델링예테스트벤치모듈

HDL모델을시뮬레이션하기위한 Verilog모듈 HDL 모델을시뮬레이션하기위한 Verilog 모듈 DUT에인가될시뮬레이션입력(stimulus)을생성하는구문 시뮬레이션대상이되는모듈(Design Under Test; DUT)의인스턴스 시뮬레이션입력에대한 DUT의반응(response)을관찰하는구문

Sti lStimulusGenerator

Design Under Test(DUT)

Response Monitor

Ver1.0 (2008)26한국기술교육대학교 정보기술공학부

Page 27: 1 1. VilVerilog HDL 개요Verilog HDL의역사 Verilog HDL 1983년GatewayDesignAutomationGateway Design Automation사에서하드웨어기술언어인 HiLo와C 언어의특징을기반으로개발

Verilog 모델링예

module test_fix ();reg A, B, C;

Verilog Testbench 예

circuit c1(A, B, C, Out);// DUT

initial begin A=0; B=1; C=0;

#50 A=1;#50 A=0; C=1;#50 C=0;#50 C=0;#50 $finish;

end endmodule

Ver1.0 (2008)27한국기술교육대학교 정보기술공학부

Page 28: 1 1. VilVerilog HDL 개요Verilog HDL의역사 Verilog HDL 1983년GatewayDesignAutomationGateway Design Automation사에서하드웨어기술언어인 HiLo와C 언어의특징을기반으로개발

Verilog 모델링예

module tb_ha ;reg a, b;

h lf dd U0 h lf dd ( b t)

반가산기의테스트벤치예

half_adder U0_half_adder(a, b, sum, cout);

initial begina = 0; b = 0;

#10 a = 1;#10 a = 0;

b = 1;#10 a 1#10 a = 1;#10 a = 0;

b = 0;end

endmodule

Ver1.0 (2008)28한국기술교육대학교 정보기술공학부

Page 29: 1 1. VilVerilog HDL 개요Verilog HDL의역사 Verilog HDL 1983년GatewayDesignAutomationGateway Design Automation사에서하드웨어기술언어인 HiLo와C 언어의특징을기반으로개발

Verilog 모델링예module tb_dff_sr ;

reg set, reset, clock, din;D 플립플롭의테스트벤치예

dff_sr U0_dff_sr (set, reset, clock, din, q, qb);

initial beginclock = 1'b0;forever begin

#10 clock = ~clock;end

end

initial beginforever begin

din = 0; reset = 1; set = 1;#15 din = 1;#15 din 1;#30 reset = 0;#10 reset = 1;#25 din = 0;#20 set = 0;#10 1#10 set = 1;#30 din = 0;

endendendmodule

Ver1.0 (2008)29

endmodule

한국기술교육대학교 정보기술공학부

Page 30: 1 1. VilVerilog HDL 개요Verilog HDL의역사 Verilog HDL 1983년GatewayDesignAutomationGateway Design Automation사에서하드웨어기술언어인 HiLo와C 언어의특징을기반으로개발

Verilog HDL을이용한디지털시스템설계및실습

2 자료형과 연산자2. 자료형과 연산자

Ver1.0 (2008)30한국기술교육대학교 정보기술공학부

Page 31: 1 1. VilVerilog HDL 개요Verilog HDL의역사 Verilog HDL 1983년GatewayDesignAutomationGateway Design Automation사에서하드웨어기술언어인 HiLo와C 언어의특징을기반으로개발

2.1.1 Verilog의논리값

표 2.1 Verilog의논리값집합

논리값 의 미

0 logic zero, or false condition

1 logic one, or true condition

x unknown logic value

z high-impedance state

Ver1.0 (2008)31한국기술교육대학교 정보기술공학부

Page 32: 1 1. VilVerilog HDL 개요Verilog HDL의역사 Verilog HDL 1983년GatewayDesignAutomationGateway Design Automation사에서하드웨어기술언어인 HiLo와C 언어의특징을기반으로개발

2.1.1 Verilog의논리값

Zero, low, false, logic low, ground, ‘0’VSS

One high true logic high power ‘1’ One, high, true, logic high, power, VDD, VCC

‘1’

X, unknown : occurs at logical conflict which cannot be resolved ‘x’

HiZ, high impedence, tri-stated, disabled or disconnected driverdisabled or disconnected driver

‘z’

‘0’

Ver1.0 (2008)32

‘0’

한국기술교육대학교 정보기술공학부

Page 33: 1 1. VilVerilog HDL 개요Verilog HDL의역사 Verilog HDL 1983년GatewayDesignAutomationGateway Design Automation사에서하드웨어기술언어인 HiLo와C 언어의특징을기반으로개발

Verilog HDL의자료형 Net 자료형 : 소자간의물리적인연결을추상화

wire, tri, wand, wor, triand, trior, supply0, supply1, tri0, tri1, trireg Default 자료형 ; 1비트의 wire

Variable 자료형 : 절차형할당문사이의값의임시저장 프로그래밍언어의 i bl 과유사한개념 프로그래밍언어의 variable과유사한개념 reg, integer, real, time, realtime

할당모드

자료형

net 자료형과 variable 자료형의할당모드

YesNoNoYesYesNet

force… release PCA

assign… deassign PCA

절차형

할당문연속할당문

프리미티브

출력

자료형

YesYesYesNoComb (No)Seq (Yes)Variable

YesNoNoYesYesNet

Ver1.0 (2008)33

* PCA : Procedural Continuous Assignment

한국기술교육대학교 정보기술공학부

Page 34: 1 1. VilVerilog HDL 개요Verilog HDL의역사 Verilog HDL 1983년GatewayDesignAutomationGateway Design Automation사에서하드웨어기술언어인 HiLo와C 언어의특징을기반으로개발

2.1.2 net 자료형 net 자료형

논리게이트나모듈등의하드웨어요소들사이의물리적연결을논리게이트나모듈등의하드웨어요소들사이의물리적연결을

나타내기위해사용

연속할당문( ti i t) 게이트프리미티브등과연속할당문(continuous assignment), 게이트프리미티브등과같은구동자(driver)의값에의해 net의값이연속적으로유지됨 값을저장하지않음 (단 trireg net는예외) 값을저장하지않음 (단, trireg net는예외)

구동자가연결되지않으면, default 값인 high-impedance (z)가됨 단 trireg net는이전에구동된값을유지 단, trireg net는이전에구동된값을유지

default 자료형은 1비트의 wire default초기값은 z default 초기값은 z

trireg net는 default 초기값으로 x를가짐

Ver1.0 (2008)34한국기술교육대학교 정보기술공학부

Page 35: 1 1. VilVerilog HDL 개요Verilog HDL의역사 Verilog HDL 1983년GatewayDesignAutomationGateway Design Automation사에서하드웨어기술언어인 HiLo와C 언어의특징을기반으로개발

2.1.2 net 자료형

자료형이름 의 미

표 2.2 Verilog net 자료형

wire 함축된논리적동작이나기능을갖지않는단순한연결을위한 net

tri 함축된논리적동작이나기능을갖지않는단순한연결을위한 net이며, 하드웨어에서 3상태(tri-state)가되는점이 wire와다름

wand 다중구동자를갖는 net이며, ‘wired-and’(즉, open collector logic)의하드웨어구현을모델링하기위해사용

wor 다중구동자를갖는 net이며, ‘wired-or’(즉, emitter coupled logic)의하드웨어구현을모델링하기위해사용모델링하기위해사용

triand wand와동일하게다중구동자를갖는 net이며, 하드웨어에서 3상태(tri-state)를갖는점이다름

wor와동일하게다중구동자를갖는 net이며 하드웨어에서 3상태(tri state)를갖는trior wor와동일하게다중구동자를갖는 net이며, 하드웨어에서 3상태(tri-state)를갖는점이다름

supply0 회로접지(circuit ground)에연결되는 net

supply1 전원(power supply)에연결되는 netsupply1 전원(power supply)에연결되는 net

tri0 저항성 pulldown (resistive pulldown)에의해접지로연결되는 net

tri1 저항성 pullup (resistive pullup)에의해전원으로연결되는 net

Ver1.0 (2008)35

trireg 물리적인 net에저장되는전하를모델링하는 net

한국기술교육대학교 정보기술공학부

Page 36: 1 1. VilVerilog HDL 개요Verilog HDL의역사 Verilog HDL 1983년GatewayDesignAutomationGateway Design Automation사에서하드웨어기술언어인 HiLo와C 언어의특징을기반으로개발

2.1.2 net 자료형

i 1 2 // d l t i 생략 가능wire w1, w2; // declares two wires, 생략 가능wire [7:0] bus; // a 8-bit buswire enable=1'b0; // wire with initial value of 0wand w3; // a scalar net of type wandyptri [15:0] busa; // a three-state 16-bit bus

Ver1.0 (2008)36한국기술교육대학교 정보기술공학부

Page 37: 1 1. VilVerilog HDL 개요Verilog HDL의역사 Verilog HDL 1983년GatewayDesignAutomationGateway Design Automation사에서하드웨어기술언어인 HiLo와C 언어의특징을기반으로개발

2.1.2 net 자료형 wire와 tri

회로구성요소들사이의연결에사용

wire : 단일게이트또는단일연속할당문에의해구동되는 net에사용 tri : 3상태 net에사용

wire/tri 0 1 x z

표 2.3 wire, tri net의진리표

wire/tri 0 1 x z

0 0 x x 0

1 x 1 x 11 x 1 x 1

x x x x x

0 1z 0 1 x z

Ver1.0 (2008)37한국기술교육대학교 정보기술공학부

Page 38: 1 1. VilVerilog HDL 개요Verilog HDL의역사 Verilog HDL 1983년GatewayDesignAutomationGateway Design Automation사에서하드웨어기술언어인 HiLo와C 언어의특징을기반으로개발

2.1.2 net 자료형 wired net

다중구동자를갖는설계를지원하기위해사용다중구동자를갖는설계를지원하기위해사용

표 2.4 wand, triand net의진리표 표 2.5 wor, trior net의진리표

wand/triand

0 1 x z

0 0 0 0 0

wor/trior

0 1 x z

0 0 1 00 0 0 0 0

1 0 1 x 1

0 x x x

0 0 1 x 0

1 1 1 1 1

1x 0 x x x

z 0 1 x z

x x 1 x x

z 0 1 x z

Ver1.0 (2008)38한국기술교육대학교 정보기술공학부

Page 39: 1 1. VilVerilog HDL 개요Verilog HDL의역사 Verilog HDL 1983년GatewayDesignAutomationGateway Design Automation사에서하드웨어기술언어인 HiLo와C 언어의특징을기반으로개발

2.1.2 net 자료형

module wand_ex ;reg a, b, c;wire w_nor, w_buf, w_wire;wand w wand;

코드 2.1

wand w_wand;

initial begina=0; b=0; c=0;

#50 a=1; b=1; 시뮬레이션결과#50 a=1; b=1;endnor(w_nor, a, b);buf(w_buf, c);

시뮬레이션결과

nor(w_wire, a, b);buf(w_wire, c);

( d b)nor(w_wand, a, b);buf(w_wand, c);

endmodule

Ver1.0 (2008)39한국기술교육대학교 정보기술공학부

Page 40: 1 1. VilVerilog HDL 개요Verilog HDL의역사 Verilog HDL 1983년GatewayDesignAutomationGateway Design Automation사에서하드웨어기술언어인 HiLo와C 언어의특징을기반으로개발

2.1.2 net 자료형 tri0와 tri1

tri0 :저항성 pull down에의해접지로연결되는 net에사용 tri0 : 저항성 pull-down에의해접지로연결되는 net에사용 구동자에의해구동되지않으면 net의값은 0

tri1 : 저항성 pull-up에의해전원으로연결되는 net에사용저항성 p p에의해 결되 에사용

구동자에의해구동되지않으면 net의값은 1표 2.6 tri0 net의진리표 표 2.7 tri1 net의진리표

tri1 0 1 x z

0 0 x x 0

tri0 0 1 x z

0 0 x x 0

1 x 1 x 1

x x x x x

1 x 1 x 1

x x x x x

z 0 1 x 1z 0 1 x 0

Ver1.0 (2008)40한국기술교육대학교 정보기술공학부

Page 41: 1 1. VilVerilog HDL 개요Verilog HDL의역사 Verilog HDL 1983년GatewayDesignAutomationGateway Design Automation사에서하드웨어기술언어인 HiLo와C 언어의특징을기반으로개발

2.1.3 variable 자료형 variable 자료형 ; reg, integer, real, time, realtime

절차적할당문(procedural assignment)의실행에의해그값이절차적할당문(procedural assignment)의실행에의해그값이바뀌며, 할당에서부터다음할당까지값을유지

default초기값 default 초기값 reg, time, integer 자료형 : x (unknown) real, realtime 자료형 : 0.0

variable이음의값을할당받는경우, signed reg, integer, real, realtime 자료형 : 부호를유지 i d ti 자료형 i d값으로취급 unsigned reg, time 자료형 : unsigned 값으로취급

Ver1.0 (2008)41한국기술교육대학교 정보기술공학부

Page 42: 1 1. VilVerilog HDL 개요Verilog HDL의역사 Verilog HDL 1983년GatewayDesignAutomationGateway Design Automation사에서하드웨어기술언어인 HiLo와C 언어의특징을기반으로개발

2.1.3 variable 자료형 reg

절차적할당문에의해값을받는객체의자료형절차적할당문에의해값을받는객체의자료형

할당사이의값을유지

하드웨어레지스터를모델링하기위해사용될수있음하드웨어레지스터를모델링하기위해사용될수있음

edge-sensitive (플립플롭등)와 level-sensitive (래치등)의저장소자들을모델링할수있음

reg는조합논리회로의모델링에도사용되므로, reg가항상하드웨어적인저장소자를의미하지는않음

reg a; // a scalar regreg[3 0] // a 4 bit ector reg made p of(from most toreg[3:0] v; // a 4-bit vector reg made up of(from most to

// least significant) v[3], v[2], v[1], and v[0]reg signed [3:0] signed_reg; // a 4-bit vector in range -8 to 7reg [-1:4] b; // a 6-bit vector reg

[4 0] // d l th 5 bit

Ver1.0 (2008)42

reg [4:0] x, y, z; // declares three 5-bit regs

한국기술교육대학교 정보기술공학부

Page 43: 1 1. VilVerilog HDL 개요Verilog HDL의역사 Verilog HDL 1983년GatewayDesignAutomationGateway Design Automation사에서하드웨어기술언어인 HiLo와C 언어의특징을기반으로개발

2.1.3 variable 자료형

module mux21_if(a, b, sel, out);input [1:0] a, b;

module dff (clk, d, q);input d ,clk; p [ ] ,

input sel;output [1:0] out;reg [1:0] out;

p ,output q;reg q;

always @(posedge clk)always @(a or b or sel)

if(sel == 1'b0) out = a;

always @(posedge clk)q <= d;

endmodule D 플립플롭else

out = b;endmodule 2 : 1 MUX

Ver1.0 (2008)43한국기술교육대학교 정보기술공학부

Page 44: 1 1. VilVerilog HDL 개요Verilog HDL의역사 Verilog HDL 1983년GatewayDesignAutomationGateway Design Automation사에서하드웨어기술언어인 HiLo와C 언어의특징을기반으로개발

2.1.3 variable 자료형 integer 자료형

정수형값을취급하며 절차적할당문에의해값이변경됨정수형값을취급하며, 절차적할당문에의해값이변경됨 signed reg로취급되며, 연산결과는 2의보수가됨

time자료형 time 자료형시뮬레이션시간을처리하거나저장하기위해사용됨

64비트의 와동일하게작용 64비트의 reg와동일하게작용 unsigned 값이고 unsigned 연산이이루어짐

l ti 자료형 real, reatime 자료형실수형값을취급

integer a; // integer valuetime last_chng; // time valuereal float ; // a variable to store real value

Ver1.0 (2008)44

realtime rtime ; // a variable to store time as a real value

한국기술교육대학교 정보기술공학부

Page 45: 1 1. VilVerilog HDL 개요Verilog HDL의역사 Verilog HDL 1983년GatewayDesignAutomationGateway Design Automation사에서하드웨어기술언어인 HiLo와C 언어의특징을기반으로개발

2.1.4벡터벡터

범위지정 [ b l b]을갖는다중비트의 t또는 자료형범위지정 [msb:lsb]을갖는다중비트의 net 또는 reg 자료형 signed로선언되거나 signed로선언된포트에연결되는경우를제외하고는 i d로취급제외하고는 unsigned로취급

단일할당문으로값을받을수있음

data_type [msb:lsb] identifier;

reg [7:0] rega; // 8-bit regwire [15:0] d_out; // 16-bit wire

Ver1.0 (2008)45한국기술교육대학교 정보기술공학부

Page 46: 1 1. VilVerilog HDL 개요Verilog HDL의역사 Verilog HDL 1983년GatewayDesignAutomationGateway Design Automation사에서하드웨어기술언어인 HiLo와C 언어의특징을기반으로개발

2.1.5배열배열

별도의자료형이없으며 reg또는 wire선언을이용하여선언별도의자료형이없으며, reg또는 wire 선언을이용하여선언배열전체또는일부분은단일할당문에의해값을할당받을수

없으며,또한수식에사용될수없음없으며, 또한수식에사용될수없음 배열을구성하는 element만단일할당문으로값을할당받을수있음

RAM, ROM, Register File 등의메모리모델링에사용

d t t id tifi [U dd L dd ][U dd 2 L dd 2]

2차원배열data_type identifier [Uaddr:Laddr][Uaddr2:Laddr2];

벡터의 1차원배열data_type [msb:lsb] identifier [Uaddr:Laddr][Uaddr2:Laddr2];

Ver1.0 (2008)46한국기술교육대학교 정보기술공학부

Page 47: 1 1. VilVerilog HDL 개요Verilog HDL의역사 Verilog HDL 1983년GatewayDesignAutomationGateway Design Automation사에서하드웨어기술언어인 HiLo와C 언어의특징을기반으로개발

2.1.5배열

reg [7:0] mema[0:255]; // a memory mema of 256 8-bit registersreg arrayb[7:0][0:255]; // a 2-D array of 1-bit registerswire w_array[7:0][5:0]; // an array of wiresinteger inta[1:64]; // an array of 64 integer valuesinteger inta[1:64]; // an array of 64 integer valuestime chng_hist[1:1000]; // an array of 1000 time values

mema = 0; // Illegal syntax- Attempt to write to entire arrayarrayb[1] = 0; // Illegal Syntax - Attempt to write to elementsarrayb[1] 0; // Illegal Syntax Attempt to write to elements

// [1][0]..[1][255]arrayb[1][12:31] = 0; // Illegal Syntax - Attempt to write to

// elements [1][12]..[1][31]mema[1] = 0; // Assigns 0 to the second element of memamema[1] 0; // Assigns 0 to the second element of memaarrayb[1][0] = 0; // Assigns 0 to the bit referenced by indices [1][0]inta[4] = 33559; // Assign decimal number to integer in arraychng_hist[t_index] = $time; // Assign current simulation time to

// element addressed by integer index

Ver1.0 (2008)47

// element addressed by integer index

한국기술교육대학교 정보기술공학부

Page 48: 1 1. VilVerilog HDL 개요Verilog HDL의역사 Verilog HDL 1983년GatewayDesignAutomationGateway Design Automation사에서하드웨어기술언어인 HiLo와C 언어의특징을기반으로개발

2.1.5배열

메모리

reg형요소를갖는 1차원배열메모리전체가단일할당문으로값을할당받을수없음

인덱스로지정되는워드단위로만값을할당하거나수식에사용될수

있음

reg [1:n] rega; // An n-bit registerreg mema [1:n]; // A memory of n 1-bit registers

Ver1.0 (2008)48한국기술교육대학교 정보기술공학부

Page 49: 1 1. VilVerilog HDL 개요Verilog HDL의역사 Verilog HDL 1983년GatewayDesignAutomationGateway Design Automation사에서하드웨어기술언어인 HiLo와C 언어의특징을기반으로개발

2.1.6 parameter parameter

variable 또는 net 범주에속하지않는상수값 회로의비트크기또는지연값을지정하기위해사용

defparam문또는모듈인스턴스문의 parameter overriding에의해값을변경시킬수있음변경시킬수있음

자료형과범위지정을가질수있음

범위가지정되지않은경우, 상수값에적합한크기의비트폭을 default로가짐

parameter msb = 7; // defines msb as a constant value 7parameter msb = 7; // defines msb as a constant value 7parameter e = 25, f = 9; // defines two constant numbersparameter r = 5.7; // declares r as a real parameterparameter byte_size = 8, byte_mask = byte_size - 1;parameter average delay =(r + f) / 2;parameter average_delay =(r + f) / 2;parameter signed [3:0] mux_selector = 0;parameter real r1 = 3.5e17;parameter p1 = 13'h7e;parameter [31:0] dec const = 1'b1; // value converted to 32 bits

Ver1.0 (2008)49

parameter [31:0] dec_const = 1 b1; // value converted to 32 bitsparameter newconst = 3'h4; // implied range of [2:0]

한국기술교육대학교 정보기술공학부

Page 50: 1 1. VilVerilog HDL 개요Verilog HDL의역사 Verilog HDL 1983년GatewayDesignAutomationGateway Design Automation사에서하드웨어기술언어인 HiLo와C 언어의특징을기반으로개발

2.1.6 parametermodule modXnor (y_out, a, b);parameter size=8, delay=15;output [size-1:0] y out;

모듈인스턴스의 parameter overriding

output [size 1:0] y_out;input [size-1:0] a, b;wire [size-1:0] #delay y_out= a ~^ b; // bit-wise XNOR

endmodule

module Param;wire [7:0] y1_out;wire [3:0] y2_out;reg [7:0] b1, c1;reg [7:0] b1, c1;reg [3:0] b2, c2;modXnor G1 (y1_out, b1, c1); // use default parametersmodXnor #(4, 5) G2 (y2_out, b2, c2); // overrides default parameters

endmoduleendmodule

// Primitive instantiation with 3 units of delay

nand #3 G1 (out nd2, in0, in1); primitive gate의 delay

( _ , , )

Ver1.0 (2008)50한국기술교육대학교 정보기술공학부

Page 51: 1 1. VilVerilog HDL 개요Verilog HDL의역사 Verilog HDL 1983년GatewayDesignAutomationGateway Design Automation사에서하드웨어기술언어인 HiLo와C 언어의특징을기반으로개발

2.2 Verilog의연산자

연산자 기능 연산자 기능

표 2.8 Verilog HDL의연산자

{}, {{}} 결합, 반복 ^ 비트단위 exclusive or

+, -, *, /, ** 산술 ^~ 또는 ~^ 비트단위 xnor% 나머지 & 축약 and% 나머지 & 축약 and

>, >=, <, <= 관계 ~& 축약 nand! 논리부정 | 축약 or&& 논리 and ~| 축약 nor|| 논리 or ^ 축약 xor== 논리등가 ^~ 또는 ~^ 축약 xnor!= 논리부등 << 논리왼쪽시프트

=== case 등가 >> 논리오른쪽시프트

!== case부등 <<< 산술왼쪽시프트!== case 부등 <<< 산술왼쪽시프트

~ 비트단위부정 >>> 산술오른쪽시프트

& 비트단위 and ? : 조건

Ver1.0 (2008)51

| 비트단위 inclusive or or Event or

한국기술교육대학교 정보기술공학부

Page 52: 1 1. VilVerilog HDL 개요Verilog HDL의역사 Verilog HDL 1983년GatewayDesignAutomationGateway Design Automation사에서하드웨어기술언어인 HiLo와C 언어의특징을기반으로개발

2.2 Verilog의연산자

연산자 기능 연산자 기능

표 2.9 실수형수식에사용될수있는연산자

연산자 기능 연산자 기능

+, -, *, /, ** 산술 || 논리 or

+ 부호 == 논리등가+, - 부호 == 논리등가

>, >=, <, <= 관계 != 논리부등

! 논리부정 ? : 조건! 논리부정 ? : 조건

&& 논리 and or Event or

Ver1.0 (2008)52한국기술교육대학교 정보기술공학부

Page 53: 1 1. VilVerilog HDL 개요Verilog HDL의역사 Verilog HDL 1983년GatewayDesignAutomationGateway Design Automation사에서하드웨어기술언어인 HiLo와C 언어의특징을기반으로개발

2.2 Verilog의연산자표 2.10 Verilog 연산자의우선순위

+, -, !, ~ (단항) Highest precedence**

*, /, %, /, %

+, -(이항)<<, >>, <<<, >>>

<, <=, >, >=

==, !=, ===, !==

&, ~&,

^, ^~, ~^

|, ~|

&&

||

? : (conditional operator) Lowest precedence

Ver1.0 (2008)53

p

한국기술교육대학교 정보기술공학부

Page 54: 1 1. VilVerilog HDL 개요Verilog HDL의역사 Verilog HDL 1983년GatewayDesignAutomationGateway Design Automation사에서하드웨어기술언어인 HiLo와C 언어의특징을기반으로개발

2.2 Verilog의연산자

integer IntA, IntB, IntC, IntD;IntA = -12 / 4; // The result is -3.IntB = -'d12 / 4; // The result is 1073741821.IntC = -'sd12 / 4; // The result is -3.IntD = -4'sd12 / 4; // -4'sd12 is the negative of the 4-bit 1100,

// which is -4. -(-4) = 4. The result is 1.

Ver1.0 (2008)54한국기술교육대학교 정보기술공학부

Page 55: 1 1. VilVerilog HDL 개요Verilog HDL의역사 Verilog HDL 1983년GatewayDesignAutomationGateway Design Automation사에서하드웨어기술언어인 HiLo와C 언어의특징을기반으로개발

2.2.1산술연산자 피연산자의비트에 x (unknown)나 z (high-impedance)가포함된경우에는전체결과값은 x가됨

나누기와나머지연산자에서두번째피연산자가 0인경우, 결과값은 x가됨 나머지연산자의결과값은첫번째피연산자의부호를따름

거듭제곱연산자에서다음의경우에는결과값이정의되지않음 거듭제곱연산자에서다음의경우에는결과값이정의되지않음

첫번째피연산자가 0이고두번째피연산자가양수가아닌경우 첫번째피연산자가음수이고두번째피연산자가정수값이아닌경우 첫번째피연산자가음수이고두번째피연산자가정수값이아닌경우

기 호 기 능

+ 더하기

표 2.11 산술연산자+ 더하기

- 빼기

* 곱하기

/ 나누기(몫)

% 나머지(modulo)

** 거듭제곱( )

Ver1.0 (2008)55

** 거듭제곱(power)

한국기술교육대학교 정보기술공학부

Page 56: 1 1. VilVerilog HDL 개요Verilog HDL의역사 Verilog HDL 1983년GatewayDesignAutomationGateway Design Automation사에서하드웨어기술언어인 HiLo와C 언어의특징을기반으로개발

2.2.1산술연산자

수 식 결과값 설 명

표 2.12 나머지연산자의연산결과

수 식 결과값 설 명

10 % 3 1 10을 3으로나눈나머지는 1

11 % 3 2 11을 3으로나눈나머지는 211 % 3 2 11을 3으로나눈나머지는 2

12 % 3 0 12를 3으로나눈나머지는 0

10 % 3 1 결과값은첫번째피연산자의부호를따름-10 % 3 -1 결과값은첫번째피연산자의부호를따름

11 % -3 2 결과값은첫번째피연산자의부호를따름

Ver1.0 (2008)56한국기술교육대학교 정보기술공학부

Page 57: 1 1. VilVerilog HDL 개요Verilog HDL의역사 Verilog HDL 1983년GatewayDesignAutomationGateway Design Automation사에서하드웨어기술언어인 HiLo와C 언어의특징을기반으로개발

2.2.1산술연산자

표 2.13 산술연산자에서의자료형해석

자료형 해석자료형 해석

unsigned net Unsigned

signed net Signed, 2’s complementg g

unsigned reg Unsigned

signed reg Signed, 2’s complement

integer Signed, 2’s complement

time Unsigned

l lti Si d fl ti i treal, realtime Signed, floating-point

Ver1.0 (2008)57한국기술교육대학교 정보기술공학부

Page 58: 1 1. VilVerilog HDL 개요Verilog HDL의역사 Verilog HDL 1983년GatewayDesignAutomationGateway Design Automation사에서하드웨어기술언어인 HiLo와C 언어의특징을기반으로개발

2.2.1산술연산자

integer intA;reg [15:0] regA;reg signed [15:0] regS;g g [ ] g ;

intA = -4'd12;regA = intA / 3; // 결과 값은 -4

// intA는 integer 자료형이고, regA는 65532regA = -4'd12; // regA는 65524intA = regA / 3; // 결과 값은 21841

결과 값은intA = -4'd12 / 3; // 결과 값은 1431655761// -4d'12는 32-bit reg 자료형

regA = -12 / 3; // 결과 값은 -4, -12는 integer 자료형// A는 65532// regA는 65532

regS = -12 / 3; // 결과 값은 -4. regS는 signed regregS = -4'sd12 / 3; // 결과 값은 1. -4'sd12는 실제로 4이므로

// 정수 나눗셈 규칙에 의해 4/3=1이 된다

Ver1.0 (2008)58

// 정수 나눗셈 규칙에 의해 4/3=1이 된다.

한국기술교육대학교 정보기술공학부

Page 59: 1 1. VilVerilog HDL 개요Verilog HDL의역사 Verilog HDL 1983년GatewayDesignAutomationGateway Design Automation사에서하드웨어기술언어인 HiLo와C 언어의특징을기반으로개발

2.2.2관계연산자 산술연산자보다낮은우선순위를가짐

피연산자의비트에 x (unknown)나 z(high-impedance)가포함된경우에는 피연산자의비트에 x (unknown)나 z(high impedance)가포함된경우에는결과값은 1비트의 x가됨

두피연산자의비트수가다른경우에는, 비트수가작은피연산자의MSB 쪽에 0이채워져비트수가큰피연산자에맞추어진후, 관계를판단함

피연산자중하나가실수형이면다른피연산자가실수형으로변환된후, 비교됨비교됨

관계연산자식 의 미

표 2.14 관계연산자

관계연산자식 의 미

a < b a가 b보다작다

> b 가 b보다크다a > b a가 b보다크다

a <= b a가 b보다작거나같다

a > b 가 b보다크거나같다

Ver1.0 (2008)59

a >= b a가 b보다크거나같다

한국기술교육대학교 정보기술공학부

Page 60: 1 1. VilVerilog HDL 개요Verilog HDL의역사 Verilog HDL 1983년GatewayDesignAutomationGateway Design Automation사에서하드웨어기술언어인 HiLo와C 언어의특징을기반으로개발

2.2.2관계연산자

// A = 9, B = 4// D = 4'b1001, E = 4'b1100, F = 4'b1xxx

A <= B // 결과 값은 거짓(0)A > B // 결과 값은 참(1)E >= D // 결과 값은 참(1)E >= D // 결과 값은 참(1)E < F // 결과 값은 x

ⓛ a < b-1 // ⓛ과 ②는 결과가 동일

② a <(b-1)② a <(b-1)③ b-(1 < a) // ③과 ④는 결과가 다를 수 있음

④ b-1 < a

Ver1.0 (2008)60한국기술교육대학교 정보기술공학부

Page 61: 1 1. VilVerilog HDL 개요Verilog HDL의역사 Verilog HDL 1983년GatewayDesignAutomationGateway Design Automation사에서하드웨어기술언어인 HiLo와C 언어의특징을기반으로개발

2.2.3등가연산자 관계연산자보다낮은우선순위를가짐

피연산자의비트끼리비교

두피연산자의비트수가다른경우에는, 비트수가작은피연산자의MSB 쪽에 0이채워져비트수가큰피연산자에맞추어진후, 등가를판단함

lit 와 i lit 연산자( ! )는대부분의 EDA case equality와 case inequality 연산자(===, !==)는대부분의 EDA 툴에서논리합성이지원되지않으므로, 합성을위한 RTL 수준의모델링에는사용하지않는것이좋음사용하지않는것이좋음

관계연산자식 의 미

표 2.15 등가연산자

관계연산자식 의 미

a === b a와 b는같다. (x와 z가포함된일치를판단)

! b 와 b는같지않다 ( 와 가포함된불일치를판단)a !== b a와 b는같지않다. (x와 z가포함된불일치를판단)

a == b a와 b는같다. (결과가 x가될수있음)

a ! b 와 b는같지않다 (결과가 가될수있음)

Ver1.0 (2008)61

a != b a와 b는같지않다. (결과가 x가될수있음)

한국기술교육대학교 정보기술공학부

Page 62: 1 1. VilVerilog HDL 개요Verilog HDL의역사 Verilog HDL 1983년GatewayDesignAutomationGateway Design Automation사에서하드웨어기술언어인 HiLo와C 언어의특징을기반으로개발

2.2.3등가연산자

// A = 9 B = 4// A = 9, B = 4// D = 4'b1001, E = 4'b1100// F = 4'b1xxz, G = 4'b1xxz, H = 4'b1xxx

A === B // 결과 값은 거짓(0)D != E // 결과 값은 참(1)D == F // 결과 값은 xF === G // 결과 값은 참(1)F === H // 결과 값은 거짓(0)G !== H // 결과 값은 참(1)

Ver1.0 (2008)62한국기술교육대학교 정보기술공학부

Page 63: 1 1. VilVerilog HDL 개요Verilog HDL의역사 Verilog HDL 1983년GatewayDesignAutomationGateway Design Automation사에서하드웨어기술언어인 HiLo와C 언어의특징을기반으로개발

2.2.4논리연산자참또는거짓의판단이모호한경우에는결과값은 x

논리연산자식 의 미

a && b a와 b의논리 AND

a || b a와 b의논리 OR

!a a의부정 (NOT a)

// A = 3, B = 0, C = 2'b0x, D = 2'b10인 경우에,A && B // 결과 값은 0A || B // 결과 값은 1A || B // 결과 값은 1!A // 결과 값은 0!B // 결과 값은 1C && D // 결과 값은 x

Ver1.0 (2008)63

C && D // 결과 값은 x

한국기술교육대학교 정보기술공학부

Page 64: 1 1. VilVerilog HDL 개요Verilog HDL의역사 Verilog HDL 1983년GatewayDesignAutomationGateway Design Automation사에서하드웨어기술언어인 HiLo와C 언어의특징을기반으로개발

2.2.4논리연산자

// alpha = 237, beta=0인 경우에,

regA = alpha && beta; // regA에는 0이 할당된다.regB = alpha || beta; // regB에는 1이 할당된다.

a < size-1 && b != c && index != last_one(a < size-1) && (b != c) && (index != last_one) // recommended

if(!reset)

Ver1.0 (2008)64한국기술교육대학교 정보기술공학부

Page 65: 1 1. VilVerilog HDL 개요Verilog HDL의역사 Verilog HDL 1983년GatewayDesignAutomationGateway Design Automation사에서하드웨어기술언어인 HiLo와C 언어의특징을기반으로개발

2.2.5비트연산자피연산자의해당비트들에대한연산을수행

피연산자의비트수가같지않으면 비트수가작은피연산자의MSB피연산자의비트수가같지않으면, 비트수가작은피연산자의MSB 위치에 0이채워진후, 연산됨

표 2.16 비트 and 연산자 표 2.17 비트 or 연산자

& 0 1 x z

0 0 0 0 0

| 0 1 x z

0 0 1 x x

1 0 1 x x

x 0 x x x

1 1 1 1 1

x x 1 x x

z 0 x x x z x 1 x x

Ver1.0 (2008)65한국기술교육대학교 정보기술공학부

Page 66: 1 1. VilVerilog HDL 개요Verilog HDL의역사 Verilog HDL 1983년GatewayDesignAutomationGateway Design Automation사에서하드웨어기술언어인 HiLo와C 언어의특징을기반으로개발

2.2.5비트연산자

^ 0 1

표 2.18 비트 xnor 연산자

^ 0 1

표 2.19 비트 xor 연산자

~^ 0 1 x z

0 1 0 x x

1 0 1 x x

^ 0 1 x z

0 0 1 x x

1 1 0 x x

x x x x x

z x x x x

x x x x x

z x x x x

표 2.20 비트부정연산자

// D 4'b1001 E 4'b1101 F 4'b10 1~ 0

0 1

1 0

// D = 4'b1001, E = 4'b1101, F = 4'b10x1

~D // 결과 값은 4'b0110D & E // 결과 값은 4'b10011 0

x x

z x

// 과 값D | E // 결과 값은 4'b1101D ^ E // 결과 값은 4'b0100D ~^ E // 결과 값은 4'b1011D & F // 결과 값은 4'b10 1

Ver1.0 (2008)66

D & F // 결과 값은 4'b10x1

한국기술교육대학교 정보기술공학부

Page 67: 1 1. VilVerilog HDL 개요Verilog HDL의역사 Verilog HDL 1983년GatewayDesignAutomationGateway Design Automation사에서하드웨어기술언어인 HiLo와C 언어의특징을기반으로개발

2.2.6축약(reduction)연산자단항연산자

피연산자의단위비트들에적용되어단일비트의결과값을생성피연산자의단위비트들에적용되어단일비트의결과값을생성

reg[7:0] cnt;assign parity = ^cnt;assign parity = cnt[7]^cnt[6]^cnt[5]^cnt[4]^cnt[3]^cnt[2]^cnt[1]^cnt[0];

& 0 1 x z

표 2.21 축약 and 연산자

~& 0 1 x z

축약 nand 연산자

& 0 1 x z

0 0 0 0 0

1 0 1 x x

~& 0 1 x z

0 1 1 1 1

1 1 0 x x

x 0 x x x

z 0 x x x

x 1 x x x

z 1 x x x

Ver1.0 (2008)67한국기술교육대학교 정보기술공학부

Page 68: 1 1. VilVerilog HDL 개요Verilog HDL의역사 Verilog HDL 1983년GatewayDesignAutomationGateway Design Automation사에서하드웨어기술언어인 HiLo와C 언어의특징을기반으로개발

2.2.6축약연산자표 2.22 축약 or 연산자 축약 nor 연산자

| 0 1 x z

0 0 1 x x

1 1 1 1 1

~| 0 1 x z

0 1 0 x x

1 0 0 0 01 1 1 1 1

x x 1 x x

z x 1 x x

1 0 0 0 0

x x 0 x x

z x 0 x x

표 2.23 축약 xor 연산자 축약 xnor 연산자

^ 0 1 x z

0 0 1 x x

~^ 0 1 x z

0 1 0 x x

1 1 0 x x

x x x x x

z x x x x

1 0 1 x x

x x x x x

z x x x x

Ver1.0 (2008)68

z x x x x z x x x x

한국기술교육대학교 정보기술공학부

Page 69: 1 1. VilVerilog HDL 개요Verilog HDL의역사 Verilog HDL 1983년GatewayDesignAutomationGateway Design Automation사에서하드웨어기술언어인 HiLo와C 언어의특징을기반으로개발

2.2.6축약연산자

연산자 연산결과연산자

피연산자

연산결과설 명

& ~& | ~| ^ ~^

4'b0000 0 1 0 1 0 1 모든비트가 0인경우4 b0000 0 1 0 1 0 1 모든비트가 0인경우

4'b1111 1 0 1 0 0 1 모든비트가 1인경우

4'b0110 0 1 1 0 0 1 1의개수가짝수인경우의개수가짝수 경우

4'b1000 0 1 1 0 1 0 1의개수가홀수인경우

Ver1.0 (2008)69한국기술교육대학교 정보기술공학부

Page 70: 1 1. VilVerilog HDL 개요Verilog HDL의역사 Verilog HDL 1983년GatewayDesignAutomationGateway Design Automation사에서하드웨어기술언어인 HiLo와C 언어의특징을기반으로개발

2.2.7시프트연산자 논리시프트연산자 ( <<, >> )

<< :우측피연산자값만큼좌측으로시프트후,비어있는비트에 0을채움 : 우측피연산자값만큼좌측으로시프트후, 비어있는비트에 0을채움 >> : 우측피연산자값만큼우측으로시프트후, 비어있는비트에 0을채움

산술시프트연산자 ( >>>, <<< ) <<< : 우측피연산자값만큼좌측으로시프트후, 비어있는비트에 0을채움 >>> : 우측피연산자값만큼우측으로시프트후, 비어있는비트에좌측피연산자의MSB를채움피연산자의MSB를채움

우측피연산자

x 또는 z가포함된경우, 시프트연산의결과값은 x 항상 unsigned 수

Ver1.0 (2008)70한국기술교육대학교 정보기술공학부

Page 71: 1 1. VilVerilog HDL 개요Verilog HDL의역사 Verilog HDL 1983년GatewayDesignAutomationGateway Design Automation사에서하드웨어기술언어인 HiLo와C 언어의특징을기반으로개발

2.2.7시프트연산자

// A = 4'b1100B = A >> 1 // 오른쪽으로 1비트 시프트, 결과 값은 B=4'b0110C = A << 1 // 왼쪽으로 1비트 시프트, 결과 값은 B=4'b1000// 왼쪽 비 시 , 결과 값

D = A << 2 // 왼쪽으로 2비트 시프트, 결과 값은 B=4'b0000

module shift;reg [3:0] start result;

논리시프트연산

reg [3:0] start, result;

initial beginstart = 1;start 1;result =(start << 2); // 결과 값은 0100

endendmodule

Ver1.0 (2008)71한국기술교육대학교 정보기술공학부

Page 72: 1 1. VilVerilog HDL 개요Verilog HDL의역사 Verilog HDL 1983년GatewayDesignAutomationGateway Design Automation사에서하드웨어기술언어인 HiLo와C 언어의특징을기반으로개발

2.2.7시프트연산자

module ashift;i d [3 0] t t lt

산술시프트연산

reg signed [3:0] start, result;initial begin

start = 4'b1000;result =(start >>> 2); // 결과 값은 1110result =(start >>> 2); // 결과 값은 1110

endendmodule

Ver1.0 (2008)72한국기술교육대학교 정보기술공학부

Page 73: 1 1. VilVerilog HDL 개요Verilog HDL의역사 Verilog HDL 1983년GatewayDesignAutomationGateway Design Automation사에서하드웨어기술언어인 HiLo와C 언어의특징을기반으로개발

2.2.8조건연산자조건연산자

i 1이참(1 즉 0 또는 가아닌값)으로평가되면 expression1이참(1, 즉 0, x 또는 z가아닌값)으로평가되면expression2의값이좌변의변수에할당

expression1이거짓(0)으로평가되면 expression3의값이좌변의 expression1이거짓(0)으로평가되면 expression3의값이좌변의변수에결과값으로할당

expression1이 x또는 z이면(즉,참또는거짓을판단할수없는 expression1이 x 또는 z이면(즉, 참또는거짓을판단할수없는모호성이존재하는경우), expression2와 expression3을함께평가하여비트단위로비교된값이좌변의변수에할당

expression3이 real 형값이아니면결과값은비트단위로비교되어결정되며, real 형값인경우에는결과값은 0이됨

conditional_expression ::= expression1 ? expression2 : expression3

Ver1.0 (2008)73한국기술교육대학교 정보기술공학부

Page 74: 1 1. VilVerilog HDL 개요Verilog HDL의역사 Verilog HDL 1983년GatewayDesignAutomationGateway Design Automation사에서하드웨어기술언어인 HiLo와C 언어의특징을기반으로개발

2.2.8조건연산자

표 2.24 조건에애매성이존재하는경우의조건연산자의결과값결정

? : 0 1 x z0 0 x x x

표 2.24 조건에애매성이존재하는경우의조건연산자의결과값결정

1 x 1 x xx x x x xz x x x x

wire [15:0] busa = drive busa ? data : 16'bz;

조건연산자를이용한 3상태버퍼

_

Ver1.0 (2008)74한국기술교육대학교 정보기술공학부

Page 75: 1 1. VilVerilog HDL 개요Verilog HDL의역사 Verilog HDL 1983년GatewayDesignAutomationGateway Design Automation사에서하드웨어기술언어인 HiLo와C 언어의특징을기반으로개발

2.2.9결합및반복연산자결합연산자

중괄호 { }에의해묶인두개이상의표현이갖는비트들을결합중괄호 { }에의해묶인두개이상의표현이갖는비트들을결합 결합되는피연산자들은각각의크기를결정할수있어야결합이가능

unsized상수는결합연산자로결합시킬수없음 unsized 상수는결합연산자로결합시킬수없음

{a b[3:0] w 3'b101}{a, b[3:0], w, 3'b101}

//결합 연산자의 결과

{a, b[3], b[2], b[1], b[0], w, 1'b1, 1'b0, 1'b1}

Ver1.0 (2008)75한국기술교육대학교 정보기술공학부

Page 76: 1 1. VilVerilog HDL 개요Verilog HDL의역사 Verilog HDL 1983년GatewayDesignAutomationGateway Design Automation사에서하드웨어기술언어인 HiLo와C 언어의특징을기반으로개발

2.2.9결합및반복연산자결합연산자

대입문의좌측또는우측에사용가능

비트폭이일치하지않는변수의연산이나대입이허용됨

우변의비트폭이작은경우, 우변의MSB에 0을붙여연산됨 좌변의비트폭이우변보다작을경우, MSB는누락되어저장

wire [15:0] addr_bus;assign addr_bus = {addr_hi, addr_lo}; // addr hi, addr lo는 8 비트 신호// addr_hi, addr_lo는 8 비트 신호

wire [3:0] a, b, sum;wire carry;yassign {carry, sum} = a + b; // 4비트 데이터의 덧셈은 5비트 결과

// 좌변이 5 비트이므로, 우변의 a+b는 MSB에 0을 붙인 5비트로 연산 됨

Ver1.0 (2008)76한국기술교육대학교 정보기술공학부

Page 77: 1 1. VilVerilog HDL 개요Verilog HDL의역사 Verilog HDL 1983년GatewayDesignAutomationGateway Design Automation사에서하드웨어기술언어인 HiLo와C 언어의특징을기반으로개발

2.2.9결합및반복연산자반복연산자

{ {b}}의형태로표현하여 b를 회반복 {a{b}}의형태로표현하여 b를 a회반복 반복횟수 a는 0, x, z가아닌상수이어야함

{4{w}} // {w, w, w, w}와 동일한 표현.

a[31:0] = {1'b1, {0{1'b0}} }; // 우변이 {1'b1}가 되므로 잘못된 표현임.

a[31:0] = {1'b1, {1'bz{1'b0}} }; // 우변이 {1'b1}가 되므로 잘못된 표현임.

a[31:0] = {1'b1, {1'bx{1'b0}} }; // 우변이 {1'b1}가 되므로 잘못된 표현임.

result = {func(w), func(w), func(w), func(w)};result = {4{func(w)}}; // 위의 문장과 동일함.{b, {3{a, b}}} // {b, a, b, a, b, a, b}와 동일함.

Ver1.0 (2008)77

{ , { { , }}} { , , , , , , }

한국기술교육대학교 정보기술공학부

Page 78: 1 1. VilVerilog HDL 개요Verilog HDL의역사 Verilog HDL 1983년GatewayDesignAutomationGateway Design Automation사에서하드웨어기술언어인 HiLo와C 언어의특징을기반으로개발

Verilog HDL을이용한디지털시스템설계및실습

3 게이트 수준 모델링3. 게이트 수준 모델링

Ver1.0 (2008)78한국기술교육대학교 정보기술공학부

Page 79: 1 1. VilVerilog HDL 개요Verilog HDL의역사 Verilog HDL 1983년GatewayDesignAutomationGateway Design Automation사에서하드웨어기술언어인 HiLo와C 언어의특징을기반으로개발

게이트및스위치프리미티브

predefined primitives

정의나선언없이사용가능 정의나선언없이사용가능

단일출력을가짐

모듈내에서만사용가능

initial과 always 구문내부에서는사용불가

표 3.1 Verilog에서제공되는게이트및스위치프리미티브

n-input gates

n-output gates

three-state gates pull gates MOS

switchesbidirectional

switches

and buf bufif0 pulldown cmos rtranand buf bufif0 pulldown cmos rtran

nand not bufif1 pullup nmos rtranif0

nor notif0 pmos rtranif1

or notif1 rcoms tran

xnor rnmos tranif0

Ver1.0 (2008)79

xor rpmos tranif1

한국기술교육대학교 정보기술공학부

Page 80: 1 1. VilVerilog HDL 개요Verilog HDL의역사 Verilog HDL 1983년GatewayDesignAutomationGateway Design Automation사에서하드웨어기술언어인 HiLo와C 언어의특징을기반으로개발

3.1게이트프리미티브 gate primitives

인스턴스구문인스턴스구문

primitive_gate_name [#(n1,n2)][instance_name](output, input1, ..);

#(n1,n2) : 게이트프리미티브의지연. default 지연값은 0 n1 :상승지연 n2 :하강지연 n1 : 상승지연, n2 : 하강지연 min(n1, n2) : 출력이 x (unknown)로변할때의지연

instance name :생략가능 instance_name : 생략가능포트연결 :

순서에의한매핑만사용가능 (이름에의한포트매핑불가능) 순서에의한매핑만사용가능 (이름에의한포트매핑불가능) 출력포트가처음에오며, 입력신호들은임의의순서로나열

Ver1.0 (2008)80한국기술교육대학교 정보기술공학부

Page 81: 1 1. VilVerilog HDL 개요Verilog HDL의역사 Verilog HDL 1983년GatewayDesignAutomationGateway Design Automation사에서하드웨어기술언어인 HiLo와C 언어의특징을기반으로개발

3.1게이트프리미티브and 게이트 or 게이트

and 0 1 x z

0 0 0 0 0

1 0 1 x x

or 0 1 x z

0 0 1 x x

1 1 1 1 11 0 1 x x

x 0 x x x

z 0 x x x

1 1 1 1 1

x x 1 x x

z x 1 x x

nand 게이트 nor 게이트

nand 0 1 x z0 1 1 1 1

1 1 0 x x

nor 0 1 x z0 1 0 x x

1 0 0 0 01 1 0 x x

x 1 x x x

z 1 x x x

1 0 0 0 0

x x 0 x x

z x 0 x x

Ver1.0 (2008)81한국기술교육대학교 정보기술공학부

Page 82: 1 1. VilVerilog HDL 개요Verilog HDL의역사 Verilog HDL 1983년GatewayDesignAutomationGateway Design Automation사에서하드웨어기술언어인 HiLo와C 언어의특징을기반으로개발

3.1게이트프리미티브

xor 게이트 xnor 게이트

xor 0 1 x z xnor 0 1 x z

0 0 1 x x

1 1 0 x x

0 1 0 x x

1 0 1 x x

x x x x x

z x x x x

x x x x x

z x x x x

Ver1.0 (2008)82한국기술교육대학교 정보기술공학부

Page 83: 1 1. VilVerilog HDL 개요Verilog HDL의역사 Verilog HDL 1983년GatewayDesignAutomationGateway Design Automation사에서하드웨어기술언어인 HiLo와C 언어의특징을기반으로개발

3.1게이트프리미티브

and U1(out1, a, b); // 2입력 and 게이트nand (out2, a, b); // 인스턴스 이름을 생략한 경우

or U3(out3, a, b, c); // 3입력 or 게이트nor #(2) U4(out4, a, b); // 2입력 nor 게이트xor #(3, 4) U5(out5, c, b, a); // 3입력 xor 게이트xnor U6(out6, a, b); // 2입력 xnor 게이트// multiple instantiations

Ver1.0 (2008)83한국기술교육대학교 정보기술공학부

Page 84: 1 1. VilVerilog HDL 개요Verilog HDL의역사 Verilog HDL 1983년GatewayDesignAutomationGateway Design Automation사에서하드웨어기술언어인 HiLo와C 언어의특징을기반으로개발

3.1게이트프리미티브

module full_adder_g(a, b, cin, sum, cout);input a, b, cin;output sum, cout;wire s1, c1, c2;

xor (s1, a, b);and (c1, a, b);and (c1, a, b);and G3 (c2, s1, cin);xor G4 (sum, s1, cin);xor G5 (cout, c1, c2);d d l

a s1endmodule b

c2

sum

cin

c1

cout

Ver1.0 (2008)84한국기술교육대학교 정보기술공학부

Page 85: 1 1. VilVerilog HDL 개요Verilog HDL의역사 Verilog HDL 1983년GatewayDesignAutomationGateway Design Automation사에서하드웨어기술언어인 HiLo와C 언어의특징을기반으로개발

3.2 buf와 not 게이트프리미티브buf 게이트 not 게이트

input output input output

bufinput output

notinput output

0 01 1x x

0 11 0x xx x

z xx xz x

buf b1(out1, out2, in);not #5 inv(out, in);

Ver1.0 (2008)85한국기술교육대학교 정보기술공학부

Page 86: 1 1. VilVerilog HDL 개요Verilog HDL의역사 Verilog HDL 1983년GatewayDesignAutomationGateway Design Automation사에서하드웨어기술언어인 HiLo와C 언어의특징을기반으로개발

3.3 3상태버퍼프리미티브 3상태버퍼프리미티브

포트연결포트연결 : 순서에의한매핑만사용가능

출력포트 데이터입력포트 제어입력포트의순서로매핑 출력포트,데이터입력포트, 제어입력포트의순서로매핑

3개의지연값지정 : #(n1, n2, n3) n1 :상승지연, n2 :하강지연, n3 : z로변할때의지연 n1 : 상승지연, n2 : 하강지연, n3 : z로변할때의지연 min(n1, n2, n3) : 출력이 x로변할때의지연

2개의지연값지정 : #(n1, n2)( , ) n1 : 상승지연, n2 : 하강지연 min(n1, n2) : 출력이 x 또는 z로변할때의지연

bufif0 bf0(out0, in, control);bufif1 #(10,12,11) bf1(out1, in, control);

Ver1.0 (2008)86한국기술교육대학교 정보기술공학부

Page 87: 1 1. VilVerilog HDL 개요Verilog HDL의역사 Verilog HDL 1983년GatewayDesignAutomationGateway Design Automation사에서하드웨어기술언어인 HiLo와C 언어의특징을기반으로개발

3.3 3상태버퍼프리미티브

bufif1 게이트 bufif0 게이트

data out data out

control control

bufif0CONTROL

0 1 x zbufif1

CONTROL0 1 x z

DAT

0 0 z L L1 1 z H Hx x z x x

DAT

0 z 0 L L1 z 1 H Hx z x x x

Ax x z x xz x z x xA

x z x x xz z x x x

L : 0또는 z가될수있는 unknown H : 1또는 z가될수있는 unknown

Ver1.0 (2008)87

L : 0 또는 z가될수있는 unknown H : 1 또는 z가될수있는 unknown

한국기술교육대학교 정보기술공학부

Page 88: 1 1. VilVerilog HDL 개요Verilog HDL의역사 Verilog HDL 1983년GatewayDesignAutomationGateway Design Automation사에서하드웨어기술언어인 HiLo와C 언어의특징을기반으로개발

3.3 3상태버퍼프리미티브

notif1 게이트 notif0 게이트

data outdata out

controlcontrol

notif0CONTROL

0 1 x znotif1

CONTROL0 1 x z 0 1 x z

DAT

0 1 z H H1 0 z L L

0 1 x z

DAT

0 z 1 H H1 z 0 L L

TA

x x z x xz x z x x

TA

x z x x xz z x x x

Ver1.0 (2008)88한국기술교육대학교 정보기술공학부

Page 89: 1 1. VilVerilog HDL 개요Verilog HDL의역사 Verilog HDL 1983년GatewayDesignAutomationGateway Design Automation사에서하드웨어기술언어인 HiLo와C 언어의특징을기반으로개발

3.4논리게이트인스턴스의배열게이트인스턴스의배열

인스턴스이름뒤에배열의범위를지정하여반복회수를표현인스턴스이름뒤에배열의범위를지정하여반복회수를표현

nand #2 t_nand[0:3]( ... ), t_nand[4:7]( ... ); // syntax error

nand #2 t_nand[0:7]( ... );#nand #2 x_nand[0:3]( ... ), y_nand[4:7]( ... );

Ver1.0 (2008)89한국기술교육대학교 정보기술공학부

Page 90: 1 1. VilVerilog HDL 개요Verilog HDL의역사 Verilog HDL 1983년GatewayDesignAutomationGateway Design Automation사에서하드웨어기술언어인 HiLo와C 언어의특징을기반으로개발

3.4논리게이트인스턴스의배열

module driver(in, out, en);input [3:0] in;input en;t t [3 0] toutput [3:0] out;

bufif0 ar[3:0](out, in, en); // 3상태 버퍼의 배열endmodule 코드 3.2

module driver_eq(in, out, en); // 코드 3.2와 등가input [3:0] in;input en;input en;output [3:0] out;

bufif0 ar3(out[3], in[3], en); // 3상태 버퍼의 개별적인 인스턴스bufif0 ar2(out[2], in[2], en);bufif0 ar1(out[1], in[1], en);bufif0 ar0(out[0], in[0], en);

endmodule 코드 3 3

Ver1.0 (2008)90

endmodule 코드 3.3

한국기술교육대학교 정보기술공학부

Page 91: 1 1. VilVerilog HDL 개요Verilog HDL의역사 Verilog HDL 1983년GatewayDesignAutomationGateway Design Automation사에서하드웨어기술언어인 HiLo와C 언어의특징을기반으로개발

3.5게이트지연과 net 지연 게이트지연

게이트의입력에서부터출력까지의신호전달지연 ( ti d l ) 게이트의입력에서부터출력까지의신호전달지연 (propagation delay) 상승지연, 하강지연, 턴-오프 (turn-off) 지연 defualt 값은 0값

net 지연 net를구동하는 driver의값이변하는시점부터 net의값이갱신되는시점까지소요되는시간

상승지연, 하강지연, 턴-오프 (turn-off) 지연 defualt값은 0 defualt 값은 0

관성지연(inertial delay) 지정된지연값보다입력신호의변화폭이작은경우에는입력신호가

출력에영향을미치지않음

Verilog HDL의 default 지연

Ver1.0 (2008)91한국기술교육대학교 정보기술공학부

Page 92: 1 1. VilVerilog HDL 개요Verilog HDL의역사 Verilog HDL 1983년GatewayDesignAutomationGateway Design Automation사에서하드웨어기술언어인 HiLo와C 언어의특징을기반으로개발

3.5게이트지연과 net 지연

From value: To value: 2개의지연값(d1, d2)이사용된경우

3개의지연값(d1, d2, d3)이사용된경우

From value: To value:사용된경우 사용된경우

0 1 d1 d10 x min(d1, d2) min(d1, d2, d3)( ) ( )0 z min(d1, d2) d31 0 d2 d21 i (d1 d2) i (d1 d2 d3)1 x min(d1, d2) min(d1, d2, d3)1 z min(d1, d2) d3x 0 d2 d2x 1 d1 d1x z min(d1, d2) d3z 0 d2 d2z 0 d2 d2z 1 d1 d1z x min(d1, d2) min(d1, d2, d3)

Ver1.0 (2008)92한국기술교육대학교 정보기술공학부

Page 93: 1 1. VilVerilog HDL 개요Verilog HDL의역사 Verilog HDL 1983년GatewayDesignAutomationGateway Design Automation사에서하드웨어기술언어인 HiLo와C 언어의특징을기반으로개발

3.5게이트지연과 net 지연

and #(10) a1(out, in1, in2); // only one delayand #(10,12) a2(out, in1, in2); // rise and fall delaysbufif0 #(10,12,11) b3(out, in, ctrl); // rise, fall, turn-off delays

3상태출력을갖는래치

module tri_latch(qout, qbout, clock, data, enable);output qout, qbout;input clock, data, enable;tri qout qbout;tri qout, qbout;

not #5 n1(ndata, data);nand #(3,5) n2(wa, data, clock), n3(wb, ndata, clock);nand #(12,15) n4(q, qb, wa), n5(qb, q, wb);bufif1 #(3,7,13) q_drive(qout, q, enable),

qb_drive(qbout, qb, enable);endmodule 코드 3 4

Ver1.0 (2008)93

endmodule 코드 3.4

한국기술교육대학교 정보기술공학부

Page 94: 1 1. VilVerilog HDL 개요Verilog HDL의역사 Verilog HDL 1983년GatewayDesignAutomationGateway Design Automation사에서하드웨어기술언어인 HiLo와C 언어의특징을기반으로개발

3.5게이트지연과 net 지연

datandata

wb qbqbqbout

wa qclock

qout

clock

enable

그림 3.4 3상태출력을갖는래치림 상태출력을갖는래치

Ver1.0 (2008)94한국기술교육대학교 정보기술공학부

Page 95: 1 1. VilVerilog HDL 개요Verilog HDL의역사 Verilog HDL 1983년GatewayDesignAutomationGateway Design Automation사에서하드웨어기술언어인 HiLo와C 언어의특징을기반으로개발

3.5게이트지연과 net 지연module inertial_delay_gate();reg a, b; and #30(out, a, b);initial begin 게이트지연에서의관성지연initial begin

a = 1'b0; b = 1'b0;#50 a = 1'b1; b = 1'b1;#50 a = 1'b0; b = 1'b0;#50 1'b1 b 1'b1

게이트지연에서의관성지연

#50 a = 1'b1; b = 1'b1;#20 b = 1'b0;#50; end

endmodule

코드 3.5

Ver1.0 (2008)95한국기술교육대학교 정보기술공학부

Page 96: 1 1. VilVerilog HDL 개요Verilog HDL의역사 Verilog HDL 1983년GatewayDesignAutomationGateway Design Automation사에서하드웨어기술언어인 HiLo와C 언어의특징을기반으로개발

Verilog HDL을이용한디지털시스템설계및실습

4 할당문4. 할당문

Ver1.0 (2008)96한국기술교육대학교 정보기술공학부

Page 97: 1 1. VilVerilog HDL 개요Verilog HDL의역사 Verilog HDL 1983년GatewayDesignAutomationGateway Design Automation사에서하드웨어기술언어인 HiLo와C 언어의특징을기반으로개발

할당문

할당문

연속할당문 t형객체에값을할당연속할당문 : net형객체에값을할당 assign 문

continuous assign ::= assign [driving strength] [delay] net assignments;

절차형할당문 : variable형객체에값을할당

continuous_assign ::= assign [driving_strength] [delay] net_assignments;

절차형할당문 : variable형객체에값을할당 always 블록, initial 블록, task, function 내부의할당문 blocking 할당문 : 할당기호 =을사용 nonblocking 할당문 : 할당기호 <=을사용

절차형연속할당문 (Procedural Continuous Assignment; PCA) assign - deassign 문, force - release 문

Ver1.0 (2008)97한국기술교육대학교 정보기술공학부

Page 98: 1 1. VilVerilog HDL 개요Verilog HDL의역사 Verilog HDL 1983년GatewayDesignAutomationGateway Design Automation사에서하드웨어기술언어인 HiLo와C 언어의특징을기반으로개발

할당문

표 4 1 할당문좌변의형태

할당문형태 좌변 (Left-hand Side; LHS)

Net (vector or scalar)

표 4.1 할당문좌변의형태

연속할당

Net (vector or scalar)Constant bit select of a vector netConstant part select of a vector netConstant indexed part select of a vector netConstant indexed part select of a vector netConcatenation of any of the above four LHS

Variables (vector or scalar)

절차형할당

Bit-select of a vector reg, integer, or time variableConstant part select of a vector reg, integer, or time variableMemory wordIndexed part select of vector reg, integer, or time variableConcatenation of regs; bit or part selects of regs

Ver1.0 (2008)98한국기술교육대학교 정보기술공학부

Page 99: 1 1. VilVerilog HDL 개요Verilog HDL의역사 Verilog HDL 1983년GatewayDesignAutomationGateway Design Automation사에서하드웨어기술언어인 HiLo와C 언어의특징을기반으로개발

4.1연속할당문연속할당문

i 문을이용하여 t형객체에값을할당 assign 문을이용하여 net형객체에값을할당우변의값에변화(event)가발생했을때좌변의객체에값의할당이일어남일어남

단순한논리표현을이용한조합논리회로모델링에이용

함축적(i li it)연속할당문함축적(implicit) 연속할당문 net 선언문에연속할당문을포함시킨경우

wire mynet = enable & data;

wire mynet; 함축적연속할당문과등가

assign mynet = enable & data;

Ver1.0 (2008)99한국기술교육대학교 정보기술공학부

Page 100: 1 1. VilVerilog HDL 개요Verilog HDL의역사 Verilog HDL 1983년GatewayDesignAutomationGateway Design Automation사에서하드웨어기술언어인 HiLo와C 언어의특징을기반으로개발

4.1연속할당문

assign na = ~(in1 & in2); // 2 input NANDassign out = (sel==1) ? d1 : d0; // 2-to-1 MUXassign carry = (cnt10==4’h9); assign sum = a + b; // 덧셈 회로

연속할당문을이용한 4비트가산기

module adder (sum_out, carry_out, carry_in, ina, inb);output [3:0] sum_out;output carry out;output carry_out;input [3:0] ina, inb;input carry_in;

assign {carry_out, sum_out} = ina + inb + carry_in;endmodule 코드 4.1

Ver1.0 (2008)100한국기술교육대학교 정보기술공학부

Page 101: 1 1. VilVerilog HDL 개요Verilog HDL의역사 Verilog HDL 1983년GatewayDesignAutomationGateway Design Automation사에서하드웨어기술언어인 HiLo와C 언어의특징을기반으로개발

4.1연속할당문module select_bus (busout, bus0, bus1, bus2, bus3, enable, s);

parameter n = 16;parameter Zee = 16'bz;poutput [1:n] busout;input [1:n] bus0, bus1, bus2, bus3;input enable;input [1:2] s; 연속할당문을이용한ptri [1:n] data; // net declaration

// 연속 할당을 갖는 net 선언(함축적 연속 할당문)tri [1:n] busout = enable ? data : Zee;

16비트출력버스

// 4개의 assign 문을 이용한 표현assign data =(s == 0) ? bus0 : Zee;assign data =(s == 1) ? bus1 : Zee;assign data =(s == 2) ? bus2 : Zee;assign data =(s == 3) ? bus3 : Zee;

/* 하나의 assign 문으로 4개의 연속 할당을 표현(위의 4개의 assign 문과 등가임)g gassign data =(s == 0) ? bus0 : Zee,

data =(s == 1) ? bus1 : Zee,data =(s == 2) ? bus2 : Zee,data =(s == 3) ? bus3 : Zee; */

Ver1.0 (2008)101

endmodule 코드 4.2

한국기술교육대학교 정보기술공학부

Page 102: 1 1. VilVerilog HDL 개요Verilog HDL의역사 Verilog HDL 1983년GatewayDesignAutomationGateway Design Automation사에서하드웨어기술언어인 HiLo와C 언어의특징을기반으로개발

4.1.1할당지연과 net 지연연속할당문의지연값지정

i 뒤에지연연산자(#)를사용하여지정 assign 뒤에지연연산자(#)를사용하여지정우변피연산자값의변화에서부터그값이좌변에할당되기까지의

시간간격을지정시간간격을지정

assign #10 wireA = a & b;

t지연

wire #10 wireA = a & b; // 함축적 연속 할당문의 지연

net 지연 net 선언문에서지연값을지정

지정된 net 지연이경과한후에할당이이루어짐 해당 net를구동하는모든구동자 (게이트프리미티브, 연속할당문)

)등)에영향을미침i #10 i A

Ver1.0 (2008)102

)등)에영향을미침wire #10 wireA;

한국기술교육대학교 정보기술공학부

Page 103: 1 1. VilVerilog HDL 개요Verilog HDL의역사 Verilog HDL 1983년GatewayDesignAutomationGateway Design Automation사에서하드웨어기술언어인 HiLo와C 언어의특징을기반으로개발

4.1.1할당지연과 net 지연관성지연 (inertial delay)

V il HDL의 d f lt지연 Verilog HDL의 default 지연지정된지연값보다입력신호의변화폭이작은경우, 입력신호의변화가출력에영향을미치지않음변화가출력에영향을미치지않음

관성지연은게이트수준모델링에도동일하게적용

관성지연의적용과정관성지연의적용과정

①우변수식의값이평가된다.②평가된우변의값이좌변에할당예정된값과다르면, 현재예정된할당 event가②평가 우 의값이좌 에할당예정 값과다 , 재예정 할당 가

취소된다.③새로운우변의값이좌변의현재값과동일하면할당을위한 event가예정되지않는다.

④새로운우변의값이좌변의현재값과다르면, 지연이계산되고주어진지연후에새로운할당 event가일어나도록예정된다.

Ver1.0 (2008)103한국기술교육대학교 정보기술공학부

Page 104: 1 1. VilVerilog HDL 개요Verilog HDL의역사 Verilog HDL 1983년GatewayDesignAutomationGateway Design Automation사에서하드웨어기술언어인 HiLo와C 언어의특징을기반으로개발

4.1.1할당지연과 net 지연module inertial_delay();reg a, b;assign #30 wireA = a & b;i iti l b iinitial begin

a = 1'b0; b = 1'b0;#50 a = 1'b1; b = 1'b1;#50 a = 1'b0; b = 1'b0;# ; ;#50 a = 1'b1; b = 1'b1;#20 b = 1'b0;#50; end

d d l

코드 4.3

endmodule

Ver1.0 (2008)104한국기술교육대학교 정보기술공학부

Page 105: 1 1. VilVerilog HDL 개요Verilog HDL의역사 Verilog HDL 1983년GatewayDesignAutomationGateway Design Automation사에서하드웨어기술언어인 HiLo와C 언어의특징을기반으로개발

4.2절차형할당문 절차형할당문

i t l ti lti 등 i bl 에값을갱신 reg, integer, real, time, realtime 등 variable에값을갱신 지연을갖지않으며, 다음절차형할당문에의해값이갱신될때까지변수에할당된값을유지할당된값을유지

always, initial, task, function 등의프로시저(procedure) 내부에서사용 문장의실행에의해좌변 variable에값이할당되는소프트웨어적인특성

우변수식의 event 발생과는무관 할당문들의순서가시뮬레이션결과에영향을미칠수있음

함축적변수할당문

variable 선언문에서 variable에대한초기값을설정 배열에대한함축적변수할당은허용되지않음 배열에대한함축적변수할당은허용되지않음

Ver1.0 (2008)105한국기술교육대학교 정보기술공학부

Page 106: 1 1. VilVerilog HDL 개요Verilog HDL의역사 Verilog HDL 1983년GatewayDesignAutomationGateway Design Automation사에서하드웨어기술언어인 HiLo와C 언어의특징을기반으로개발

4.2절차형할당문

module proc_assignment(a, b, c, out);input a, b;output out;reg out, c;reg out, c;

always @(posedge c) begin c = a & b; // blocking assignment

//out <= c; // nonblocking assignmentend

endmodule 코드 4.4

reg[3:0] areg = 4'h4;

reg[3:0] areg; 함축적변수할당문과등가

initial areg = 4'h4;

reg [3:0] array [3:0] = 0; //illegal (배열에 대한 함축적 변수 할당문)

Ver1.0 (2008)106

reg [3:0] array [3:0] = 0; //illegal (배열에 대한 함축적 변수 할당문)

한국기술교육대학교 정보기술공학부

Page 107: 1 1. VilVerilog HDL 개요Verilog HDL의역사 Verilog HDL 1983년GatewayDesignAutomationGateway Design Automation사에서하드웨어기술언어인 HiLo와C 언어의특징을기반으로개발

4.3절차형연속할당문 (PCA) 절차형연속할당문 (Procedural Continuous Assignment; PCA)

절차형할당문의예외적인구문

variable 또는 net에대해연속적구동을허용하는절차형할당문 assign - deassign 문

i PCA문 형 i bl 에연속할당문인 i 을사용하여 assign PCA 문 : reg 형 variable에연속할당문인 assign을사용하여절차형할당을덮어쓰기(override)하는예외적인구문

deassign PCA문 : variable에대한 assign PCA문의영향을제거 deassign PCA 문 : variable에대한 assign PCA 문의영향을제거 force-release 문

assign - deassign 문과기능이동일하나, force는 variable뿐만아니라net에도사용될수있음

variable에대한 force 문 : release 문이실행되기전까지절차형할당또는PCA문을덮어쓰기한다PCA 문을덮어쓰기한다.

net에대한 force 문 : release 문이실행되기전까지 net, 게이트및모듈출력, 연속할당문등의모든 driver를덮어쓰기한다.

Ver1.0 (2008)107한국기술교육대학교 정보기술공학부

Page 108: 1 1. VilVerilog HDL 개요Verilog HDL의역사 Verilog HDL 1983년GatewayDesignAutomationGateway Design Automation사에서하드웨어기술언어인 HiLo와C 언어의특징을기반으로개발

4.3절차형연속할당문 (PCA)

edge-triggered D 플립플롭의비동기 clear/preset 동작모델링

module dff(q, d, clear, preset, clock);output q;input d clear preset clock;

g gg p

input d, clear, preset, clock;reg q;

always @(clear or preset)if(!clear)

assign q = 0;else if(!preset)

assign q = 1;assign q = 1;else

deassign q;

always @(posedge clock)q = d;

endmodule 코드 4.5

Ver1.0 (2008)108한국기술교육대학교 정보기술공학부

Page 109: 1 1. VilVerilog HDL 개요Verilog HDL의역사 Verilog HDL 1983년GatewayDesignAutomationGateway Design Automation사에서하드웨어기술언어인 HiLo와C 언어의특징을기반으로개발

4.3절차형연속할당문 (PCA)

module force_release;reg a, b, c, d;wire e;

and and1(e, a, b, c);initial begin

$monitor("%d d=%b,e=%b", $time, d, e);assign d = a & b & c;a = 1; b = 0; c = 1;#10;force d =(a | b | c);force d =(a | b | c);force e =(a | b | c);#10 $stop;release d;release e;#10 $finish;

endendmodule 코드 4 6

0 d=0,e=010 d=1,e=120 d=0,e=0

Ver1.0 (2008)109

endmodule 코드 4.620 d 0,e 0

한국기술교육대학교 정보기술공학부