Verilog Language Concepts

Similar documents
ECE Digital System Design & Synthesis Exercise 1 - Logic Values, Data Types & Operators - With Answers

14:332:231 DIGITAL LOGIC DESIGN. Hardware Description Languages

Schematic design. Gate level design. 0 EDA (Electronic Design Assistance) 0 Classical design. 0 Computer based language

Verilog HDL Introduction

P-1/74. Samir Palnitkar. Prentice-Hall, Inc. INSTRUCTOR : CHING-LUNG SU.

Verilog Design Principles

Online Verilog Resources

Verilog Design Principles

CSE140L: Components and Design Techniques for Digital Systems Lab

CSE140L: Components and Design

Synthesis vs. Compilation Descriptions mapped to hardware Verilog design patterns for best synthesis. Spring 2007 Lec #8 -- HW Synthesis 1

Contents. Appendix D Verilog Summary Page 1 of 16

EEL 4783: HDL in Digital System Design

Logic Synthesis. EECS150 - Digital Design Lecture 6 - Synthesis

EECS150 - Digital Design Lecture 10 Logic Synthesis

Introduction. Why Use HDL? Simulation output. Explanation

Course Topics - Outline

FPGA: FIELD PROGRAMMABLE GATE ARRAY Verilog: a hardware description language. Reference: [1]

Department of Computer Science and Electrical Engineering. Intro to Verilog II

Computer Aided Design Basic Syntax Gate Level Modeling Behavioral Modeling. Verilog

Synthesis of Language Constructs. 5/10/04 & 5/13/04 Hardware Description Languages and Synthesis

Spring 2017 EE 3613: Computer Organization Chapter 5: Processor: Datapath & Control - 2 Verilog Tutorial

A Verilog Primer. An Overview of Verilog for Digital Design and Simulation

EECS 427 Lecture 14: Verilog HDL Reading: Many handouts/references. EECS 427 W07 Lecture 14 1

Programmable Logic Devices Verilog VII CMPE 415

LANGUAGE CONSTRUCTS AND CONVENTIONS IN VERILOG

Introduction. Purpose. Intended Audience. Conventions. Close

CSE241 VLSI Digital Circuits Winter Recitation 1: RTL Coding in Verilog

Verilog. Like VHDL, Verilog HDL is like a programming language but:

EECS150 - Digital Design Lecture 10 Logic Synthesis

Verilog HDL. A Guide to Digital Design and Synthesis. Samir Palnitkar. SunSoft Press A Prentice Hall Title

Lecture #2: Verilog HDL

Introduction to Digital VLSI Design מבוא לתכנון VLSI ספרתי

Combinational Logic II

Verilog. What is Verilog? VHDL vs. Verilog. Hardware description language: Two major languages. Many EDA tools support HDL-based design

Lecture 2: Data Types, Modeling Combinational Logic in Verilog HDL. Variables and Logic Value Set. Data Types. Why use an HDL?

Chapter 3: Dataflow Modeling

ECEN 468 Advanced Logic Design

CSE140L: Components and Design Techniques for Digital Systems Lab. Verilog HDL. Instructor: Mohsen Imani UC San Diego. Source: Eric Crabill, Xilinx

Chap 6 - Introduction to HDL (b)

register:a group of binary cells suitable for holding binary information flip-flops + gates

Hardware Description Language (HDL)

Design Using Verilog

This Lecture. Some components (useful for the homework) Verilog HDL (will continue next lecture)

VERILOG 2: LANGUAGE BASICS

Extending SystemVerilog Data Types to Nets

Verilog Dataflow Modeling

GEETHANJALI COLLEGE OF ENGINEERING AND TECHNOLOGY. DEPARTMENT OF Electronics and communications Engineering

Chap 3. Modeling structure & basic concept of Verilog HDL

Speaker: Shao-Wei Feng Adviser: Prof. An-Yeu Wu Date: 2010/09/28

ENGIN 241 Digital Systems with Lab

Speaker: Kayting Adviser: Prof. An-Yeu Wu Date: 2009/11/23

Verilog Coding Guideline

RIZALAFANDE CHE ISMAIL TKT. 3, BLOK A, PPK MIKRO-e KOMPLEKS PENGAJIAN KUKUM. SYNTHESIS OF COMBINATIONAL LOGIC (Chapter 8)

Microcomputers. Outline. Number Systems and Digital Logic Review

Chapter 4 :: Topics. Introduction. SystemVerilog. Hardware description language (HDL): allows designer to specify logic function only.

Introduction To Verilog Design. Chun-Hung Chou

Lexical Considerations

Course Topics - Outline

Index. A a (atto) 154 above event 120, 207 restrictions 178

ADVANCED DIGITAL IC DESIGN. Verilog Simulation Techniques (I)

Verilog introduction. Embedded and Ambient Systems Lab

N-input EX-NOR gate. N-output inverter. N-input NOR gate

In this lecture, we will go beyond the basic Verilog syntax and examine how flipflops and other clocked circuits are specified.

Advanced Digital Design with the Verilog HDL

Chapter 2 Using Hardware Description Language Verilog. Overview

ECE 4514 Digital Design II. Spring Lecture 7: Dataflow Modeling

EDIABAS BEST/2 LANGUAGE DESCRIPTION. VERSION 6b. Electronic Diagnostic Basic System EDIABAS - BEST/2 LANGUAGE DESCRIPTION

EN2911X: Reconfigurable Computing Topic 02: Hardware Definition Languages

Introduction to Verilog/System Verilog

A Brief Introduction to Verilog Hardware Definition Language (HDL)

Graduate Institute of Electronics Engineering, NTU. Lecturer: Chihhao Chao Date:

Introduction to VHDL #1

Verilog-A/MS is a case sensitive language. Spaces, tabs, and newlines are considered white space and are ignored except when found in strings.

EN2911X: Reconfigurable Computing Lecture 05: Verilog (2)

St.MARTIN S ENGINEERING COLLEGE Dhulapally, Secunderabad

CS232 VHDL Lecture. Types

Lecture 32: SystemVerilog

ESE 570 Cadence Lab Assignment 1: Logic Simulation in Verilog-XL

EN164: Design of Computing Systems Lecture 06: Lab Foundations / Verilog 2

Extending SystemVerilog Data Types to Nets

a, b sum module add32 sum vector bus sum[31:0] sum[0] sum[31]. sum[7:0] sum sum overflow module add32_carry assign

FPGA Design Challenge :Techkriti 14 Digital Design using Verilog Part 1

INSTITUTE OF AERONAUTICAL ENGINEERING Dundigal, Hyderabad ELECTRONICS AND COMMUNICATIONS ENGINEERING

Chapter-5. EE 335 : Advanced Microprocessor. Logic Design with Behavioral Models of Combinational and Sequential Logic

