VERILOG QUICKSTART. Second Edition. A Practical Guide to Simulation and Synthesis in Verilog

Similar documents
VERILOG QUICKSTART. James M. Lee Cadence Design Systems, Inc. SPRINGER SCIENCE+BUSINESS MEDIA, LLC

VERILOG QUICKSTART. A Practical Guide to Simulation and Synthesis in Verilog. Third Edition

Appendix A GATE-LEVEL DETAILS

Verilog Tutorial (Structure, Test)

St.MARTIN S ENGINEERING COLLEGE Dhulapally, Secunderabad

A Tutorial Introduction 1

INSTITUTE OF AERONAUTICAL ENGINEERING Dundigal, Hyderabad ELECTRONICS AND COMMUNICATIONS ENGINEERING

The Verilog Hardware Description Language, Fifth Edition

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

MLR Institute of Technology

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

Introduction to Digital Design with Verilog HDL

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

The Verilog Hardware Description Language

430 Index. D flip-flop, from nands, 189, 191, 192 D flip-flop, verilog, 37

Online Verilog Resources

CHAPTER - 2 : DESIGN OF ARITHMETIC CIRCUITS

Programmable Logic Devices Verilog VII CMPE 415

Digital VLSI Design with Verilog

Advanced Digital Design Using FPGA. Dr. Shahrokh Abadi

Verilog for High Performance

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

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

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

Introduction to Verilog design. Design flow (from the book) Hierarchical Design. Lecture 2

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

Introduction to Verilog design. Design flow (from the book)

Sunburst Design - Verilog-2001 Design & Best Coding Practices by Recognized Verilog & SystemVerilog Guru, Cliff Cummings of Sunburst Design, Inc.

Lecture 15: System Modeling and Verilog

Why Should I Learn This Language? VLSI HDL. Verilog-2

Digital Design with SystemVerilog

CONTENTS CHAPTER 1: NUMBER SYSTEM. Foreword...(vii) Preface... (ix) Acknowledgement... (xi) About the Author...(xxiii)

Verilog Essentials Simulation & Synthesis

Digital System Design with SystemVerilog

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

Combinational Logic II

THE VERILOG? HARDWARE DESCRIPTION LANGUAGE

Synthesizable Verilog

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

Verilog HDL Introduction

Introduction. Purpose. Intended Audience. Conventions. Close

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

UNIT V: SPECIFICATION USING VERILOG HDL

Contents. Appendix D Verilog Summary Page 1 of 16

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

A Brief Introduction to Verilog Hardware Definition Language (HDL)

(ii) Simplify and implement the following SOP function using NOR gates:

The Verilog Hardware Description Language. Fifth Edition

OVERVIEW: ============================================================ REPLACE

IT T35 Digital system desigm y - ii /s - iii

Verilog introduction. Embedded and Ambient Systems Lab

VHDL for Synthesis. Course Description. Course Duration. Goals

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

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

Brief Introduction of Cell-based Design. Ching-Da Chan CIC/DSD

Index. B Back-annotation, 507 SDF, 508

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

Digital Design Using Digilent FPGA Boards -- Verilog / Active-HDL Edition

The Verilog Language COMS W Prof. Stephen A. Edwards Fall 2002 Columbia University Department of Computer Science

ECE 551 Digital System Design and Synthesis. Instructor: Kewal K. Saluja. Midterm Exam

Logic Synthesis. EECS150 - Digital Design Lecture 6 - Synthesis

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

Verilog Overview. Verilog Overview. Simple Example. Simple Example. Simple Example. Simple Example

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

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

ECE 2300 Digital Logic & Computer Organization. More Sequential Logic Verilog

The Verilog Hardware Description Language, Fifth Edition

Lecture 32: SystemVerilog

CAD for VLSI Design - I. Lecture 21 V. Kamakoti and Shankar Balachandran

EECS150 - Digital Design Lecture 10 Logic Synthesis

Verilog Module 1 Introduction and Combinational Logic

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

Lecture 7. Summary of two-level combinational-logic. Ways of specifying circuits. Solving combinational design problems. Verilog versus VHDL

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

Advanced Digital Design with the Verilog HDL

Design Using Verilog

Hardware description languages

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

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

CSE140L: Components and Design Techniques for Digital Systems Lab

The Verilog Golden Reference Guide

Computer Arithmetic andveriloghdl Fundamentals

Introduction to Verilog/System Verilog

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

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

