디지털시스템설계및실습 1. Verilog HDL 문법 한국기술교육대학교전기전자통신공학부 Ver1.0 (2008)1

Similar documents
Microsoft PowerPoint - DSD01_verilog1a.pptx

Microsoft PowerPoint - M01_VerilogHDL01.ppt [호환 모드]

Microsoft PowerPoint - DSD01_verilog1b.pptx

Microsoft PowerPoint - verilog문법new.ppt

OCW_C언어 기초

Microsoft PowerPoint - hw4.ppt [호환 모드]

Microsoft PowerPoint - chap04-연산자.pptx

MAX+plus II Getting Started - 무작정따라하기

歯Chap1-Chap2.PDF

Microsoft PowerPoint - 3ÀÏ°_º¯¼ö¿Í »ó¼ö.ppt

Microsoft PowerPoint - Verilog_Summary.ppt

Microsoft PowerPoint - DSD03_verilog3b.pptx

VHDL 기초 VHDL 두원공과대학정보통신미디어계열이무영

Microsoft PowerPoint - DSD03_verilog3a.pptx

Microsoft Word - 제6장 Beyond Simple Logic Gate.doc

wire [n-1:0] a, b, c, d, e, f, g, h; wire [n-1:0] x; // internal wires wire [n-1:0] tmp0, tmp1, tmp2, tmp3, tmp4, tmp5; mux_2to1 mux001 (.x(tmp0),.a(a

Microsoft PowerPoint - DSD02_verilog2a.pptx

Microsoft PowerPoint - hw8.ppt [호환 모드]

ºÎ·ÏB

Microsoft PowerPoint - VHDL01_chapter1.ppt [호환 모드]

비트와바이트 비트와바이트 비트 (Bit) : 2진수값하나 (0 또는 1) 를저장할수있는최소메모리공간 1비트 2비트 3비트... n비트 2^1 = 2개 2^2 = 4개 2^3 = 8개... 2^n 개 1 바이트는 8 비트 2 2

PowerPoint 프레젠테이션

Microsoft PowerPoint - ICCAD_Digital_lec02.ppt [호환 모드]

슬라이드 1

Microsoft PowerPoint - C프로그래밍-chap03.ppt [호환 모드]

프로그래밍개론및실습 2015 년 2 학기프로그래밍개론및실습과목으로본내용은강의교재인생능출판사, 두근두근 C 언어수업, 천인국지음을발췌수정하였음

< E20C6DFBFFEBEEE20C0DBBCBAC0BB20C0A7C7D12043BEF0BEEE20492E707074>

2 장수의체계 1. 10진수 2. 2진수 3. 8진수와 16진수 4. 진법변환 5. 2진정수연산과보수 6. 2진부동소수점수의표현 한국기술교육대학교전기전자통신공학부전자전공 1

디지털공학 5판 7-8장

Microsoft Word - logic2005.doc

C# Programming Guide - Types

Microsoft PowerPoint - VHDL08.ppt [호환 모드]

PowerPoint 프레젠테이션

Microsoft Word - logic2005.doc

Microsoft PowerPoint 자바-기본문법(Ch2).pptx

슬라이드 1

PowerPoint 프레젠테이션

8장 조합논리 회로의 응용

PowerPoint 프레젠테이션

Microsoft PowerPoint - chap03-변수와데이터형.pptx

Computer Architecture

강의 개요

Microsoft PowerPoint - 1-2장 디지털_데이터 .ppt

untitled

Microsoft PowerPoint - DSD02_verilog2b.pptx

Microsoft PowerPoint - chap-05.pptx

Microsoft PowerPoint - Perpect C 02.ppt [호환 모드]

hwp

Microsoft PowerPoint - lec2.ppt

Microsoft PowerPoint - chap02-C프로그램시작하기.pptx

T100MD+

<4D F736F F F696E74202D C6F672D48444CC0BB20C0CCBFEBC7D120B5F0C1F6C5D0BDC3BDBAC5DBBCB3B0E82E707074>

歯03-ICFamily.PDF

Microsoft PowerPoint - CHAP-03 [호환 모드]

PowerPoint 프레젠테이션

[2010 년디지털시스템설계및실험중간고사 2 답안지 ] 출제 : 채수익 1. (a) (10 pts) Robertson diagram Quotient 와 remainder 의 correction 을뒤로미루는것이 non-restoring division 이다. 즉, q =

슬라이드 1

수없기때문에간단한부분으로나눠서구현하고, 이를다시합침으로써전체를구현하게 된다. 실험에서는이미구현된 4-Bit ALU인 74LS181 Chip을사용한다. 이 Chip은 4-bit의 Data input A, B와 Selection input 4 bit, Carry In 1

Microsoft PowerPoint - ICCAD_Analog_lec01.ppt [호환 모드]

歯02-BooleanFunction.PDF

Microsoft PowerPoint - C++ 5 .pptx

<4D F736F F F696E74202D20B8B6C0CCC5A9B7CEC7C1B7CEBCBCBCAD202839C1D6C2F7207E203135C1D6C2F >

Microsoft PowerPoint - [2009] 02.pptx

<4D F736F F F696E74202D20332EB5F0C1F6C5D0C8B8B7CEBFCD20B1B8C7F62E >

4. #include <stdio.h> #include <stdlib.h> int main() { functiona(); } void functiona() { printf("hihi\n"); } warning: conflicting types for functiona

PHPoC vs PHP > 개요 개요 PHPoC 는솔내시스템 이자체개발한프로그래밍언어입니다. 당사의모든 PHPoC 제품들의펌웨어에는 PHPoC 인터프리터가내장되어있습니다. PHPoC 는범용스크립트언어인 PHP 를기반으로제작되었습니다. PHPoC 는매우간단하여 C 언어등

<4D F736F F F696E74202D20BBB7BBB7C7D15F FBEDFB0A3B1B3C0B05FC1A638C0CFC2F72E BC8A3C8AF20B8F0B5E55D>

슬라이드 1

Microsoft PowerPoint - c2.ppt

. 고성능마이크로프로세서 LU 와레지스터 파일의구조 (2.). 직접디지털주파수합성기 (FS) 의구조 3. 고성능마이크로프로세서부동소수점연산기 (Floating-Point Unit) 구조 (2) (2.) (2.) 2. 암호화를위한 VLSI 구조와설계의개요 (2.) 다음참