Verilog Module 1 Introduction and Combinational Logic

Hardware description language (HDL)

1 Lexical Considerations

Verilog Tutorial. Introduction. T. A.: Hsueh-Yi Lin. 2008/3/12 VLSI Digital Signal Processing 2

A Fast Review of C Essentials Part I

IP Core Design. Lecture 6 Introduction to Verilog-2001

Digital Design with FPGAs. By Neeraj Kulkarni

Introduction to Verilog. Garrison W. Greenwood, Ph.D, P.E.

Verilog. Verilog for Synthesis

Spiral 1 / Unit 4 Verilog HDL. Digital Circuit Design Steps. Digital Circuit Design OVERVIEW. Mark Redekopp. Description. Verification.

HDLs and SystemVerilog. Digital Computer Design

MLR Institute of Technology

Lab 7 (All Sections) Prelab: Introduction to Verilog

Digital Design (VIMIAA01) Introduction to the Verilog HDL

Verilog Tutorial - Edited for CS141

Transcription:

Verilog Language Concepts Adapted from Z. Navabi Portions Copyright Z. Navabi, 2006 1 Verilog Language Concepts Characterizing Hardware Languages Timing Concurrency Timing and concurrency example Module Basics Code format Logic value system Wires and variables Modules Module ports Names Numbers 2 1

Verilog Language Concepts Module Basics (cont.) Arrays Verilog operators Verilog data types Array indexing Verilog Simulation Model Continuous assignments Procedural assignments 3 Verilog Language Concepts Compiler Directives timescale default-nettype include define ifdef, else, else, endifendif unconnected-drive celldefine, endcelldefine resetall 4 2

Verilog Language Concepts System Tasks and Functions Display tasks File I/O tasks Timescale tasks Simulation control tasks Timing check tasks PLA modeling tasks Conversion functions for reals Other tasks and functions Summary 5 Characterizing Hardware Languages Timing and concurrency are the main characteristics of hardware description languages. Timing is associated with values that are assigned to hardware carriers. Concurrency refers to simultaneous operation of various hardware components. 6 3

Characterizing Hardware Languages Characterizing Hardware Languages Timing Concurrency Timing & Concurrency Example 7 Timing Characterizing Hardware Languages Timing Concurrency Timing & Concurrency Example 8 4