ALTERA FPGA Design Using Verilog

CSE140L: Components and Design

FSM-based Digital Design using Veriiog HDL

EEL 4783: HDL in Digital System Design

Verilog. Verilog for Synthesis

Asynchronous FIFO Design

EECS150 - Digital Design Lecture 10 Logic Synthesis

Lecture #2: Verilog HDL

Verilog Design Principles

Digital Design with FPGAs. By Neeraj Kulkarni

EN2911X: Reconfigurable Computing Topic 02: Hardware Definition Languages

THE DESIGNER S GUIDE TO VERILOG-AMS

Synthesis of Combinational and Sequential Circuits with Verilog

Chapter 2 Basic Logic Circuits and VHDL Description

Verilog Design Principles

Transcription:

VERILOG QUICKSTART A Practical Guide to Simulation and Synthesis in Verilog Second Edition

VERILOG QUICKSTART A Practical Guide to Simulation and Synthesis in Verilog Second Edition James M. Lee SEVA Technologies KLUWER ACADEMIC PUBLISHERS New York / Boston / Dordrecht / London / Moscow

ebook ISBN: 0-306-47048-9 Print ISBN: 0-792-38515-2 2002 Kluwer Academic Publishers New York, Boston, Dordrecht, London, Moscow Print 1999 Kluwer Academic / Plenum Publishers New York All rights reserved No part of this ebook may be reproduced or transmitted in any form or by any means, electronic, mechanical, recording, or otherwise, without written consent from the Publisher Created in the United States of America Visit Kluwer Online at: and Kluwer's ebookstore at: http://kluweronline.com http://ebooks.kluweronline.com

TABLE OF CONTENTS LIST OF FIGURES LIST OF EXAMPLES LIST OF TABLES 1 INTRODUCTION Framing Verilog Concepts The Design Abstraction Hierarchy Types of Simulation Types of Languages Simulation versus Programming HDL Learning Paradigms Where To Get More Information Reference Manuals Usenet Talk Verilog 2 INTRODUCTION TO THE VERILOG LANGUAGE Identifiers Escaped Identifiers White Space Comments Numbers Text Macros Modules Semicolons Value Set Strengths Numbers, Values, and Unknowns xii xiv xx 1 3 3 4 4 5 5 7 8 8 8 9 9 10 11 12 12 13 14 14 15 15 16

vi 3 STRUCTURAL MODELING Primitives Ports Ports in Primitives Ports in Modules Instances Hierarchy Hierarchical Names Connect by Name Top-Level Modules You Are Now Ready To Run Your First Simulations Exercise 1 The Hello Simulation Exercise 2 The 8-Bit Hierarchical Adder Verilog Quickstart 19 19 20 20 21 21 22 24 26 27 28 28 28 4 BEHAVIORAL MODELING Starting Places for Places for Blocks of Behavioral Code The initial Keyword The always Keyword Delays begin-end Blocks fork-join Blocks System Tasks for Printing Out Results What Is a System Task? $display and Its Relatives Other Commands To Print Results Writing to Files Setting the Default Radix Exercise 3 Printing Out Results from Wires Buried in the Hierarchy Special Characters Suppressing Spaces in Your Output Data Objects in Verilog Nets Ranges Implicit Nets Registers Memories Initial Value of Regs Integers and Reals Time and Realtime Parameters Events Strings Multi-Dimensional Arrays Accessing Words and Bits of Multi-Dimensional Arrays 33 34 34 34 35 36 39 47 47 47 49 50 52 53 53 54 57 57 58 59 60 60 61 61 62 63 63 64 64 65

vii Procedural Assignments Ports and Registers 5 OPERATORS Binary Operators Unary Operators Reduction Operators Ternary Operator Equality Operators Concatenations Logical versus Bit-wise Operations Operations That Are Not Legal on Reals Working with Strings Combining Operators Sizing Expressions Signed Operations Signed Constants 6 WORKING WITH BEHAVIORAL MODELING Continuous Assignment Event Control The always Block for Combinatorial Logic Event Control Explained The if Statement The case Statement Exercise 4 Using Expressions and case Loops The forever Loop The repeat Loop The while Loop The for Loop Procedural Continuous Assignments tasks functions Exercise 5 Functions and Continuous Assignments A Reminder about Ports and Registers Modeling with inout Ports Named Blocks The disable Statement When is a Simulation Done? 7 USER-DEFINED PRIMITIVES 65 69 71 71 73 74 75 76 79 80 82 82 83 83 84 84 87 87 91 92 93 97 98 101 107 107 108 109 110 111 116 123 126 126 126 128 128 131 133