[ 마이크로프로세서 1] 2 주차 3 차시. 포인터와구조체 2 주차 3 차시포인터와구조체 학습목표 1. C 언어에서가장어려운포인터와구조체를설명할수있다. 2. Call By Value 와 Call By Reference 를구분할수있다. 학습내용 1 : 함수 (Functi

학습목차 2.1 다차원배열이란 차원배열의주소와값의참조

<4D F736F F F696E74202D C61645FB3EDB8AEC7D5BCBA20B9D720C5F8BBE7BFEBB9FD2E BC8A3C8AF20B8F0B5E55D>

chap 5: Trees

1.2 자료형 (data type) 프로그램에서다루는값의형태로변수나함수를정의할때주로사용하며, 컴퓨터는선언된 자료형만큼의메모리를확보하여프로그래머에게제공한다 정수 (integer) 1) int(4 bytes) 연산범위 : (-2 31 ) ~ (2 31 /2)-

Microsoft PowerPoint - ch07 - 포인터 pm0415

한국기술교육대학교장영조 한국기술교육대학교전기전자통신공학부 1

KNK_C03_Expr_kor

PowerPoint 프레젠테이션

Microsoft PowerPoint - KNK_C03_Expr_kor

Microsoft PowerPoint - a10.ppt [호환 모드]

歯15-ROMPLD.PDF

Microsoft PowerPoint - e pptx

Microsoft PowerPoint - M07_RTL.ppt [호환 모드]

컴파일러

Microsoft PowerPoint - chap06-2pointer.ppt

OCW_C언어 기초

1

10 강. 쉘스크립트 l 쉘스크립트 Ÿ 쉘은명령어들을연속적으로실행하는인터프리터환경을제공 Ÿ 쉘스크립트는제어문과변수선언등이가능하며프로그래밍언어와유사 Ÿ 프로그래밍언어와스크립트언어 -프로그래밍언어를사용하는경우소스코드를컴파일하여실행가능한파일로만들어야함 -일반적으로실행파일은다

API 매뉴얼

금오공대 컴퓨터공학전공 강의자료

JAVA PROGRAMMING 실습 02. 표준 입출력

06 세상을 변화시키는 연산자

Microsoft PowerPoint - 강의자료8_Chap9 [호환 모드]

슬라이드 1

<BFACBDC0B9AEC1A6C7AEC0CC5F F E687770>

목차 BUG DEQUEUE 의 WAIT TIME 이 1 초미만인경우, 설정한시간만큼대기하지않는문제가있습니다... 3 BUG [qp-select-pvo] group by 표현식에있는컬럼을참조하는집합연산이존재하지않으면결괏값오류가발생할수있습니다... 4

歯처리.PDF

Transcription:

디지털시스템설계및실습 1. Verilog HDL 문법 Ver1.0 (2008)1

Verilog HDL 의역사 q Verilog HDL v 1983년 Gateway Design Automation사에서하드웨어기술언어인 HiLo와 C 언어의특징을기반으로개발 v 1991년 Cadence Design Systems가 Open Verilog International (OVI) 라는조직을구성하고 Verilog HDL을공개 v 1993년 IEEE Working Group이구성되어표준화작업을진행 v 1995년 12월 IEEE Std. 1364-1995로표준화 v 2001년에 IEEE Std. 1364-2001로개정 v Verilog HDL의확장형태인 SystemVerilog가개발되어 IEEE 표준화를추진 Ver1.0 (2008)2

Verilog HDL 과 C 언어 q C 언어와유사점 v 문법은매우유사 v 절차형 (procedural) 및순차형실행은동일 v if~else문, case 문, for loop 문등사용 v 연산자 : 논리 (&,, ^..), 산술 ( +, -, * /..), 비교 (<, >=, ==,..) qhdl 언어의특성 v 동시성 (concurrent) v 병렬성 (parallel) v 추상화 (abstraction) Ver1.0 (2008) 3

HDL 의 3 가지 Modeling q 구조적 (Structural) 모델링 v 논리게이트, 플립플롭등을사용한연결도표현 v 기존설계한회로를포함한네트리스트 (netlist) 사용 q 데이터플로우 (dataflow) 모델링 v 데이터이동을표현 v 연산자를사용한연속할당문 q 동작적 (behavioral) 모델링 v if~else, case, while, for 등과같은구문사용 v 인간의사고에가장근접한표현 Ver1.0 (2008) 4

Verilog 언어의기능 q시뮬레이션 (simulation) : full set q합성 ( synthesis) : subset qlibrary : system 함수 q문서화 (documentation) : full set Verilog HDL 합성 assign, if~else, case, for always Simulation, 문서화 initial, $finish $fopen Library specify $width table Ver1.0 (2008) 5

설계흐름도와추상화레벨 High level Abstraction Specification 사양 : 동작모델, 속도, 전력, 가격, 소형화.. C, System C, SystemVerilog Design Entry Behavioral Simulation 설계입력 : 블록도와입출력신호연결도그래픽혹은문서입력 Verilog, VHDL High level Synthesis Functional (RTL) Simulation RTL : 동작적표현, 클럭타이밍 Adder, 디코더, ALU, 레지스터.. Verilog, VHDL Gate level Synthesis Gate level Simulation 게이트레벨,: 논리, 프리미티브게이트연결도 Verilog, VHDL Low level Abstraction Technology Mapping Timing Simulation 하드웨어 : SoC, ASIC, FPGA. 배치및배선, 타이밍검증 EDIF, JEDEC Ver1.0 (2008) 6

Verilog 첫걸음 Ver1.0 (2008) 7

반가산기 (Half Adder) 설계 진리표 x y co s 0 0 0 0 0 1 0 1 1 0 0 1 논리식 S = x xor y co = xy 모듈정의 module HA (x, y, co, s); input x; input y; output co, s; 1 1 1 0 HA module name x y co input output s Ver1.0 (2008) 8

반가산기 (Half Adder) 설계 q 모듈구조 Ver1.0 (2008) 9