Timing Transfer of data is done through wires or busses and some of delays are associated with transfer of data through wires. Variables in Verilog may be used for representation of wires and variable assignments can include timing specification. 9 Timing An assign A statement sharp-sign (#) A more accurate assignment: drives the followed signal on by the a number left-hand specifies side of the the delay of equal sign the Because left hand side assign #6 n = ~b; In with this the signal. simple of the 6 ns boolean The circuit can assign be written #3 like m this: = a & b; assignment expression delay of inverter on Glitches in its second path from b assign #3 p = n & c; that right. may appear on w due to w to a 6 different ns glitch assign #2 w2 = m p; assign w1 = a & b c & ~b; delay appears paths from on w. b to w are not considered. a b T d = 6 ns Td = 3ns T d = 3ns m T d =2ns w c n p An AND-OR Circuit 10 5

Timing When b changes from 1 to 0 the final value of w remains at 1. However, because of the inverter delay in forwarding a 1 to the output, a 6 ns glitch appears on w. w1,, which is the result of the single assign Output Glitch statement, does not show the delay w2 shows both propagation delays and glitches that may occur on the w output of circuit 11 Concurrency Characterizing Hardware Languages Timing Concurrency Timing & Concurrency Example 12 6

Concurrency Concurrency is an essential feature of any language for description of hardware. Functionality of a hardware system is described by concurrent sub- components or by a program in a sequential manner. By using concurrent sub-components Verilog simulator makes us think that simulation of components is being done concurrently. 13 a b c T d = 6 ns An AND-OR Circuit Concurrency assign #6 n = ~b; assign #3 m = a & b; assign #3 p = n & c; assign #2 w2 = m p; n T d = 3ns T d = 3ns m p Regarded The gates as concurrent. are The concurrently order in which active. these We statements cannot decide appear on in a concurrent pre-determined body of order Verilog in which is gates not important. of this circuit perform their operations. T d =2ns w 14 7

Timing & Concurrency Example Characterizing Hardware Languages Timing Concurrency Timing & Concurrency Example 15 Timing & Concurrency Example `timescale 1ns/100ps Module header declares inputs and outputs of circuit. module FullAdder (input a, b, ci, output co, s); assign #4 co = a & b a & ci b & ci; assign #3 s = a ^ b ^ ci; endmodule Because of the delay The two values, assign statements drive s Full Adder Propagation Concurrent Delay if an input change causes Description (sum) and co (carry- of Assignment both outputs to change, s changes before out) outputs co does. of circuit. 16 8

Timing & Concurrency Example `timescale 1ns/100ps module FullAdderTester; Declaration and reg a = 0, b = 0, ci = 0; initialization of variables, wires, wire co, s; and constants parameter tlimit = 500; FullAdder MUT (a, b, ci,, co, s);... Instantiation statement... to instantiate the full adder that is the module Fulladder Tester Procedural Description under test 17 A concurrent structure on the outside, but has a procedural body. Checks the simulation always begin time and if it exceeds if ($time >= tlimit) $stop; tlimit it stops the simulation. else begin #17; After a wait of 17ns input a is complemented a = ~a; #13; ci = ~ci~ ci; Applies test data to #19; the ports of the circuit being tested. b = ~b; end end endmodule Timing & Concurrency Example Fulladder Tester Procedural Description (Continued) 18 9

Module Basics Now we are going to see: How modules are developed How names, numbers and operators are used 19 Module Basics Module Basics Code Format Logic Value System Wires and Variables Modules Module Ports Names Numbers Arrays Verilog Verilog Data Types Array Indexing 20 10

Code Format Module Basics Code Format Logic Value System Wires and Variables Modules Module Ports Names Numbers Arrays Verilog Verilog Data Types Array Indexing 21 Code Format Verilog code is free format. Spaces and new lines are served as separators. It is case sensitive. Language keywords use lowercase characters. A comment designator start with // makes the rest of line comment. The symbols /* */ bracket the section of code which is in between as a comment. 22 11

Logic Value System Module Basics Code Format Logic Value System Wires and Variables Modules Module Ports Names Numbers Arrays Verilog Verilog Data Types Array Indexing 23 Logic Value System Bit type, or bits of vectors or arrays, of Verilog wires and variables take the 4-value logic value system. Values in this system are 0, 1, Z and X. The values 0 and 1 have Three modes: Forcing, Resistive and Capacitive. The Z value represents an undriven,, high impedance value. The X value represent a conflict in multiple driving values, an unknown or value of a variable not initialized. 24 12

Logic Value System 0 : 0 X 0 1 : 1 x 1 X or x : 0 1 X 1 0 Z or z : 1 0 z Logic Values and Examples 25 Wires and Variables Module Basics Code Format Logic Value System Wires and Variables Modules Module Ports Names Numbers Arrays Verilog Verilog Data Types Array Indexing 26 13

Wires and Variables Wires and Variables: net: : represents a wire driven by a hardware structure or output of a gate. reg: : represents a variable that can be assigned values in behavior description of a component in a Verilog procedural block. 27 Modules Module Basics Code Format Logic Value System Wires and Variables Modules Module Ports Names Numbers Arrays Verilog Verilog Data Types Array Indexing 28 14

Modules Module is the main structure of definition of hardware components and testbenchs. Begins with module keyword and end with endmodule. Immediately following the module keyword, port list of the module appears enclosed in parenthesis. 29 Modules `timescale 1ns/100ps module FlipFlop (preset, reset, din, clk, qout); input preset, reset, din, clk; Ports are only listed in the output qout; port list and declared as reg qout; separate input and output ports inside the body of always @ (posedge( clk) begin the Flip-Flop module. if (reset) qout <= #7 0; else if (preset) qout <= #7 1; else qout <= #8 din; end endmodule Separate Port Declarations Statements 30 15

Module Ports Module Basics Code Format Logic Value System Wires and Variables Modules Module Ports Names Numbers Arrays Verilog Verilog Data Types Array Indexing 31 Module Ports Inputs and outputs of a model must be declared as: input output inout By default, all declared ports are regarded as nets s and the default net type is used for the ports. Ports declared as output may be declared as reg. This way they can be assigned values in procedural blocks. An inout port can be used only as a net.. To assign values to an inout port in procedural bodies, a reg corresponding to the port must be declared and used. For an output, a reg specification can follow the output keyword in the port list of the module. 32 16

Names Module Basics Code Format Logic Value System Wires and Variables Modules Module Ports Names Numbers Arrays Verilog Verilog Data Types Array Indexing 33 Names A stream of characters starting with a letter or an underscore forms a Verilog identifier. The $ character and underscore are allowed in an identifier. Verilog uses keywords that are all formed by streams of lowercase characters. The names of system tasks and functions begin with a $ character. Compiler directive names are preceded by the ` (back single quote) character. Example: `timescale 34 17

Names The following are valid names for identifiers: a_name, name1, _name, Name, Name$, name55, _55name, setup, _$name. The following are Verilog keywords or system tasks. $display, default, $setup, begin, tri1, small. 35 Numbers Module Basics Code Format Logic Value System Wires and Variables Modules Module Ports Names Numbers Arrays Verilog Verilog Data Types Array Indexing 36 18

Numbers Constants in Verilog are integer or real. Specification of integers can include X and Z in addition to the standard 0 and 1 logic values. Integers may be Sized: Begins with the number of equivalent bits Unsized: Without the number of bits specification The general format for a sized integers is: number_of_bits base_identifier digits example: 6 b1011006 The base specifier is a single lower or uppercase character b, d, o or h which respectively stand for binary, decimal, octal and hexadecimal bases. 37 Numbers Optionally, the base-identifier can be preceded by the single character s (or S) ) to indicate a signed quantity. A plus or minus operator can be used on the left of the number specification to change the sign of the number. The underscore character (_) can be used anywhere in a number for grouping its bits or digits for readability purposes. Real constants in Verilog use the standard format as described by IEEE std 754-1985, the IEEE standard for double precision floating- point numbers. Examples: 1.9, 2.6E9, 0.1e-6, 315.96-12. 38 19

Numbers Number Representation Examples Number representation Binary Equivalent Explanation 4 d5 101 Decimal 5 is interpreted as a 4-bit number. number. 4 d5 101 Decimal 5 is interpreted as a 4-bit number. 8 b101 101 101 Binary 101 is turned Binary 101 into is turned an into 8-bit an 8-bit number. 12 h5b_3 10110110011 Binary Binary equivalent equivalent of hex; underscore of hex; is ignored. This is 2 s of the number in the -8 b101 11111011 This is underscore the 2 scomplement is ignored. of the above example. 10 o752 0111101010 This number is the octal in the 752 above with example. a 0 padded 10 o752 111101010to itself to make it a 10-bit number. This is the octal 752 with a 0 padded to its left to make it a 10-bit number. 8 hf 00001111 Hexadecimal F is expanded to 8 hf 1111 8 bits by padding zeros to its left. 12 hxa xxxxxxxx1010 Hexadecimal XA is expanded to 12 hxa xxxxxxxx1010 12 bits by extending the left x. 12 sha6 Signed 111110100110 Signed This is This an is 8-bit an 8-bit number treated treated as a 2 s 12 sha6 as 111110100110 complement signed number. -4 sha Signed 0110 The a 2 s complement signed (because number. of the Hexadecimal F is expanded to 8 bits by padding zeros to its left. Hexadecimal XA is expanded to 12 bits by extending the left X. The 2 s complement (because of the minus sign) -4 sha Signed 0110 minus sign) 4-bit 4-bit A is regarded A is regarded as a signed number. as a 596 596 1001010100 This This a is a positive constant. signed number. 39 Numbers `timescale 1ns/100ps Display Results Variables a through l are $displayb declared tasks and initialized. display the binary values. module NumberTest; reg [11:0] a = 8'shA6; initial $displayb ("a=", a); // a=111110100110 reg [11:0] b = 8'sh6A; initial $displayb ("b=", b); // b=000001101010 reg [11:0] c = 'sha6; initial $displayb ("c=", c); // c=000010100110 reg [11:0] d = 'sh6a; initial $displayb ("d=", d); // d=000001101010 reg [11:0] e = -8'shA6;initial $displayb ("e=", e); // e=000001011010... Integer Constants 40 20

Numbers... reg [11:0] f = -'sha6; initial $displayb ("f=", f); // f=111101011010 reg [11:0] g = 9'shA6; initial $displayb ("g=", g); // g=000010100110 reg [11:0] h = 9'sh6A; initial $displayb ("h=", h); // h=000001101010 reg [11:0] i = -9'shA6;initial $displayb ("i=", i); // i=111101011010 reg [11:0] j = -9'sh6A;initial $displayb ("j=", j); // j=111110010110 reg [11:0] k = 596; initial $displayb ("k=", k); // k=001001010100 reg [11:0] l = -596; initial $displayb ("l=", l); // l=110110101100 endmodule Integer Constants (Continued) 41 Arrays Module Basics Code Format Logic Value System Wires and Variables Modules Module Ports Names Numbers Arrays Verilog Verilog Data Types Array Indexing 42 21

Arrays Verilog allows declaration and usage of multidimensional arrays for nets s or regs. The following declares a_array as a two-dimensional array of 8-bit words: reg [7:0] a_array [0:1023][0:511]; In an array declaration, the address range of the elements of the array comes after the name of the array. Range specifications are enclosed in square brackets. The size and range specification of the elements of an array come after the net type (e.g., wire) ) or reg keyword. In the absence of a range specification before the name of the array, an element size of one bit is assumed. 43 Arrays // An 8-bit vector reg [7:0] Areg; Areg 7 0 7 // A memory of 8 one -bit elements reg Amem [7:0]; Amem Array StructuresS 0 44 22