viii Combinatorial UDPs Optimistic Mux Pessimistic Mux The Gritty Details Sequential UDPs UDP Instances The Final Details Exercise 6 Using UDPs 8 PARAMETERIZED MODULES n-bit Mux n-bit Adder n By m Mux n By m Ram Using Parameterized Modules Parameter Passing by Name Parameter Passing By Order Parameter Passing by Names List Values of Parameters in Module Instances 9 STATE MACHINES State Machine Types State Machine Modeling Style State Encoding Methods Default Conditions Implicit State Machines Registered and Unregistered Outputs Factors in Choosing a State Machine Modeling Style 10 MODELING TIPS Modeling Combinatorial Logic Combinatorial Models Using Continuous Assignments Combinatorial Models Using the always Block and regs Combinatorial Models Using Functions Modeling Sequential Logic Sequential Models Using always Sequential Models Using initial Sequential Models Using tasks Modeling Asynchronous Circuits Modeling a One-Shot Modeling Asynchronous Systems Special-Purpose Models Verilog Quickstart 134 134 134 135 136 139 139 140 143 144 144 145 146 147 147 147 148 149 151 151 153 161 163 164 165 166 167 167 168 169 172 173 173 173 176 178 178 179 185

ix Two-Dimensional Arrays Z-Detectors Multiplier Examples A Proven, Successful Approach to Modeling 11 MODELING STYLE TRADE-OFFS Forces That Influence Modeling Style Evolution of a Model Modeling Style and Synthesis Is It Synthesizable? Learning From Other People s Mistakes When To Use UDPs Blocking and Non Blocking Asssignments 12 TEST BENCHES AND TEST MANAGEMENT Introduction to Testing Model Size versus Test Volume Functional Testing Regression Testing Self-Checking Test Benches Sign-Off System Test versus Unit Tests Response-Driven Stimulus Test Benches for Inouts Loading Files into Verilog Memories Test Benches with No Test Vectors Using a Script To Run Test Cases Modeling BIST The Surround and Capture Method 13 COMMON ERRORS Mismatched Ports Missing or Incorrect Declarations Missing Registers Missing Widths Reversed Ranges Improper Use of Procedural Continuous Assignments Missing initial or always Blocks Zero-Delay always Loops initial Instead of always Missing Initialization Overly Complex Code Unintended Storage 185 186 187 197 199 199 200 201 202 203 210 211 213 213 214 215 215 215 220 220 221 224 226 229 229 230 232 237 237 238 238 239 240 240 241 241 242 242 243 243

x Verilog Quickstart Timing Errors Negative Setup Time Zero-Delay Races 14 DEBUGGING A DESIGN Overview of Functional Debugging Where Are the Errors? Universal Techniques Printing Out Messages I am here. Values The Log File Using Waveforms Interactive Debugging Going Interactive The Prompts Special Keys in Interactive Mode Command History The Key File Traversing and Observing Back-Tracing Fan-In Using force and release Waveforms, Graphic User Interfaces, and Other Conveniences Catching Problems Later in a Simulation Isolating Differences in Models Summary of Debugging Appendix A GATE LEVEL DETAILS Primitive Descriptions Logic Gates AND NAND OR NOR XOR XNOR Buffers BUF NOT BUFIF0 BUFIF1 NOTIF0 NOTIF1 PULLDOWN 243 244 244 247 247 248 248 248 248 249 250 250 252 252 253 255 260 263 269 273 274 275 275 277 278 281 281 281 281 282 283 283 284 284 285 285 285 286 286 287 288 288

xi PULLUP Switches NMOS and RNMOS PMOS and RPMOS CMOS and RCMOS TRAN and RTRAN TRANIF0 and RTRANIF0 TRANIF1 and RTRANIF1 Instance Details Delays Delay Units Printing Out Time and the Timescale Strengths Displaying strengths with %v Strength reduction of switch primitives Appendix B EXAMPLE SUMMARY INDEX 289 289 290 291 292 293 293 294 294 294 295 296 296 297 298 299 313