반가산기 (Half Adder) 설계 q 모델링 // code1.2.1-1 : HA_s.v module HA_s (x, y, co, s); input x; input y; output co, s; // 하위모듈호출, 구조적모델링 and U1 (co, x, y); // 프리미티브게이트인스턴스 xor U2 (s, x, y); endmodule // code 1.2.1-2 : HA_d.v module HA_d (x, y, co, s); input x; input y; output co, s; // 연속할당문, 데이터플로우모델링 assign s = x ^ y ; // bitwise XOR 논리연산자 assign co = x & y; // bitwise AND 논리연산자 endmodule Ver1.0 (2008) 10

반가산기 (Half Adder) 설계 q 모델링 // code 1.2.1-3 : HA_b.v module HA_b (x, y, co, s); input x; input y; output co, s; reg co, s; // 절차형블록문, 동작적모델링 always @ (x or y) begin s = x ^ y ; // blocking 할당문 co = x & y; end endmodule // code 1.2.1-4 : HA_t.v module HA_t (x, y, co, s); input x, y; output co, s; reg co, s; // 절차형블록문, 진리표의동작적모델링 always @ (x or y) case ({x,y}) 2'b00 : {co,s} = 2'b00; 2'b01 : {co,s} = 2'b01; 2'b10 : {co,s} = 2'b01; 2'b11 : {co,s} = 2'b10; default : {co,s} = 2'b00; endcase endmodule Ver1.0 (2008) 11

설계검증 q 테스트벤치 시뮬레이션을위한입력여기 (stimulus) 파형 // code 1.2.2-1 : TB_HA.v `timescale 1ns/1ps // 시뮬레이션시간단위 module TB_HA; reg x, y; wire cout, sum; // DUT instance HA_b U1 (.x(x),.y(y),.co(cout),.s(sum) ); 시뮬레이션파형 // input stimulus initial begin x=0; y=0; #200; // 200 ns 지연 x=0; y=1; #200; // 200 ns 지연 x=1; y=0; #200; x=1; y=1; #200; $finish; // 시뮬레이션종료 end endmodule Ver1.0 (2008) 12

1.3 Verilog 어휘규칙 q 어휘토큰 (lexical tokens) v 여백 (white space) v 주석 (comment) v 연산자 (operator) v 수 (number) v 문자열 (string) v 식별자 (identifier) v 키워드 (keyword) Ver1.0 (2008) 13

Verilog 어휘규칙 q 여백 (white space) v 빈칸 (space), 탭 (tab), 줄바꿈 v 어휘토큰들을분리하기위해사용되는경우를제외하고는무시 v 공백 (blank) 과탭은문자열에서의미있게취급 q 주석 (comment) v HDL 소스코드의설명을위해사용되며, 컴파일과정에서무시됨 v 단일라인주석문 ; // 로시작되어해당라인의끝까지 v 블록주석문 ; /* ~ */ 로표시 Ø 블록주석문은내포 (nested) 될수없음 q 연산자 (operator) v 단항연산자, 2 항연산자, 3 항연산자 Ver1.0 (2008) 14

Verilog 어휘규칙 q 식별자 (identifier) v 객체에고유의이름을지정하기위해사용 v 대소문자를구별하여인식 v 가독성을위해밑줄사용가능 v 단순식별자 ; 일련의문자, 숫자, 기호 $, 밑줄등으로구성 Ø 첫번째문자는숫자나기호 $ 사용불가, 문자또는밑줄만사용 v 확장식별자 (escaped identifier); Ø \ (back slash) 로시작되며, 여백 ( 빈칸, 탭, 줄바꿈 ) 등으로끝남 Ø 프린트가능한 ASCII 문자들을식별자에포함시키는수단을제공 q 키워드 (keyword) v Verilog 구성요소를정의하기위해미리정의된식별자 v 확장문자가포함된키워드는키워드로인식되지않음 Ver1.0 (2008) 15

Verilog 어휘규칙 예 : 유효한식별자의예 shiftreg_a busa_index error_condition merge_ab _bus3 n$657 예 : 확장식별자의예 \busa+index \-clock \***error-condition*** \net1/\net2 \{a,b} \a*(b+c) Ver1.0 (2008) 16

Verilog 어휘규칙 q 수표현 (number representation) v 정수형 (integer) ; 10 진수, 16 진수, 8 진수, 2 진수 v 형식 : [size_constant]'<base_format> <number_value> Ø [size_constant]: 값의비트크기를나타내는상수 ü 0 이아닌 unsigned 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 가함께사용될수있음 Ø number_value : unsigned 숫자를사용하여값을표현 ü 'base_format 에적합한숫자들로구성 Ø base_format 과 number_value 사이에 + 또는 - 부호사용불가 Ver1.0 (2008) 17

Verilog 어휘규칙 q 수표현 (number representation) v 비트크기와밑수를갖지않는단순 10진수는 signed 정수로취급 v 부호지정자없이밑수만지정되면 unsigned 정수로취급 v 밑수지정자와부호지정자 s가함께사용되면 signed 정수로취급 Ø 부호지정자 s는비트패턴에는영향을미치지않으며, 비트패턴의해석에만영향을미침 v 음수는 2의보수 (2 s complementary) 형식으로표현됨 v 지정된비트크기보다 unsigned 수의크기가작은경우 Ø MSB 왼쪽에 0이삽입 Ø MSB가 x 또는 z이면, x 또는 z가왼쪽에삽입 v 값에물음표 (? ) 가사용되면 z로취급 v 첫번째문자를제외하고는밑줄 (underscore) 이사용될수있으며, 이는수의가독성 (readability) 을좋게함 Ver1.0 (2008) 18

Verilog 어휘규칙 Number # of Bits Base Dec. Equiv. Stored 10 32 Decimal 10 00...01010 2 b10 2 Binary 2 10 3 d5 3 Decimal 5 101 8 o5 8 Octal 5 00000101 8 ha 8 Hex 10 00001010 3 b5 Invalid! 3 b01x 3 Binary - 01x 12 hx 12 Hex - xxxxxxxxxxxx 8 b0000_0001 8 Binary 1 00000001 8 bx01 8 Binary - xxxxxx01 bz Unsized Binary - zz...zz(32bits) 8 HAD 8 Hex 173 10101101 Ver1.0 (2008) 19