Arrays 7 // A two-dimensional memory of one -bit elements reg Bmem [7:0] [0:3]; Bmem 0 // A memory of four 8-bit words reg [7:0] Cmem [0:3]; Cmem 0 7 Array StructuresS (Continued) 3 45 Arrays // A two-dimensional memory of 3-bit elements reg [2:0] Dmem [0:3] [0:4]; 0 Dmem 3 0 1 2 3 4 Array StructuresS 46 23

Verilog Module Basics Code Format Logic Value System Wires and Variables Modules Module Ports Names Numbers Arrays Verilog Verilog Data Types Array Indexing 47 Verilog Basic OPERATION DESCRIPTION RESULT Arithmetic + - * /** Basic arithmetic Multi -bit Relational > > = < <= Basic Shift Equality OPERATION OPERATION compare One-bit DESCRIPTION DESCRIPTION RESULT RESULT Arithmetic Logical Right Equality One-bit! = not including Zero-fill Z, X + - * >>n / ** Basic arithmetic Equality Shift n places One-bit including Z, X Multi-bit Multi-bit Logical Case! Equality OPERATION DESCRIPTION RESULT Relational Boolean > >= < <= compare One-bit OPERATION DESCRIPTION RESULT == Zero-fill Equality Logical &&! Simple logic Logical Left One-bit <<n One-bit not including Z, X Multi-bit!= Shift n places Bit -wise ~ & ^ ^~ Vector logic One-bit operation Concat ~^ Boolean OPERATION DESCRIPTION RESULT OPERATION Reduction === DESCRIPTION & ~& ~ ^ Perform operation Equality One-bit RESULT ^~ ~^ on all bits Case One-bit Concatenation Arithmetic Right!=={ >>>n } including Join bits Z, X Multi-bit Multi-bit Shift OPERATION DESCRIPTION RESULT Logical &&! Simple logic One-bit Zero-fill Replication Condition OPERATION {{ }} Join DESCRIPTION & Replicate Logical Right >>n Shift n places Multi -bit Multi-bit RESULT Arithmetic Left <<<n Multi-bit Zero-fill Conditional Logical Left? : <<n If-then-else Multi -bit Shift n places Multi-bit Bit-wise ~ & ^ ^~ Vector logic One-bit Arithmetic Right >>>n Multi -bit operation ~^ Reduction Arithmetic Left Concat Concatenation Replication Condition Conditional <<<n & ~& ~ ^ { } ^~ ~^ OPERATION DESCRIPTION {{ }} Join & Replicate OPERATION DESCRIPTION? : If-then-else Multi -bit Perform operation RESULT Join bits on all bitsmulti -bit Multi -bit RESULT Multi -bit One-bit Verilog Operations 48 24

Verilog Verilog Basic Equality Boolean Shift Concatenation Conditional 49 Basic Verilog Basic Equality Boolean Shift Concatenation Conditional 50 25

Basic Arithmetic Operations in Verilog take bit, vector, integer and real operands. Basic operators of Verilog are +, -, *, / and **. An X or a Z value in a bit of either of the operands of a multiplication causes the entire result of the multiply operation to become X. Unary plus (+) and minus ( )( are allowed in Verilog. These operators take precedence over other arithmetic operators. If any of the operands of a relational operator contain an X or a Z,, then the result becomes X. 51 Example Basic Results in 25 * 8 b6 150 25 + 8 b7 32 25 / 8 b6 4 22 % 7 1 8'b10110011 > 8 b0011 1 4 b1011 < 10 0 4 b1z10 < 4 b1100 4 b1x10 < 4 b1100 4 b1x10 <= 4 b1x10 x x x Examples of Basic Operations 52 26

Equality Verilog Basic Equality Boolean Shift Concatenation Conditional 53 Equality Equality operators are categorized into two groups: Logical: Compare their operands for equality (==) or inequality (!=) Return a one-bit result, 0, 1,, or Z An X ambiguity arises when an X or a Z occurs in one of the operands. Case: Consider X and Z values in comparing their operands. The result is always 0 or 1. 54 27

Equality Example Results in 8 b10110011 == 8 b10110011 1 8 b1011 == 8 b00001011 1 4 b1100 == 4 b1z10 0 4 b1100!= 8 b100x 1 8 b1011!== 8 b00001011 0 8 b101x === 8 b101x 1 Examples of Equality Operations 55 Boolean Verilog Basic Equality Boolean Shift Concatenation Conditional 56 28

Boolean If an X or a Z appears in an operand of a logical operator, an X will result. The complement operator ~ results in 1 and 0 for 0 and 1 inputs and X for X and Z inputs. 57 Boolean If an X or a Z appears in an operand of a logical operator, an X will result. The complement operator ~ results in 1 and 0 for 0 and 1 inputs and X for X and Z inputs. & ^ 0 1 X Z ^~ 0 1 X Z 0 0 0 1 0 x 0 x 0 1 1 0 x x x x 0 1 1 1 x 1 x 1 1 0 0 1 x x x x 0 x x 1 x x x x x x x x x x x x 0 x x 1 x x x x 1 x x x x x x x Bit-by-bit Bitwise and Reduction 58 29

Boolean Complement reduction operations (~&( ~&, ~,, and ~^) ) perform reduction first and then complement the result. Example Results in 8 b01101110 && 4 b0 0 8 b01101110 4 b0 1 8 b01101110 && 8 b10010001 1! (8 b10010001) 1 8 b01101110 & 8 bxxzz1100 8 b0xx01100 8 b01101110 8 bxxzz1100 8'bx11x1110 ~& (4 b0xz1) 1 ~ (4 b0xz1) 0 Logical, Bit-wise, and Reduction 59 Shift Verilog Basic Equality Boolean Shift Concatenation Conditional 60 30

Shift Logical shift operators (>>( and << for shift right and left) fill the vacated bit positions with zeros. Fill values for arithmetic shift operators depend on the type of their results being signed or unsigned. Example Results in 8 b0110_0111 << 3 8 b0011_1000 8 b0110_0111 << 1 bz 8 bxxxx_xxxx Signed_LHS = 8 b1100_0000>>>2 8 b1111_0000 Shift 61 Concatenation Verilog Basic Equality Boolean Shift Concatenation Conditional 62 31

Concatenation The notation used for this operator is a pair of curly brackets ({...}( {...}) enclosing all scalars and vectors that are being concatenated. If a is a 4-bit reg and aa is a 6-bit reg, the following assignment places 1101 in a and 001001 in aa: {a, aa} } = 10 b1101001001 63 Concatenation If the a and aa registers have the values assigned to them above, and aaa is a 16-bit reg data type, then the assignment, aaa = {aa{ aa,, {2{a}}, 2 b11} 2 puts 001001_1101_1101_11 in aaa. {a, 2{b,c}, 3{d}} is equivalent to: {a, b, c, b, c, d, d, d} {2 b00, 3{2 01}, 2 b11} 2 results in: 10 b0001010111 64 32

Conditional Verilog Basic Equality Boolean Shift Concatenation Conditional 65 Conditional expression1? expression2 : expression3 assign a = (b == c)? 1 : 0; If expression1 is true, then expression2 is selected as the result of the operation; otherwise expression3 is selected. If expression1 is X or Z,, both expressions 2 and 3 will be evaluated, and the result becomes the bit-by-bit combination of these two expressions. 66 33

Conditional Example Results in 1? 4 b1100 : 4 b ZX0 4 b1100 0? 4 b1100 : 4 b1zx0 4 b1zx0 X? 4 b1100 : 4 b1zx0 4 b1xx0 Conditional 67 Precedence of + -! ~ * * * / % + - << >> <<< >>> < <= > >= ==! = ===!== & ~ & ^ ^~ ~^ ~ & & Highest Operator Precedence? : Lowest 68 34

Precedence of W & X + Y A & B && C + D + & + & && Precedence Examples 69 Verilog Data Types Module Basics Code Format Logic Value System Wires and Variables Modules Module Ports Names Numbers Arrays Verilog Verilog Data Types Array Indexing 70 35

Verilog Data Types Verilog Data Types Net Declarations Reg Declarations Signed Data Parameters 71 Net Declarations Verilog Data Types Net Declarations Reg Declarations Signed Data Parameters 72 36

Net Declarations Types wire and tri, wand and triand,, and wor and trior are equivalent. Types supply0 and supply1 are used for declaring signal names for supply voltages. The trireg net type declares three-state capacitive signals. Other net types (wire( wire, wand and wor or their equivalents, tri, triand and trior ) declare state signals that allow multiple driving sources. 73 Net Declarations This statement declares wires used between gates or Boolean expressions representing logic structures. wire w, n, m, p; By default, ports of a module are net of wire type. The Z value is the weakest and is overridden by non-z values from other driving sources. 74 37

Net Declarations Driving a wire with multiple 0 and 1 conflicting values resolves in the X value for the wire. The wand and wor type nets signify wired-and and wired-or functions, respectively. For wand type, a 0 value on a driving source overrides all other source values and value Z is treated as null and is overridden by any other value driving a wand net. In wor operation, logic value 1 on one source overrides all other source values. As in wand,, the Z value is the weakest and is overridden by 0, 1 and X values. 75 Net Declarations NET TYPES PROPERTIES INITIAL Supply Three-state supply0 supply1 wire (tri) wand (triand) wor (trior) Driven: 0 Driven: 1 Tri-state wired logic Wired-and logic Wired-or logic 0 1 Driven: X Not Driven: Z Driven: X Not Driven: Z Driven: X Not Driven: Z Capacitive trireg Hold old value X net Types and Properties 76 38

Net Declarations s1 s2 0 1 X Z 0 1 X Z 0 X X 0 X X 0 1 1 X 1 X X X X Z s1 s2 wire value wire net type 77 s1 s2 0 1 X Z 0 1 X Z 0 0 0 0 0 0 Net Declarations 0 1 1 X 1 X X X X Z s1 s2 wand value s1 s2 0 1 X Z 0 1 X Z 0 1 X 0 1 X 0 1 1 1 1 1 X X X Z s1 s2 wor value (a) wand net Types, (b) wor net Type 78 39

Net Declarations The trireg type net behaves as a capacitive wire and holds its old value when a new resolved value is to become Z. As long as there is at least one driver with 0, 1, or X value, trireg behaves the same as wire. When all drivers are turned off (Z), a trireg net retains its previous value. The amount of time a trireg net holds a value is specified by a delay parameter in its declaration. Delay parameters will be discussed next. Chapter 7 shows examples of using trireg for CMOS flip-flop modeling. 79 Net Declarations Three delay values for net switching to 1, to 0, and to Z are specified in a set of parenthesis that are followed by a # sign after the net type keyword. A simpler format contains a single delay value. wire #3 w, n, m, p; 80 40

Net Declarations trireg net types may also be declared with three delay parameters. Unlike the case with other nets, in this case the third timing parameter is not delay for the Z transition. Instead, this specifies the time that a declared trireg net holds an old value when driven by Z. The initial value for all net types except supply0 and supply1 with at least one driver is X. A net with no driver assumes the Z value, except for trireg,, which has the initial value X. 81 Reg Declarations Verilog Data Types Net Declarations Reg Declarations Signed Data Parameters 82 41

Reg Declarations reg is a variable for holding intermediate signal values or nonhardware parameters and function values. The reg declaration shown below declares a, b and ci as reg types with 0 initial values. reg a=0, b=0, ci=0; The default initial value of a declared reg is (X). 83 Reg Declarations Other reg types are integer and time. An integer declaration declares a signed 2s-complement number, and a time declaration declares an unsigned reg variable of at least 64 bits. Verilog also allows declaration of real and realtime variables. These variables are similar in use to integer and time variables, but do not have direct bit-to-bit correspondence with reg type registers. 84 42

Signed Data Verilog Data Types Net Declarations Reg Declarations Signed Data Parameters 85 Signed Data Verilog net and reg types can be declared as signed. In below example areg is declared as a signed reg. reg signed [15:0] areg; A signed reg that is shifted right by the >>> operator is sign filled, whereas an unsigned reg shifted by this operator is zero-filled. If the right-hand side of an assignment is determined as signed, it is sign extended to the size of its left hand side and is placed on the left hand side reg or net. 86 43

Parameters Verilog Data Types Net Declarations Reg Declarations Signed Data Parameters 87 Parameters Parameters in Verilog do not belong to either the variable or the net group. Parameters are constants and cannot be changed at runtime. Parameters can be declared as signed, real, integer, time or realtime. Example parameter p1=5, p2=6; parameter [4:0] p1=5, p2=6; parameter integer p1=5; parameter signed [4:0] p1=5; Explanation 32 bit parameters 5 bit parameters 32 bit parameters 5 bit signed parameters Parameter Examples 88 44

Array Indexing Module Basics Code Format Logic Value System Wires and Variables Modules Module Ports Names Numbers Arrays Verilog Verilog Data Types Array Indexing 89 Array Indexing Array Indexing Bit Selection Part Selection Standard Memory Multi Dimensional Memories 90 45

Bit Selection Array Indexing Bit Selection Part Selection Standard Memory Multi Dimensional Memories 91 Bit Selection Bit-select and part-select operators are used for extracting a bit or a group of bits from a declared array. reg [7:0] Areg; reg Amem [7:0]; reg Dmem [7:0][0:3]; reg [7:0] Cmem [0:3]; reg [2:0] Dmem [0:3][0:4]; Bit-selection is done by using the addressed bit number in a set of square brackets. For example Areg[5] selects bit 5 of the Areg array. 92 46

Part Selection Array Indexing Bit Selection Part Selection Standard Memory Multi Dimensional Memories 93 Part Selection Verilog allows constant and indexed part-select. For example, Areg[7:3] selects the upper five bits of Areg. Areg [5:3] //selects bits 5, 4 and 3 Areg [5-:4] //selects bits 5, 4, 3 and 2 Areg [2+:4] //selects bits 5, 4, 3 and 2 94 47

Standard Memory Array Indexing Bit Selection Part Selection Standard Memory Multi Dimensional Memories 95 Standard Memory Emem as a byte-oriented The memory standard with format a 10 bit for address declaring a memory in Verilog is to declare it as an array of a vector. (1024 address space) extracts Cmem word reg [7:0] Emem [0:1023]; addressed by Cmem [Areg[7:6]] Areg[7:6] Emem [Emem[0]] Extracts Emem word Emem [355][3:0] addressed by 4 LSB Emem[0] of location 355 Emem [355][3-:4] 4 bits starting Emem [355:358] from 3, down Illegal; Does not address a 4-word block 96 48

Multi-Dimensional Memories Array Indexing Bit Selection Part Selection Standard Memory Multi Dimensional Memories Memory 97 Multi-Dimensional Memories For accessing such memories (e.g. Dmem declared before), simple indexing are allowed for specifying a word in the memory, and bit- select and part-select are allowed for accessing bit or bits of the addressed word. 98 49

Multi-Dimensional Memories // declaration : reg [7:0] Areg; Areg [7:5] // declaration : reg [7:0] Areg ; Areg [7:5] // declaration : reg Amem [ 7:0]; Amem [3] Areg Areg 7 7 7 Amem 7 0 // declaration : reg Amem [ 7:0]; Amem [3] Amem 0 7 7 0 0 3 // declaration : reg Bmem [7:0][0:3] Bmem [2] [1] Array Addressing & Selection // declaration : reg Bmem [7:0][0:3] Bmem [2] [1] // declaration : reg [7:0] Cmem [0:3] // declaration : reg [7:0] Cmem [0:3] Cmem [1] [6 -: 4] // Cmem declaration [1] [6 -: 4] : reg [ 2:0] Dmem [0:3][0:4] Dmem [0] [2] // declaration : reg [ 2:0] Dmem [0:3][0:4] Dmem [0] [2] 0 7 Cmem 0 Dmem 3 3 0 Bmem Cmem 0 1 3 0 0 Dmem 3 0 Bmem 0 7 2 0 0 3 4 3 2 1 0 4 99 Verilog Simulation Model Verilog Simulation Model Continuous Procedural 100 50

Continuous Verilog Simulation Model Continuous Procedural 101 Continuous Continuous Simple Delay Specification Strength Specification Net Declaration Multiple Drives 102 51

Simple Continuous Simple Delay Specification Strength Specification Net Declaration Multiple Drives 103 Simple A continuous assignment in Verilog is used only in concurrent Verilog bodies. This assignment represents a net driven by a gate output or a logic function. assign w = m p; 104 52

Delay Specification Continuous Simple Delay Specification Strength Specification Net Declaration Multiple Drives 105 Delay Specification assign #2 w = m p; This assignment becomes active when m or p changes. At this time, the new value of the m p expression is evaluated, and after a wait time of 2 time units, this new value is assigned to w. 106 53

Delay Specification `timescale 1ns/100ps module Mux2to1 (input( a, b, c, output w); wire n, m, p; assign #3 m = a & b; Regardless of position in the code, assign #3 p = n & c; each assignment waits for a right-hand-side variable to assign #6 n = ~b; change for it to execute. assign #2 w = m p; endmodule Concurrent Continuous 107 Delay Specification The simulation of the previous circuit results in a glitch due to a 1-hazard on w. The event driven simulation of concurrent statements makes this simulation to correspond to events in the actual circuit. Simulation Run Showing a Glitch 108 54

Strength Specification Continuous Simple Delay Specification Strength Specification Net Declaration Multiple Drives 109 Simple Net strengths are specified by a pair of strength values bracketed by a set of parenthesis, as shown below. assign (strong0, strong1) ) w = m p; One strength value is for logic 1 and one is for logic 0, and the order in which the strength values appear in the set of parenthesis is not important. Strength value names for logic 1 end with a 1 (supply1( supply1, strong1, pull1, weak1, )) and those for logic 0 end with a 0 (supply0( supply0, strong0, pull0, weak0, ). 110 55

Default values for these nets Strength Specification and small, are used for are strong0 and strong1 for For wire and tri type nets, drive Three strength values, large, medium, strength values are used, and for and small, are used for trireg net types, storage nets charge strength logic is 0 and used. and the default is medium. logic 1 respectively. Wires (tri) wand (triand), Wor ( trior), tri0, tri1 trireg Strength value Supply 0 Strong 0 Pull 0 Level 7 6 5 Strength values Strength 0 4 Large Weak 0 3 2 Medium (0) 1 Small (0) Highz 0 Highz 1 0 0 1 2 Small (1) Medium (1) Weak values Weak 1 3 4 Large (1) Pull 1 5 Strong1 6 Supply 1 net Types and Their Strengths 7 Strength 1 111 Net Declaration Continuous Simple Delay Specification Strength Specification Net Declaration Multiple Drives 112 56

Net Declaration `timescale 1ns/100ps module Mux2to1 (input( a, b, c, output w); wire #3 m = a & b, p = n & c, In this code, all the continuous n = ~b, assignments of previous code are w = m p; replaced by a list of net declaration endmodule assignments providing drivers for w, n, m and p signals. Using net_declaration_assignment 113 Multiple Drives Continuous Simple Delay Specification Strength Specification Net Declaration Multiple Drives 114 57

Multiple Drives `timescale 1ns/100ps module Mux2to1 (input( a, b, c, output w); wire n; A value assigned to w is first wor #2 w; delayed by continuous assignment assign #3 w = a & b; delay. Before this value appears on assign #3 w = n & c; w,, it is further delayed by 2 ns assign #6 n = ~b; specified in wor declaration. endmodule A net with Multiple Drivers 115 Multiple Drives Simulation Run of Assignment Statements 116 58

Procedural Verilog Simulation Model Continuous Assignment Procedural 117 Procedural Procedural assignments in Verilog take place in the initial and always procedural constructs, which are regarded as procedural bodies. 118 59

Procedural Procedural Procedural Flow Control Procedural Non-blocking Procedural Continuous Procedural Blocking Multiple Force and Release 119 Procedural Flow Control Procedural Procedural Flow Control Procedural Non-blocking Procedural Continuous Procedural Blocking Multiple Force and Release 120 60

Procedural Flow Control Statements in a procedural body are executed when program flow reaches them. Flow control statements are classified as delay control and event control. An event or delay control statement in a procedural body causes program flow to be put on hold temporarily. 121 Procedural Flow Control program flow stops when it Program flow resumes reaches the @ (reset) after the positive edge statement of and resumes when always the Program value always of flow the clk reset resumes changes. after being put on hold. for 10 time units....... end @ (reset )..... end @ (posedge CLK) always...... end #10 Procedural Flow Control 122 61

Procedural Blocking Procedural Procedural Flow Control Procedural Non-blocking Procedural Continuous Procedural Blocking Multiple Force and Release 123 Procedural Blocking A blocking assignment uses a reg data type on the left-hand side and an expression on the right-hand side of an equal sign. The syntax of intra-assignment control constructs is similar to that of procedural flow control statements, but these constructs appear on the right-hand side of an equal sign in a procedural assignment....; #200 a = #100 b; The procedural assignment that is delayed by 200 time units by a delay control statement and by 100 time units by an intra- assignment delay control. 124 62

Procedural Blocking initial begin : Blocking_Assignment_to_b b = 1; #100 b = #80 0; b = #120 1; #100 $display ("Initial Block with Blocking Assignment to b Ends at:", $time); end The $display statement displays 400 Blocking Procedural 125 Procedural Non-blocking Procedural Procedural Flow Control Procedural Non-blocking Procedural Continuous Procedural Blocking Multiple Force and Release 126 63

Procedural Non-blocking A non-blocking assignment uses the left arrow notation <= (left angular bracket followed by the equal sign) instead of the equal sign used in blocking assignments. When flow reaches a non-blocking assignment, the right-hand side of the assignment is evaluated and will be scheduled for the left-hand side reg to take place when the intra-assignment control is satisfied. 127 Procedural Non-blocking initial begin : Non_blocking_Assignment_to_a a = 1; #100 a <= #80 0; a <= #120 1; #100 $display ("Initial Block with Non-blocking Assignment to a Ends at:", $time); end The $display statement displays 200 Non-blocking Procedural 128 64

Procedural Non-blocking Comparing Blocking and Non-blocking Procedural 129 Multiple Procedural Procedural Flow Control Procedural Non-blocking Procedural Continuous Procedural Blocking Multiple Force and Release 130 65

Multiple If several assignments appear at the same real time in a procedural body, the last assignment overrides all others. If program flow in two procedural bodies reaches assignments to the same reg at exactly the same time, the outcome of the value assigned to the left-hand side of the assignment will not be known. 131 Multiple initial begin clk = 0; end always begin clk = ~clk~ clk; #17; end Multiple reg This code works properly only if complementing of the clk is delayed until the clk is initialized to 0 in the initial block. 132 66

Multiple initial begin clk = 0; end always begin #0; clk = ~clk~ clk; #17; end One way to correct this problem is to delay complementing the clock by one simulation cycle. This can be done by inserting #0. Multiple reg ; Delay Used for Deterministic Results 133 Procedural Continuous Procedural Procedural Flow Control Procedural Non-blocking Procedural Continuous Procedural Blocking Multiple Force and Release 134 67

Procedural Continuous Using a procedural continuous assignment construct, an assignment to a reg type variable can be made to stop all other assignments to this variable from taking place. While qout is not deassigned, deassign qout <= 0; no other assignments to it affect its value. Unlike assign and deassign,, which apply to reg type variables, force and release constructs apply to net and reg types. 135 Procedural Continuous `timescale 1ns/100ps module FlipflopAssign (input reset, din, clk, output qout); reg qout; always @(reset) begin If reset is not active (it is 0), the flip-flop output qout is deassigned. if (reset) assign qout <= 0; Only Assignment after qout takes is deassigned place only can when else deassign qout; other reset assignments is 0. While an to qout assign change is in end effect, another its value. assign to the same always @(posedge clk) begin variable, deassigns the one that is qout <= din; in effect and then assigns a new end value to the variable. endmodule Procedural Continuous 136 68

Force and Release Procedural Procedural Flow Control Procedural Non-blocking Procedural Continuous Procedural Blocking Multiple Force And and Release 137 Force and Release Unlike assign and deassign,, which apply to reg type variables, force, and release constructs apply to net and reg types. Forcing a value on a net overrides all values assigned to the net through continuous assignments or connected to it through gate outputs. 138 69

Compiler Directives Compiler Directives timescale default-nettype include define ifdef, else, endif unconnected -drive celldefine, endcelldefine resetall 139 `timescale Compiler Directives timescale default_nettype include define ifdef, else, endif unconnected _drive celldefine, endcelldefine resetall 140 70

`timescale Including the timescale 1ns/100 ps directive before a module header causes all time-related numbers to be interpreted as having a 1-ns time unit. 141 `default-nettype Compiler Directives timescale default_nettype defaultdefault-nettype include define ifdef, else, endif unconnected _drive celldefine, endcelldefine resetall 142 71

`default-nettype The default wire type can be changed by the default_nettype.. For example, default_nettype wor at the beginning of a module causes undeclared nets in constructs such as the terminal list of a module instance to be assumed to be wor type nets. 143 `include Compiler Directives timescale default_nettype include define ifdef, else, endif unconnected _drive celldefine, endcelldefine resetall 144 72

`include Because Verilog does not provide a common library of parts and utilities, a shared code must be explicitly inserted in modules that use the code. 145 `define Compiler Directives timescale default_nettype include define ifdef, else, endif unconnected _drive celldefine, endcelldefine resetall 146 73

`define `define word_length 32 `define begin_fetch_state 3 b101 if begin_fetch_state is used anywhere in a Verilog code, it is replaced by 3 b101. undef directive undefines a previously defined text macro 147 `ifdef,, `else, `endif` Compiler Directives timescale default_nettype include define ifdef ifdef, else, endif unconnected _drive celldefine, endcelldefine resetall 148 74

`ifdef,, `else, `endif` Because Verilog does not provide a common library of parts and utilities, a shared code must be explicitly inserted in modules that use the code. 149 `ifdef,, `else, `endif` If the next macro has been defined, the group of lines bracketed between ifdef and else is compiled. If the text macro has not been defined, the group of lines bracketed between else and endif is compiled. 150 75

`unconnected-drive Compiler Directives timescale default_nettype include define ifdef, else, endif unconnected _drive -drive celldefine, endcelldefine resetall 151 `unconnected-drive Changes port value left open in the connection list of a module instantiation which is assumed to have the default net value. The only arguments allowed with this directive are pull0 or pull1 for unconnected values 0 and 1, respectively. 152 76

`celldefine,, `endcelldefine` Compiler Directives timescale default_nettype include define ifdef, else, endif unconnected _drive celldefine celldefine, endcelldefine resetall 153 `celldefine,, `endcelldefine` The celldefine and endcelldefine directives bracket modules that are to be considered as cells. 154 77

`resetall Compiler Directives timescale default_nettype include define ifdef, else, endif unconnected _drive celldefine, endcelldefine resetall 155 `resetall Using this directive at the beginning of every module guarantees that no previous setting affects compilation of modules and that all defaults are set. 156 78

System Tasks and Functions The names of system tasks and functions begin with a dollar sign, $, followed by a task specifier 157 System Tasks and Functions System Tasks and Functions Display Tasks Timescale Tasks Timing Check Tasks Conversion Functions For Reals File I/O Tasks Simulation Control Tasks PLA Modeling Tasks Other Tasks and Functions 158 79

Display Tasks System Tasks and Functions Display Tasks Timescale Tasks Timing Check Tasks Conversion Functions For Reals File I/O Tasks Simulation Control Tasks PLA Modeling Tasks Other Tasks and Functions 159 Display Tasks Display tasks include those for monitoring and outputting variable values as they change (the $monitor group of tasks) and those for displaying variables at a selected time (the $display tasks). Display tasks can display in binary, hexadecimal, or octal formats. The character b, h, or o at the end of the task name specifies the data type a task handles. 160 80

File I/O Tasks System Tasks and Functions Display Tasks Timescale Tasks Timing Check Tasks Conversion Functions For Reals File I/O Tasks Simulation Control Tasks PLA Modeling Tasks Other Tasks and Functions 161 File I/O Tasks The $fopen function opens a file and assigns an integer file description. The file descriptor will be used as an argument for all file I/O tasks. There are string write tasks ($swrite( swrite) ) that write their formatted outputs to a string. Verilog also provides tasks for inputting data from files or strings. Examples of these tasks are $fgetc, $fscanf,, and $sscanf for getting character from file, reading formatted data from file, and reading formatted data from string, respectively. 162 81

File I/O Tasks Other input tasks exist for reading memory data directly into a declared memory. Examples of such tasks are $fread and $readmemh. File positioning tasks, $fseek and $frewind are available for positioning file pointer for read or write. 163 Timescale Tasks System Tasks and Functions Display Tasks Timescale Tasks Timing Check Tasks Conversion Functions For Reals File I/O Tasks Simulation Control Tasks PLA Modeling Tasks Other Tasks and Functions 164 82

Timescale Tasks The $printtimescale task displays the timescale and precision of the module whose hierarchical name is being passed to it as its argument. The $timeformat task formats time for display by file IO and display tasks. 165 Simulation Control Tasks System Tasks and Functions Display Tasks Timescale Tasks Timing Check Tasks Conversion Functions For Reals File I/O Tasks Simulation Control Tasks PLA Modeling Tasks Other Tasks and Functions 166 83

Simulation Control Tasks The $finish task ends the simulation and exits. The $stop task suspends the simulation and does not exit the simulation environment. 167 Timing Check Tasks System Tasks and Functions Display Tasks Timescale Tasks Timing Check Tasks Conversion Functions For Reals File I/O Tasks Simulation Control Tasks PLA Modeling Tasks Other Tasks and Functions 168 84

Timing Check Tasks In general, timing check tasks check the timing on one signal or the relative timing of several signals for certain conditions to hold. $nochange (posedge clock, d_input,, 3, 5); Uses the $nochange$ timing check task to report a violation if d_input changes in the period of 3 time units before and 5 time units after the positive edge of the clock. 169 PLA Modeling Tasks System Tasks and Functions Display Tasks Timescale Tasks Timing Check Tasks Conversion Functions For Reals File I/O Tasks Simulation Control Tasks PLA Modeling Tasks Other Tasks and Functions 170 85

PLA Modeling Tasks The general format that we use for describing these tasks is: $sync_async: can be either sync or async $and_or: can be and, or, nand,, or nor $array_plane: in place of array_plane,, array or plane can be used. $async $nand $array (mem8by4, {a1, a2, a3, a4, a5, a6, a7, a8}, {b1, b2, b3, b4}} An asynchronous PLA with a nand logical function, a1 to a7 inputs, and b1 to b4 outputs. PLA nand-plane fuses are determined by the contents of the mem8by4 declared memory 171 a1 a2 a3 a4 a5 a6 a7 a8 0 0 1 1 0 0 0 1 PLA Modeling Tasks b1 = ~(a3 & a4 & a8) b2 = ~(a1 & a2 & a5) b3 = ~(a5 & a6) b4 = ~(a2 & a4) b1 PLA Output Equations a1 a2 a3 a4 a5 a6 a7 a8 b1 1 1 0 0 1 0 0 0 b2 b2 0 0 0 0 1 1 0 0 b3 b3 0 1 0 1 0 0 0 0 b4 b4 (a) Contents of mem8by4, (b) Corresponding PLA NAND Plane 172 86

Conversion Functions for Reals System Tasks and Functions Display Tasks Timescale Tasks Timing Check Tasks Convention Conversion Functions For for Reals File I/O Tasks Simulation Control Tasks PLA Modeling Tasks Other Tasks and Functions 173 Conversion Functions for Reals Verilog provides four system functions for converting from real to integer or bit, and for converting between bit or integer and real. The functions are $bitstoreal, $realtobits, $itor,, and $rtoi. 174 87

Other Functions and Tasks System Tasks and Functions Display Tasks Timescale Tasks Timing Check Tasks Conversion Functions For Reals File I/O Tasks Simulation Control Tasks PLA Modeling Tasks Other Tasks and Functions 175 Other Functions and Tasks $random is a useful function for random data generation. There are three time functions, $realtime, $time,, and $stime,, that return the simulation time in various formats. 176 88

Summary This chapter presented: General timing and concurrency concepts that are particular to hardware description languages. Utilities found in Verilog for describing hardware and hardware test environments. General syntax of the language its operators, names, and data types. Simulation of hardware described in Verilog using language constructs and utilities of this language. Tasks and compiler directives, that are part of the language utilities for hardware and testbench modeling, but are secondary to those discussed in Section 3.2. Most of Verilog without presenting a lot of examples and specific applications of the language constructs. 177 89