xii Verilog Quickstart LIST OF FIGURES Figure 1-1 Design Abstraction Hierarchy Figure 1-2 Gate-Level Model Mux Schematic Figure 2-1 Number Format Figure 2-2 The Mux Example Figure 2-3 Three-State Buffer Figure 2-4 Two Three-State Buffers Figure 3-1 AND Gate Primitives Figure 3-2 Gate-Level Model Mux Schematic Figure 3-3 Connecting Two Muxes Figure 3-4 Hierarchical 4-Bit Mux Figure 3-5 Mux4 Hierarchy Expanded Figure 3-6 Syntax for Connect by Name Figure 3-7 Adder Schematic Figure 3-8 Adder2 Schematic Figure 3-9 Adder4 Schematic Figure 3-10 Adder8 Schematic Figure 6-1 Connecting 4 Registers to a Wire Figure 6-2 Rotate Left Figure 6-3 Logical Shift Left with 0 Fill Figure 6-4 Rotate Right Figure 6-5 Logical Shift Right with 0 Fill Figure 6-6 ALU Test Vector File alu_test.vec Figure 6-7 Relationships of Ports and Regs Figure 7-1 Adder Using Five Built-In Primitives Figure 7-2 Adder Using Two UDPs Figure 9-1 Moore State Machine Figure 9-2 Mealy State Machine Figure 10-1 State Diagram for Alarm System Figure 11-1 Forces That Act on Modeling Style Figure 11-2 Synthesizablility Flowchart Figure 12-1 Test Bench for an inout Figure 12-2 Logic Surrounded by BIST Figure 12-3 Surround and Capture Method Figure A-1 AND Gate Figure A-2 NAND Gate Figure A-3 OR Gate Figure A-4 NOR Gate Figure A-5 XOR Gate Figure A-6 XNOR Gate Figure A-7 BUF Gate Figure A-8 NOT Gate Figure A-9 BUFIF0 Gate 3 7 12 14 15 16 21 22 23 24 25 26 29 29 30 30 89 103 104 104 104 107 126 141 141 152 152 180 200 203 225 230 233 281 282 283 283 284 284 285 285 286

xiii Figure A-10 BUFIF1 Gate Figure A-11 NOTIF0 Gate Figure A-12 NOTIF1 Gate Figure A-13 Pulldown Figure A-14 Pullup Figure A-15 NMOS or RNMOS Transistor Figure A-16 PMOS or RPMOS Transistor Figure A-17 CMOS or RCMOS Transistor 286 287 288 288 289 290 291 292

xiv Verilog Quickstart LIST OF EXAMPLES Example 1-1 Abstract Model of a Phone Example 1-2 Verilog for Gate-Level Mux Example 2-1 Simple Hello Module Example 2-2 Hello Module without White Space Example 2-3 Hello Module with Extra White Space Example 2-4 Illegal Use of White Space Example 2-5 Comments Example 2-6 Numbers Example 2-7 Specifying a Text Macro Example 2-8 Using a Text Macro Example 2-9 Gate-Level Mux Verilog Code Example 3-1 Verilog Code for the 2-Input and 4-Input AND Gates Example 3-2 Verilog for Gate-Level Mux Example 3-3 Hierarchical 2-Bit Mux Example 3-4 Hierarchical 4-Bit Mux Example 3-5 Hierarchical Names Example 3-6 Mux Connected by Name Example 3-7 Hello Verilog Example 3-8 Adder Test Module Example 4-1 An initial Block Example 4-2 An always Block Example 4-3 Three initial Statements Example 4-4 Three initial Statements with Delay Example 4-5 Simple begin-end Block Example 4-6 begin-end Block with Delay Example 4-7 Multiple begin-end Blocks Example 4-8 fork-join Blocks Example 4-9 Combining begin-end and fork-join Blocks Example 4-10 Displaying a String Example 4-11 Displaying a Single Value Example 4-12 Displaying Multiple Values Example 4-13 Using Format Specifiers with $display Example 4-14 Two $display Statements Example 4-15 Combining $write and $display Example 4-16 Writing to a File Example 4-17 Writing to Multiple Files Example 4-18 $display with $time Example 4-19 Leading Spaces in $monitor with $time Example 4-20 Spaces used to print an 8-Bit value Example 4-21 Suppressing Leading Spaces and Zeroes Example 4-22 Net Declarations Example 4-23 Incorrect Net Declaration 5 7 11 11 11 11 12 13 13 13 14 21 22 23 24 26 26 28 31 34 35 35 36 36 37 37 39 41 47 47 48 48 49 49 50 51 54 55 55 56 59 59