Verilog 어휘규칙 예 1.3.1 : unsized 상수 1250 // 부호없는 10진수 'o765 // 부호없는 8진수 'shab74 // 부호있는 16진수 'b1100_111 // 부호없는 2진수 'bz // zz...zz (32 bits) 4af // illegal (hexadecimal format requires 'h) 예 1.3.2 : sized 상수 3'b110 // 3비트 2진수, 110 4'b1zx0 // 4비트 2진수, 1zx0 9'O513 // 9비트 8진수, 1_0100_1011 8'hef // 8비트 16진수, 1110_1111 8'bz // 8비트 2진수, z로채워짐, zzzzzzzz 6'b1 // 6비트 2진수, 00_0001 6'shA // 6비트부호있는 16진수, 00_1010 6'h97 // 6비트 16진수, 01_0111, 상위 2비트잘려짐 12'd15 // 12비트 10진수, 0000_0000_1111 Ver1.0 (2008)

Verilog 어휘규칙 예 1.3.3 : signed 8'shE0 // 1110_0000, -32에대한 2의보수, // 8 he0와동일 -8'shE0 // -(8'1110_0000), 0010000, 즉 +32 - d100 // 2 32-100 = 4294967196 -'sd100 // -100 = 4294967196-5 d6 // -6에대한 5비트 2의보수, 11010 4'sb1010 // -6 12'sb0010 // 0000_0000_0010, +2 예 : 밑줄을사용한수의표현 27_195_000 16'b0011_0101_0001_1111 32'h12ab_f001 Ver1.0 (2008) 21

Verilog 어휘규칙 예 : MSB 자동삽입 reg [11:0] a, b, c, d; initial begin a = 'hx; // yields xxx b = 'h3x; // yields 03x c = 'hz3; // yields zz3 d = 'h0z3; // yields 0z3 end Ver1.0 (2008) 22

Verilog 어휘규칙 v 실수형 (real) ; IEEE Std. 754-1985(IEEE standard for double-precision floating-point number) 표현형식 value.value baseeexponent decimal notation scientific notation (the E is not case sensitive) 예 1.3.4 : 실수표현 0.5 679.00123 3e4 0.5e-0 5.6E-2 87E-4 93.432_26e-5 예 : 문법적오류.12 9. 4.E3.2e-7 Ver1.0 (2008) 23

Verilog 어휘규칙 q 문자열 (string) v 이중인용부호 ( ) 사이에있는일련의문자들 v 단일라인에존재해야하며, 여러라인에걸친문자열은사용불가 v 8비트 ASCII 값으로표현되는 unsigned 정수형상수로취급 v 문자열변수는 reg형의변수이며, 문자열내의문자수에 8을곱한크기의비트폭을가짐 예 1.3.6 : string 저장 reg [8*18:1] str1; initial begin str1 = "Hello Verilog HDL!"; end Ver1.0 (2008) 24

Verilog 어휘규칙 예 1.3.7 : string 저장및인쇄 module str_test; reg [8*10:1] str1; initial begin str1 = Hello ; $display( %s is stored as %h", str1, str1); str1 = {str1, "!!!"}; $display( %s is stored as %h", str1, str1); end endmodule Hello is stored as 000000000048656c6c6f Hello!!! is stored as 0048656c6c6f20212121 Ver1.0 (2008) 25

Verilog 어휘규칙 v 특수문자앞에확장문자 (escaped character) 를사용하면일부 특수문자를문자열에포함시킬수있음 확장문자를이용한특수문자의표현 확장문자열 확장문자열에의해생성되는특수문자 \n New line character \t Tab character \\ \ character \" " character \ddd A character specified in 1~3 octal digits (0 d 7) Ver1.0 (2008) 26

Verilog 논리값 (Logic Value) v 4 logic value 논리값 설명 0 1 z or Z x or X zero, low, or false one, high, or true high impedance (tri-stated or floating) unknown or uninitialized Ver1.0 (2008) 27

논리강도 (Logic strength) q8 개의논리강도 4 개의 driving, 3 개의 capacitive, 2 개의 high impedance (no strength) strength strength specification display level name keyword mnemonic 7 supply drive supply0 supply1 Su0 Su1 6 strong drive strong0 strong1 St0 St1 5 pull drive pull0 pull1 Pu0 Pu1 4 large capacitive large La0 La1 3 weak drive weak0 weak1 We0 We1 2 medium capacitive medium Me0 Me1 1 small capacitive small Sm0 Sm1 0 high impedance highz0 highz1 HiZ0 HiZ1 Ver1.0 (2008) 28

Ver1.0 (2008) Velilog Keyword 29 always and assign automatic begin buf bufif0 bufif1 case casex casez cell cmos config deassign default defparam design disable edge else end endcase endconfig endfunction endgenerate endmodule endprimitive endspecify endtable endtask event for force forever fork function generate genvar highz0 highz1 if ifnone initial instance inout input integer join large liblist localparam macromodule medium module nand negedge nmos nor not noshowcancelled notif0 notif1 or output parameter pmos posedge primitive pull0 pull1 pulldown pullup pulsestyle_onevent pulsestyle_ondetect rcmos real realtime reg release repeat rnmos rpmos rtran rtranif0 rtranif1 scalared signed showcancelled small specify specparam strength strong0 strong1 supply0 supply1 table task time tran tranif0 tranif1 tri tri0 tri1 triand trior trireg unsigned use vectored wait wand weak0 weak1 while wire wor xnor xor

Verilog HDL 의모듈 모듈 (module) 설계의기본단위, design entity module module_name (port_list); port 선언 reg 선언 wire 선언 parameter 선언 하위모듈호출 always, initial 문 function, task 정의문 assign 문 function, task 호출문 endmodule Semicolon 모듈선언부 body No Semicolon Ver1.0 (2008) 30

모듈정의 (definition) // 암시적내부연결 ( Implicit Internal Connection ) module module_name (port_name, port_name,... ); module_items endmodule // 명시적내부연결 (Explicit Internal Connection) module module_name (.port_name (signal_name ),.port_name (signal_name ),... ); module_items endmodule Ver1.0 (2008) 31

모듈정의 (definition) qmodule items v module_port_declarations v data_type_declarations v module_instances v primitive_instances v procedural_blocks v continuous_assignments v task_definitions v function_definitions Ver1.0 (2008) 32