xv Example 4-24 Setting Default Net Type Example 4-25 Register Declarations Example 4-26 Selecting Bits and Parts of a Register Example 4-27 Memory and Register Declarations Example 4-28 Selecting Bits in Registers and Words in Memories Example 4-29 Reg Declaration with Initialization Example 4-30 Declaring Integers and Reals Example 4-31 Declaring Variables of Type time Example 4-32 Parameters Example 4-33 Events Example 4-33 Strings Example 4-35 Multi-Dimensional Arrays of Nets Example 4-36 Multi-Dimensional Arrays of Regs Example 4-37 Accessing Multi-Dimensional Arrays Example 4-38 Simple Procedural Assignments Example 4-39 Procedural Assignments with fork-join Example 4-40 fork-join with Intra-assignment Delays Example 4-41 fork-join with Multiple Delays Example 4-42 fork-join with Simplified Delays Example 4-43 Effect of Intra-assignment Delays on Time Flow Example 4-44 Nonblocking Assignments Example 4-45 Output as a Register Example 5-1 Using Operators Example 5-2 Distinguishing between Bit-wise and Logical Operators Example 5-3 Using Reduction Operators Example 5-4 Ternary Operator Example 5-5 Using the Ternary Operator for a Three-State Buffer Example 5-6 Module To Test an Operator Example 5-7 Concatenations Example 5-8 Bit-wise and Logical operations Example 5-9 Operators and Strings Example 5-10 Combinations of operators for Exclusive-NOR Example 5-11 Signed Declarations Example 5-12 Signed Constants Example 5-13 Effect of Signed Constants Example 6-1 Three-State Buffer Using a Continuous Assignment Example 6-2 A 128-Bit Adder in a Continuous Assignment Example 6-3 Continuous Assignment Multiplier Example 6-4 Connecting Four Registers to a Wire Example 6-5 Alternate Form of Continuous Assignment Example 6-6 Many Forms of Continuous Assignments Example 6-7 Waiting for an Event Example 6-8 Mux Using Continuous Assignment Example 6-9 Mux Using always Block Example 6-10 Always Block Using Comma 60 60 60 61 61 61 62 63 63 64 64 64 65 65 66 66 67 67 68 68 69 70 73 74 75 75 76 79 80 81 82 83 84 84 85 88 88 89 90 90 90 91 92 92 93

xvi Verilog Quickstart Example 6-11 Combinatorial Always Block Example 6-12 Incorrect Mux Example 6-13 Using the event Data Type Example 6-14 Using Events To Simplify Modeling Example 6-15 always Explained Example 6-16 Using wait Example 6-17 Using wait To Detect an Unknown Example 6-18 Using always To Detect an Unknown Example 6-19 Simple if Example 6-20 if with else Example 6-21 Nested if with else Example 6-22 The case Statement Example 6-23 case Matching x and z Example 6-24 Using casez Example 6-25 Test Bench for the ALU Example 6-26 Oscillator Using always Example 6-27 Oscillator Using forever Example 6-28 Repeating Hello Verilog Example 6-29 Using repeat in a State Machine Example 6-30 A while Loop Example 6-31 A Simple for Loop Example 6-32 A for Loop with Expressions Not Referencing the Same Variable Example 6-33 A Simple Flip-Flop Example 6-34 A Flip-Flop with a Bad Reset Example 6-35 A Flip-Flop with Reset Example 6-36 A Flip-Flop with Incorrect Set and Reset Example 6-37 A Flip-flop with Correct Set and Reset Example 6-38 Incorrect Mux Example 6-39 Mux with PCA Example 6-40 Hello Verilog Tasks Example 6-41 task with Inputs, Outputs, and External References Example 6-42 Effect of task Port Size Example 6-43 Accessing a task Local Variable from Outside the task Example 6-44 Task Local and Module Items with the Same Name Example 6-45 Read Cycle task Example 6-46 Re-Entrant Task Example 6-47 Count Bits Function Example 6-48 Mux with Function and Continuous Assignment Example 6-49 Divide Function Returning Two 8-Bit Values Example 6-50 inout Port Connected to a Register Example 6-51 Register with Controllable Connection to inout Port Example 6-52 Named Blocks Example 6-53 The disable Statement Example 6-54 disable Used To Model Reset Example 6-55 Controlling When a Simulation Finishes 93 93 94 95 96 96 97 97 98 98 98 99 100 100 105 108 108 109 109 110 111 111 112 112 113 113 114 115 115 117 118 119 119 120 121 122 123 124 125 127 127 128 128 129 131

xvii Example 7-1 Optimistic Mux UDP Example 7-2 Pessimistic Mux UDP Example 7-3 One-Line UDP Example 7-4 Level-Sensitive D Latch Example 7-5 Edge-Sensitive D Flip-Flop Example 7-6 Flip-Flop Using Explicit Edge Definitions Example 7-7 initial Block in a UDP Example 8-1 parameter Statements Example 8-2 n-bit Wide 4-to-1 Mux Example 8-3 Parameterized Width Adder Example 8-4 Mux with Parameterized Width and Number of Inputs Example 8-5 Parameterized RAM Example 8-6 The defparam Statement Example 8-7 Using Parameterized Modules Example 8-8 Parameter Passing by Order Example 8-9 Parameter Passing by Named List Example 9-1 Style 1 Moore State Machine Example 9-2 Style 1 Mealy State Machine Example 9-3 Style 2 Moore Machine Example 9-4 Style 2 Mealy Machine Example 9-5 Style 3 Mealy Machine Example 9-6 Style 4 Moore Machine Example 9-7 Style 5 Moore Machine Example 9-8 Implicit State Machine Style Example 9-9 Combinatorial Outputs Example 9-10 Registered Outputs Example 10-1 A 2-to-1 Mux Using Continuous Assignment Example 10-2 A 4-to-1 Mux Using Continuous Assignment Example 10-3 Alternate 4-to-1 Mux Using Continuous Assignment Example 10-4 An 8-Bit Adder Using Continuous Assignment Example 10-5 Latch Using Continuous Assignment Example 10-6 The 2-to-1 Mux Using always Example 10-7 The 4-to-1 Mux Using always Example 10-8 The 8-Bit Adder Using always Example 10-9 Simplified 8-Bit Adder Using always Example 10-10 Mux with Continuous Assignment and Function Example 10-11 Simple Counter Example 10-12 A Counter without always Example 10-13 Sequential Stimulus Block Example 10-14 Clock Source Example 10-15 Memory Exerciser Example 10-16 Tasks for Sequential Code Example 10-17 Basic One-Shot Example 10-18 Retriggerable One-Shot Example 10-19 Behavioral Description of the Alarm 134 135 136 136 137 138 139 144 144 145 145 146 147 147 148 149 155 156 156 157 158 159 160 164 165 165 168 168 169 169 169 170 171 171 172 172 173 174 174 174 175 176 178 179 180

xviii Verilog Quickstart Example 10-20 Alarm Test Bench Example 10-21 Partial Implementation of Alarm Example 10-22 Two-Dimensional Array Example 10-23 Behavioral Z-detector Example 10-24 Structural Z-Detector Example 10-25 An 8-by-8 Booth Multiplier Example 10-26 Wallace 8-by-8 Multiplier Example 10-27 A 16-by-16 Multiplier Example 10-28 A 16-by-16 Wallace Multiplier for Signed Numbers Example 11-1 Normal D Flip-Flop Example 11-2 Modified D-Hip-Flop Example 11-3 Bad Register Example 11-4 Improved Register Example 11-5 Tweaked Register Example 11-6 Bad Adder Example 11-7 Improved Adder Example 11-8 Adder Reduced to a Continuous Assignment Example 11-9 Bad Mux Example 11-10 Improved Mux Example 11-11 Bad Barrel Shifter Example 11-12 Improved Barrel Shifter Example 11-13 Blocking vs. Non Blocking Assignments Example 12-1 Adder Test Module Repeated Example 12-2 Using Verilog To Calculate Responses Example 12-3 Simplifying the Test Bench with a task Example 12-4 Using a Second Module To Check the Results Example 12-5 Generating x's for Miscompare Example 12-6 Printer Abstraction Example 12-7 Printer Test Bench with Guessed Timing Example 12-8 Response-Driven Printer Test Bench Example 12-9 Test Bench for a RAM Example 12-10 Memory Declaration Example 12-11 Reversed Memory Declaration Example 12-12 Memory File adder8. vec Example 12-13 Adder Test Bench Reading from a File Example 12-14 PROM Data File prom.dat Example 12-15 Simple PROM Example 12-16 Test Bench with No Vectors Example 12-17 LFSR Example 12-18 Testing the ALU with a LFSR and MISR Example 12-19 ALU Modified Capture of Inputs and Outputs Example 12-20 ALU Test Bench Repeated Example 13-1 Missing Initialization Example 13-2 Negative Setup Time Example 13-3 Corrected Register 182 184 186 186 187 187 189 191 194 201 201 204 205 206 206 207 207 208 208 209 210 211 216 217 218 219 220 222 223 224 225 226 226 227 227 228 228 229 231 232 234 234 242 244 244