모듈정의 (definition) 포트연결예 // code 1.4.1-1:ex1.v 모듈정의의암시적연결, 등가비교기 module ex1 ( a1, b1, out1); input [3:0] a1, b1; output out1; assign out1 = ( a1 >= b1 ); // continuous assignment endmodule // code 1.4.1-2: ex2.v 모듈정의에포트선언목록을포함한암시적연결 // 2 input MUX with 2 bit widths module ex2 (input wire [1:0] i0, i1, input wire sel, output wire [1:0] out2); wire t0, t1; assign out2 = {t1, t0}; // concatenation assign t1 = sel? i1[1] : i0[1]; assign t0 = sel? i1[0] : i0[0]; endmodule Ver1.0 (2008) 33

모듈정의 (definition) 포트연결예 // 예 1.4.1 모듈정의의명시적연결예 module exp_port1 (.a(n1),.b(n2) ); // n1, n2는모듈내부에서선언 // a, b는포트연결로정의 module exp_port2 (.a({b,c}), d,.f(g, h[2])); // b, c, d, g, h[2] 는모듈내부에서선언 // a, d, f는포트연결로정의 module exp_port3 ({a, b},.c(d)) // a, b, d는모듈내부에서선언 // {a, b}, c는포트연결로정의 Ver1.0 (2008) 34

포트선언 (port declaration) q 포트선언형식 port_direction data_type signed [port_size] port_name, port_name,.. ; q 포트방향 v input : 스칼라 (scalar) 나벡터 (vector) 의입력포트선언 v output : 스칼라 (scalar) 나벡터 (vector) 의출력포트선언 v inout : 스칼라 (scalar) 나벡터 (vector) 의양방향포트선언 Ver1.0 (2008) 35

포트사용예 // 예 1.4.2 포트선언예 input a1, a2, en; input signed [7:0] a, b; // 3 개의스칼라 1 비트포트 // 2 개의 8 비트 signed 값을갖는포트 output reg signed [16:0] res; // 데이터형과 signed 속성을갖는포트 output reg [11:0] cnt1; inout [0:15] data_bus; input [15:12] addr; // little endian 표기방식 // big endian 표기방식 // msb:lsb 는정수값 parameter BW = 32; input [BW-1:0] addr; // 상수표현식사용가능 parameter SIZE = 4096; input [log2(size)-1:0] addr; // 상수함수를선언에서호출가능 Ver1.0 (2008) 36

Verilog HDL 의모듈 wire, reg wire wire input inout output wire Module_instance_A wire wire wire wire, reg Primitive instantiation wire wire, reg Module_instance_B wire wire wire, reg Continuous assignment assign wire_a = C D; reg reg_a, reg_b,... integer int_a,... always begin... end declarations Behavior_1 register variables initial begin... end Behavior_2 Ver1.0 (2008) 37

Verilog 모델링예 q 게이트프리미티브를이용한모델링예 ( 반가산기회로 ) Module Name Module Ports a b cout sum module Half_Adder (a, b, sum, cout); input a, b; output sum, cout; wire cout_bar; Declaration of port modes 0 0 0 0 0 1 0 1 1 0 0 1 1 1 1 0 xor (sum, a, b); nand (cout_bar, a, b); not (cout, cout_bar); endmodule Declaration of internal signals a b Half_ Adder sum = a ^ b cout = a & b sum cout Verilog keyword Instantiation of Primitive gates Ver1.0 (2008) 38

1.5 Data Type Ver1.0 (2008) 39

Verilog 의논리값 Verilog 의논리값집합 논리값 의미 0 logic zero, or false condition 1 logic one, or true condition x z unknown logic value high-impedance state Ver1.0 (2008) 40

Verilog 의논리값 q Zero, low, false, logic low, ground, VSS 0 q One, high, true, logic high, power, VDD, VCC 1 q X, unknown : occurs at logical conflict which cannot be resolved x q HiZ, high impedence, tri-stated, disabled or disconnected driver z 0 Ver1.0 (2008) 41

Verilog HDL 의자료형 q Net 자료형 : 소자간의물리적인연결을추상화 v wire, tri, wand, wor, triand, trior, supply0, supply1, tri0, tri1, trireg v Default 자료형 ; 1비트의 wire q Variable 자료형 (Regiser 자료형 ): 절차형할당문사이의값의임시저장 v 프로그래밍언어의 variable과유사한개념 v reg, integer, real, time, realtime net 자료형과 variable 자료형의할당모드 할당모드 자료형 프리미티브 출력 연속할당문 절차형할당문 assign deassign PCA force release PCA Net Yes Yes No No Yes Variable Comb (No) Seq (Yes) No Yes Yes Yes * PCA : Procedural Continuous Assignment Ver1.0 (2008) 42

variable 자료형 q variable 자료형 ; reg, integer, real, time, realtime 키워드 reg integer real time realtime 기능임의비트크기의 unsigned variable 32 비트 signed variable 배정도부동소수점 variable 64 비트 unsigned variable 배정도부동소수점 variable v 절차적할당문 (procedural assignment) 의실행에의해그값이바뀌며, 할당에서부터다음할당까지값을유지 v default 초기값 Ø reg, time, integer 자료형 : x (unknown) Ø real, realtime 자료형 : 0.0 v variable이음의값을할당받는경우, Ø signed reg, integer, real, realtime 자료형 : 부호를유지 Ø unsigned reg, time 자료형 : unsigned 값으로취급 Ver1.0 (2008) 43

variable 자료형 q reg v 절차적할당문에의해값을받는객체의자료형 v 할당사이의값을유지 v 하드웨어레지스터를모델링하기위해사용될수있음 Ø edge-sensitive ( 플립플롭등 ) 와 level-sensitive ( 래치등 ) 의저장소자들을모델링할수있음 Ø reg는조합논리회로의모델링에도사용되므로, reg가항상하드웨어적인저장소자를의미하지는않음 예 : reg 자료형선언예 reg a; // a scalar reg reg[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 7 reg [-1:4] b; // a 6-bit vector reg reg [4:0] x, y, z; // declares three 5-bit regs Ver1.0 (2008) 44