xix Example 14-1 Initial Block To Create VCD Wave File Example 14-2 Initial Block To Create SHM Wave File Example 14-3 Interactive Verilog Module Example 14-4 Single-Stepping Example 14-5 always Loop Module Example 14-6 my.key Command File Example 14-7 Hierarchical 8-Bit Adder Example A-1 Delays in Primitive Instances Example A-2 Time Scales Example A-3 Strength Declarations 251 251 253 255 259 267 270 296 298 299

xx Verilog Quickstart LIST OF TABLES Table 2-1 Radix Specifiers Table 2-2 Numbers and Their Values Table 3-1 Verilog Primitives Table 4-1 Format Specifiers Table 4-2 Screen and File Output Commands Table 4-3 Enumeration of All Output Commands Table 4-4 Format Specifiers Table 4-5 Net Types Table 5-1 Arithmetic Operators Table 5-2 Bit-wise Operators Table 5-3 Logical Operators Table 5-4 Negation Operators Table 5-5 Reduction Operators Table 5-6 Truth Table for Ternary Operator Table 5-7 Equality Operators Table 5-8 Truth Table for a == b Table 5-9 Truth Table for a === b Table 5-10 Truth Table for a!= b Table 5-11 Truth Table for a!== b Table 5-12 Truth Table for a < b Table 5-13 Truth Table for a <= b Table 5-14 Truth Table for a > b Table 5-15 Truth Table for a >= b Table 5-16 Operator Order of Precedence Table 5-17 Operators Not Legal on Reals Table 5-18 Radix Specifiers Table 6-1 Comparison of Procedural and Continuous Assignments Table 6-2 Summary of Case Values and Match per Case Type Table 6-3 ALU Exercise: Explanation of Opcodes Table 6-4 Summary of Assignment Types Table 7-1 Basic UDP Table Symbols Table 7-2 Symbols for Sequential UDP Tables Table 7-3 Summary of Instance Types Table 7-4 Complete List of UDP Table Symbols Table 9-1 State Machine Styles Table 9-2 Sequential State Encoding Table 9-3 Mapping State Code To Simplify Outputs Table 9-4 Gray State Encoding Table 9-5 States Compared with Outputs Table 9-6 Outputs as State Code Table 9-7 One-Hot State Encoding Table 14-1 Log File Options 13 17 20 48 51 53 54 57 72 72 72 73 74 76 76 77 77 77 77 78 78 78 78 80 82 85 89 101 103 116 135 137 139 140 153 161 161 162 162 163 163 250

xxi Table 14-2 Special Keys for Interactive Simulation Table 14-3 Keystroke-Related Commands Table 14-4 Commands for Traversing and Observing Table 14-5 The trace, save, and restart Commands Table 14-6 Debugging Commands, Keystrokes, and Command-Line Options Table A-1 Logic Table for and Primitive Table A-2 Logic Table for nand Primitive Table A-3 Logic Table for or Primitive Table A-4 Logic Table for nor Primitive Table A-5 Logic Table for xor Primitive Table A-6 Logic Table for xnor Primitive Table A-7 Logic Table for buf Primitive Table A-8 Logic Table for not Primitive Table A-9 Logic Table for bufif0 Primitive Table A-10 Logic Table for bufif1 Primitive Table A-11 Logic Table for notif0 Primitive Table A-12 Logic Table for notif1 Primitive Table A-13 Logic Table for nmos Primitive Table A-14 Logic Table for rnmos Primitive Table A-15 Logic Table for pmos Primitive Table A-16 Logic Table for rpmos Primitive Table A-17 Logic Table for cmos Primitive Table A-18 Logic Table for rcmos Primitive Table A-19 Delay and Precision Units Table A-20 Strengths Table A-21 Switch Strength Reduction 260 269 269 277 278 282 282 283 283 284 284 285 285 286 287 287 288 290 290 291 291 292 293 295 297 298