variable 자료형 module dff (clk, d, q); input d,clk; output q; reg q; always @(posedge clk) q <= d; endmodule D 플립플롭 module mux21_if(a, b, sel, out); input [1:0] a, b; input sel; output [1:0] out; reg [1:0] out; always @(a or b or sel) if(sel == 1'b0) out = a; else out = b; endmodule 2 : 1 MUX Ver1.0 (2008) 45

variable 자료형 q integer 자료형 v 정수형값을취급하며, 절차적할당문에의해값이변경됨 v signed reg로취급되며, 연산결과는 2의보수가됨 q time 자료형 v 시뮬레이션시간을처리하거나저장하기위해사용됨 v 64비트의 reg와동일하게작용 v unsigned 값이고 unsigned 연산이이루어짐 q real, reatime 자료형 v 실수형값을취급예 : Variable 자료형선언예 integer a; // integer value time last_chng; // time value real float ; // a variable to store real value realtime rtime ; // a variable to store time as a real value Ver1.0 (2008) 46

net 자료형 q net 자료형 v 논리게이트나모듈등의하드웨어요소들사이의물리적연결을나타내기위해사용 v 연속할당문 (continuous assignment), 게이트프리미티브등과같은구동자 (driver) 의값에의해 net의값이연속적으로유지됨 Ø 값을저장하지않음 ( 단, trireg net 는예외 ) v 구동자가연결되지않으면, default 값인 high-impedance (z) 가됨 Ø 단, trireg net 는이전에구동된값을유지 v default 자료형은 1비트의 wire v default 초기값은 z Ø trireg net 는 default 초기값으로 x 를가짐 Ver1.0 (2008) 47

net 자료형 Verilog net 자료형 자료형이름 wire tri wand wor triand trior supply0 supply1 tri0 tri1 trireg 의미 함축된논리적동작이나기능을갖지않는단순한연결을위한 net 함축된논리적동작이나기능을갖지않는단순한연결을위한 net 이며, 하드웨어에서 3 상태 (tri-state) 가되는점이 wire 와다름 다중구동자를갖는 net 이며, wired-and ( 즉, open collector logic) 의하드웨어구현을모델링하기위해사용 다중구동자를갖는 net 이며, wired-or ( 즉, emitter coupled logic) 의하드웨어구현을모델링하기위해사용 wand 와동일하게다중구동자를갖는 net 이며, 하드웨어에서 3 상태 (tri-state) 를갖는점이다름 wor 와동일하게다중구동자를갖는 net 이며, 하드웨어에서 3 상태 (tri-state) 를갖는점이다름 회로접지 (circuit ground) 에연결되는 net 전원 (power supply) 에연결되는 net 저항성 pulldown (resistive pulldown) 에의해접지로연결되는 net 저항성 pullup (resistive pullup) 에의해전원으로연결되는 net 물리적인 net 에저장되는전하를모델링하는 net Ver1.0 (2008) 48

net 자료형 q wire 와 tri v 회로구성요소들사이의연결에사용 v wire : 단일게이트또는단일연속할당문에의해구동되는 net에사용 v tri : 3상태 net에사용 wire, tri net 의진리표 wire/tri 0 1 x z 0 0 x x 0 1 x 1 x 1 x x x x x z 0 1 x z 예 : net 자료형선언예 wire w1, w2; // declares two wires, 생략가능 wire [7:0] bus; // a 8-bit bus wire enable=1'b0; // wire with initial value of 0 wand w3; // a scalar net of type wand tri [15:0] busa; // a three-state 16-bit bus Ver1.0 (2008) 49

net 자료형 q wired net v 다중구동자를갖는설계를지원하기위해사용 wand, triand net 의진리표 wand/ triand 0 1 x z 0 0 0 0 0 1 0 1 x 1 x 0 x x x z 0 1 x z wor, trior net 의진리표 wor/ trior 0 1 x z 0 0 1 x 0 1 1 1 1 1 x x 1 x x z 0 1 x z Ver1.0 (2008) 50

net 자료형 // code 1.5.2-1 : wand_test.v module wand_test(a, b, y); input a, b; output y; wand y; assign y = a; assign y = b; endmodule //code 1.5.2-2 : wor_test.v module wor_test(a, b, y); input a, b; output y; wor y; assign y = a; assign y = b; endmodule Ver1.0 (2008) 51

net 자료형 // code 1.5.2-3 : TB_net1.v `timescale 1ns/1ps module TB_net1; wire wand_y, wor_y; reg a, b; wand_test U1 (.a(a),.b(b),.y(wand_y) ); wor_test U2 (.a(a),.b(b),.y(wor_y) ); initial begin a=0; b=0; #200; a=0; b=1; #200; a=1; b=0; #200; a=1; b=1; #200; end endmodule Ver1.0 (2008) 52

벡터 v 범위지정 [msb:lsb] 을갖는다중비트의 net 또는 reg 자료형 v signed로선언되거나 signed로선언된포트에연결되는경우를제외하고는 unsigned로취급 v 단일할당문으로값을받을수있음 data_type [msb:lsb] identifier; reg [7:0] rega; // 8-bit reg wire [15:0] d_out; // 16-bit wire Ver1.0 (2008) 53

배열 v 별도의자료형이없으며, reg 또는 wire 선언을이용하여선언 v 배열전체또는일부분은단일할당문에의해값을할당받을수없으며, 또한수식에사용될수없음 Ø 배열을구성하는 element 만단일할당문으로값을할당받을수있음 v RAM, ROM, Register File 등의메모리모델링에사용 2차원배열 data_type identifier [Uaddr:Laddr][Uaddr2:Laddr2]; 벡터의 2 차원배열 data_type [msb:lsb] identifier [Uaddr:Laddr][Uaddr2:Laddr2]; Ver1.0 (2008) 54

배열 예 : 배열선언 reg [7:0] mema[0:255]; // a memory mema of 256 8-bit registers reg arrayb[7:0][0:255]; // a 2-D array of 1-bit registers wire w_array[7:0][5:0]; // an array of wires integer inta[1:64]; // an array of 64 integer values time chng_hist[1:1000]; // an array of 1000 time values 예 : 배열요소에의한할당 mema = 0; // Illegal syntax- Attempt to write to entire array arrayb[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 mema arrayb[1][0] = 0; // Assigns 0 to the bit referenced by indices [1][0] inta[4] = 33559; // Assign decimal number to integer in array chng_hist[t_index] = $time; // Assign current simulation time to // element addressed by integer index Ver1.0 (2008) 55

배열 q 메모리 v reg형요소를갖는 1차원배열 v 메모리전체가단일할당문으로값을할당받을수없음 Ø 인덱스로지정되는워드단위로만값을할당하거나수식에사용될수있음 예 : 메모리 reg [1:n] rega; reg mema [1:n]; // An n-bit register // A memory of n 1-bit registers Ver1.0 (2008) 56

parameter v variable 또는 net 범주에속하지않는상수값 v 회로의비트크기또는지연값을지정하기위해사용 v defparam 문또는모듈인스턴스문의 parameter overriding에의해값을변경시킬수있음 v 자료형과범위지정을가질수있음 Ø 범위가지정되지않은경우, 상수값에적합한크기의비트폭을 default로가짐 예 : parameter 선언 parameter msb = 7; // defines msb as a constant value 7 parameter e = 25, f = 9; // defines two constant numbers parameter r = 5.7; // declares r as a real parameter parameter byte_size = 8, byte_mask = byte_size - 1; 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 parameter newconst = 3'h4; // implied range of [2:0] Ver1.0 (2008) 57

parameter module modxnor (y_out, a, b); 모듈인스턴스의 parameter overriding parameter size=8, delay=15; output [size-1:0] y_out; input [size-1:0] a, b; wire [size-1:0] #delay y_out= a ~^ b; // bit-wise XNOR with delay endmodule module Param; wire [7:0] y1_out; wire [3:0] y2_out; reg [7:0] b1, c1; reg [3:0] b2, c2; modxnor G1 (y1_out, b1, c1); // use default parameters modxnor #(4, 5) G2 (y2_out, b2, c2); // overrides default parameters endmodule // Primitive instantiation with 3 units of delay nand #3 G1 (out_nd2, in0, in1); primitive gate 의 delay Ver1.0 (2008) 58

1.6 연산자 (Operator) Ver1.0 (2008) 59

Verilog 의연산자 Verilog HDL의연산자 연산자 기능 연산자 기능 {}, {{}} 결합, 반복 ^ 비트단위 exclusive or +, -, *, /, ** 산술 ^~ 또는 ~^ 비트단위 xnor % 나머지 & 축약 (reduction) and >, >=, <, <= 관계 ~& 축약 nand! 논리부정 축약 or && 논리 and ~ 축약 nor 논리 or ^ 축약 xor == 논리등가 ^~ 또는 ~^ 축약 xnor!= 논리부등 << 논리왼쪽시프트 === case 등가 >> 논리오른쪽시프트!== case 부등 <<< 산술왼쪽시프트 ~ 비트단위부정 >>> 산술오른쪽시프트 & 비트단위 and? : 조건 비트단위 or or Event or Ver1.0 (2008) 60

Verilog 의연산자 Verilog 연산자의우선순위 +, -,!, ~ ( 단항 ) Highest precedence ** *, /, % +, -( 이항 ) <<, >>, <<<, >>> <, <=, >, >= ==,!=, ===,!== &, ~& ^, ^~, ~^, ~ &&? : (conditional operator) Lowest precedence Ver1.0 (2008) 61

연산자 실수형수식에사용될수있는연산자 연산자 기능 연산자 기능 +, -, *, /, ** 산술 논리 or +, - 부호 == 논리등가 >, >=, <, <= 관계!= 논리부등! 논리부정? : 조건 && 논리 and or Event or Ver1.0 (2008) 62

산술연산자 v 피연산자의비트에 x 나 z 가포함된경우, 전체결과값은 x v 나누기와나머지연산자에서두번째피연산자가 0인경우, 결과값은 x v 나머지연산자의결과값은첫번째피연산자의부호를따름 v 거듭제곱연산자에서다음의경우에는결과값이정의되지않음 Ø 첫번째피연산자가 0이고두번째피연산자가양수가아닌경우 Ø 첫번째피연산자가음수이고두번째피연산자가정수값이아닌경우 기호기능 + 더하기 - 빼기 * 곱하기 / 나누기 ( 몫 ) % 나머지 (modulo) ** 거듭제곱 (power) 오퍼랜드자료형 unsigned net signed net unsigned reg signed reg integer time real, realtime 해석 Unsigned Signed, 2 s complement Unsigned Signed, 2 s complement Signed, 2 s complement Unsigned Signed, floating-point Ver1.0 (2008) 63

산술연산자사용예 -d10 / 5 // (10의 2의보수 )/5 = (2 32-10)/5 5 / 0 // 5/0 = x (-7) % (+4) = -3 // 나머지, 왼쪽오퍼랜드의부호를따른다. (+7) % (-2) = +1 // 정수, 레지스터연산예 integer inta; reg [15:0] rega; reg signed [15:0] regs; inta = -4'd12; rega = inta / 3; // -4, inta는 integer, rega는 65532 rega = -4'd12; // rega는 65524 inta = rega / 3; // 21841 inta = -4'd12 / 3; // 1431655761, -4d'12= 2 32-12 rega = -12 / 3; // -4, -12는 integer 자료형, rega는 65532 regs = -12 / 3; // -4, regs 는 signed reg regs = -4'sd12 / 3; // 1, -4'sd12 는 4 이므로 4/3=1 Ver1.0 (2008) 64

관계연산자 v 산술연산자보다낮은우선순위를가짐 v 피연산자의비트에 x 나 z가포함된경우, 결과값은 1비트의 x v 두피연산자의비트수가다른경우에는, 비트수가작은피연산자의 MSB 쪽에 0이채워져비트수가큰피연산자에맞추어진후, 관계를판단함 v 피연산자중하나가실수형이면다른피연산자가실수형으로변환된후, 비교됨 관계연산자 관계연산자식의미 a < b a > b a <= b a >= b a가 b보다작다 a가 b보다크다 a가 b보다작거나같다 a가 b보다크거나같다 Ver1.0 (2008) 65

관계연산자 예 : 관계연산자수식 // A = 9, B = 4 // D = 4'b1001, E = 4'b1100, F = 4'b1xxx A <= B // 결과값은거짓 (0) A > B // 결과값은참 (1) E >= D // 결과값은참 (1) E < F // 결과값은 x l a < b-1 2 a <(b-1) 3 b-(1 < a) 4 b-1 < a // l 과 2 는결과가동일 // 3 과 4 는결과가다를수있음 Ver1.0 (2008) 66

등가연산자 v 관계연산자보다낮은우선순위를가짐 v 피연산자의비트끼리비교 v 두피연산자의비트수가다른경우에는, 비트수가작은피연산자의 MSB 쪽에 0이채워져비트수가큰피연산자에맞추어진후, 등가를판단함 v case equality와 case inequality 연산자 (===,!==) 는대부분의 EDA 툴에서논리합성이지원되지않으므로, 합성을위한 RTL 수준의모델링에는사용하지않는것이좋음등가연산자 관계연산자식 의 미 a === b a와 b는같다. (x와 z가포함된일치를판단 ) a!== b a와 b는같지않다. (x와 z가포함된불일치를판단 ) a == b a와 b는같다. ( 결과가 x가될수있음 ) a!= b a와 b는같지않다. ( 결과가 x가될수있음 ) Ver1.0 (2008) 67

등가연산자 예 : 등가연산자 // 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 // 결과값은 x F === G // 결과값은참 (1) F === H // 결과값은거짓 (0) G!== H // 결과값은참 (1) Ver1.0 (2008) 68

논리연산자 v 참또는거짓의판단이모호한경우에는결과값은 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 // 결과값은 0 A B // 결과값은 1!A // 결과값은 0!B // 결과값은 1 C && D // 결과값은 x // 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) 69

비트연산자 v 피연산자의해당비트들에대한연산을수행 v 피연산자의비트수가같지않으면, 비트수가작은피연산자의 MSB 위치에 0이채워진후, 연산됨 비트 and 연산자 비트 or 연산자 비트부정연산자 & 0 1 x z 0 1 x z ~ 0 0 0 0 0 0 0 0 1 x x 0 1 1 0 1 x x 1 1 1 1 1 1 0 x 0 x x x x x 1 x x x x z 0 x x x z x 1 x x z x 비트 xor 연산자 ^ 0 1 x z 0 0 1 x x 1 1 0 x x x x x x x z x x x x //D = 4'b1001, E = 4'b1101, F = 4'b10x1 ~D // 결과값은 4'b0110 D & E // 결과값은 4'b1001 D E // 결과값은 4'b1101 D ^ E // 결과값은 4'b0100 D ~^ E // 결과값은 4'b1011 D & F // 결과값은 4'b10x1 Ver1.0 (2008) 70

축약 (reduction) 연산자 v 단항연산자, 피연산자의단위비트들에적용되어단일비트의결과값생성 축약 and & 0 1 x z 0 0 0 0 0 1 0 1 x x x 0 x x x z 0 x x x 연산자 피연산자 축약 nand ~& 0 1 x z 0 1 1 1 1 1 1 0 x x x 1 x x x z 1 x x x 연산결과 & ~& ~ ^ ~^ 축약 xnor ~^ 0 1 x z 0 1 0 x x 1 0 1 x x x x x x x z x x x x 설명 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 의개수가홀수인경우 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]; Ver1.0 (2008) 71

시프트연산자 q 논리시프트연산자 ( <<, >> ) v << : 우측피연산자값만큼좌측으로시프트후, 비어있는비트에 0을채움 v >> : 우측피연산자값만큼우측으로시프트후, 비어있는비트에 0을채움 q 산술시프트연산자 ( >>>, <<< ) v <<< : 우측피연산자값만큼좌측으로시프트후, 비어있는비트에 0을채움 v >>> : 우측피연산자값만큼우측으로시프트후, 비어있는비트에좌측피연산자의 MSB를채움 q 우측피연산자 v x 또는 z가포함된경우, 시프트연산의결과값은 x v 항상 unsigned 수 Ver1.0 (2008) 72

시프트연산자 // A = 4'b1100 B = A >> 1 // 오른쪽으로 1비트시프트, 결과값은 B=4'b0110 C = A << 1 // 왼쪽으로 1비트시프트, 결과값은 B=4'b1000 D = A << 2 // 왼쪽으로 2비트시프트, 결과값은 B=4'b0000 module shift; reg [3:0] start, result; initial begin start = 1; result =(start << 2); // 결과값은 0100 end endmodule module ashift; reg signed [3:0] start, result; initial begin start = 4'b1000; result =(start >>> 2); // 결과값은 1110 end endmodule Ver1.0 (2008) 73

조건연산자 conditional_expr ::= expr1? expr2 : expr3 v expr1이참 (1, 즉 0, x 또는 z가아닌값 ) 으로평가되면 expr2의값이좌변변수에할당 v expr1이 x 또는 z이면, expr2와 expr3을함께평가하여비트단위로비교된값이 좌변의변수에할당 Ø expr3이 real 형값이아니면결과값은비트단위로비교되어결정되며, real 형 값인경우에는결과값은 0이됨 조건에애매성이존재하는경우의조건연산자의결과값결정? : 0 1 x z 0 0 x x x 1 x 1 x x x x x x x z x x x x 조건연산자를이용한 3상태버퍼 wire [15:0] busa = drive_busa? data : 16'bz; Ver1.0 (2008) 74

결합연산자 v 중괄호 { } 에의해묶인두개이상의표현이갖는비트들을결합 Ø 결합되는피연산자들은각각의크기를결정할수있어야결합이가능 Ø unsized 상수는결합연산자로결합시킬수없음 v 대입문의좌측또는우측에사용가능 v 비트폭이일치하지않는변수의연산이나대입이허용됨 Ø 우변의비트폭이작은경우, 우변의 MSB 에 0 을붙여연산됨 Ø 좌변의비트폭이우변보다작을경우, MSB 는누락되어저장 {a, b[3:0], w, 3'b101} // 결합연산자의결과 {a, b[3], b[2], b[1], b[0], w, 1'b1, 1'b0, 1'b1} wire [15:0] addr_bus; assign addr_bus = {addr_hi, addr_lo}; // addr_hi, addr_lo 는 8 비트신호 wire [3:0] a, b, sum; wire carry; assign {carry, sum} = a + b; // 4비트데이터의덧셈은 5비트결과 // 좌변이 5 비트이므로, 우변의 a+b는 MSB에 0을붙인 5비트로연산됨 Ver1.0 (2008) 75

반복연산자 v {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'bz} 가되므로잘못된표현임. a[31:0] = {1'b1, {1'bx{1'b0}} }; // 우변이 {1'bx} 가되므로잘못된표현임. result = {func(w), func(w), func(w), func(w)}; // 반복함수호출 // 위문자은다음과같다. y=func(w); result = {y,y,y,y}; // 혹은, 다음과도같다. result = {4{func(w)}}; {b, {3{a, b}}} // {b, a, b, a, b, a, b} 와동일함. Ver1.0 (2008) 76