cid - etti

380
Loops & Complexity in DIGITAL SYSTEMS Lecture Notes on Digital Design in Giga-Gate per Chip Era (work in never ending progress) Gheorghe S ¸tefan WHAT ! GUESS 1st Loop 1st Loop 2nd Loop – 2010 version –

Upload: cilibiu-ionut-alin

Post on 16-Sep-2015

132 views

Category:

Documents


3 download

DESCRIPTION

Circuite integrale digitale

TRANSCRIPT

  • Loops & Complexity

    in

    DIGITAL SYSTEMS

    Lecture Notes on Digital Design

    in

    Giga-Gate per Chip Era

    (work in never ending progress)

    Gheorghe Stefan

    6

    6

    WHAT !GUESS 1st Loop

    1st Loop

    2nd Loop

    { 2010 version {

  • 2

  • Introduction

    ... theories become clear and `reasonable' only after inco-herent parts of them have been used for a long time.

    Paul Feyerabend1

    The price for the clarity and simplicity of a 'reasonable'approach is its incompleteness.

    Few legitimate questions about how to teach digital systems in Giga-Gate Per Chip Era(G2CE) are waiting for an answer.

    1. What means a complex digital system? How complex systems are designed using smalland simple circuits?

    2. How a digital system expands its size, increasing in the same time its speed? Are theresimple mechanisms to be emphasized?

    3. Is there a special mechanism allowing a \hierarchical growing" in a digital system? Or,how new features can be added in a digital system?

    The rst question occurs because already exist many dierent big systems which seem to havedierent degree of complexity. For example: big memory circuits and big processors. Both areimplemented using a huge number of circuits, but the processors seem to be more \complicated"than the memories. In almost all text books complexity is related only with the dimension ofthe system. Complexity means currently only size, the concept being unable to make necessarydistinctions in G2CE. The last improvements of the microelectronic technologies allow us to puton a Silicon die around a billion of gates, but the design tools are faced with more than the sizeof the system to be realized in this way. The size and the complexity of a digital system mustbe distinctly and carefully dened in order to have a more exible conceptual environment fordesigning, implementing and testing systems in G2CE.

    The second question rises in the same context of the big and the complex systems. Growinga digital system means both increasing its size and its complexity. How are correlated these twogrowing processes? The dynamic of adding circuits and of adding adding features seems to bevery dierent and governed by distinct mechanisms.

    The third question occurs in the hierarchical contexts in which the computation is dened.For example, Kleene's functional hierarchy or Chomsky's grammatical hierarchy are dened to

    1Paul Feyerabend (b.1924, d.1994), having studied science at the University of Vienna, moved into philosophyfor his doctoral thesis. He became a critic of philosophy of science itself, particularly of \rationalist" attempts tolay down or discover rules of scientic method. His rst book, Against Method (1975), sets out \epistemologicalanarchism", whose main thesis was that there is no such thing as the scientic method.

    3

  • 4explain how computation or formal languages used in computation evolve from simple to com-plex. Is this hierarchy reected in a corresponding hierarchical organization of digital circuits?It is obvious that a sort of similar hierarchy must be hidden in the multitude of features alreadyemphasized in the world of digital circuits. Let be the following list of usual terms: booleanfunctions, storing elements, automata circuits, nite automata, memory functions, processingfunctions, : : :, self-organizing processes, : : :. Is it possible to disclose in this list a hierarchy, andmore, is it possible to nd similarities with previously exemplied hierarchies?

    The rst answer will be derived from the Kolmogorov-Chaitin algorithmic complexity: thecomplexity of a circuit is related with the dimension of its shortest formal descrip-tion. A big circuit (a circuit built using a big number o gates) can be simple or complexdepending on the possibility to emphasize repetitive patterns in its structure. A no patterncircuit is a complex one because its description has the dimension proportional with its size.Indeed, for a complex, no pattern circuit each gate must be explicitly specied.

    The second answer associate the composition with sizing and the loop with featuring.Composing circuits results biggest structures with the same kind of functionality, while closingloops in a circuit new kind of behaviors are induced. Each new loop adds more autonomy to thesystem, because increases the dependency of the output signals in the detriment of the inputsignals. Shortly, appropriate loops means more autonomy that is equivalent sometimes with anew level of functionality.

    The third answer is given by proposing a taxonomy for digital systems based on the maxi-mum number of included loops closed in a certain digital system. The old distinction betweencombinational and sequential, applied only to circuits, is complemented with a classicationtaking into the account the functional and structural diversity of the digital systems used inthe contemporary designs. More, the resulting classication provides classes of circuits havingdirect correspondence with the levels belonging to Kleene's and Chomsky's hierarchies.

    The rst part of the book { Digital Systems: a Plane View { is a general introduction indigital systems framing the digital domain in the larger context of the computational sciences,introducing the main formal tool for describing, simulating and synthesizing digital systems, andpresenting the main mechanisms used to structure digital systems. The second part of the book{ Looping in Digital Systems { deals with the main eects of the loop: more autonomy andsegregation between the simple parts and the complex parts in digital systems. Both, autonomyand segregation, are used to minimize size and complexity. The third part of the book { LoopBased Morphisms { contains three attempts to make meaningful connections between thedomain of the digital systems, and the elds of recursive functions, of formal languages and ofinformation theories. The last chapter sums up the main ideas of the book making also some newcorrelations permitted by its own nal position. The book ends with a lot of annexes containingshort reviews of the prerequisite knowledge (binary arithmetic, Boolean functions, elementarydigital circuits, automata theory), compact presentations of the formal tools used (pseudo-codelanguage, Verilog HDL), examples, useful data about real products (standard cell libraries).

    PART I: Digital Systems: a Plane View

    The rst chapter: What's a Digital System? Few general questions are answered in thischapter. One refers to the position of digital system domain in the larger class of the sciences ofcomputation. Another asks for presenting the ways we have to implement actual digital systems.The importance is also to present the correlated techniques allowing to nalize a digital product.

    The second chapter: Let's Talk Digital Circuits in Verilog The rst step in approachingthe digital domain is to become familiar with a Hardware Description Language (HDL) as the

  • 5main tool for mastering digital circuits and systems. The Verilog HDL is introduced and in thesame time used to present simple digital circuits. The distinction between behavioral descriptionsand structural descriptions is made when Verilog is used to describe and simulate combinationaland sequential circuits. The temporal behaviors are described, along with solutions to controlthem.

    The third chapter: Scaling & Speeding & Featuring The architecture and the organi-zation of a digital system are complex objectives. We can not be successful in designing bigperformance machine without strong tools helping us to design the architecture and the highlevel organization of a desired complex system. These mechanisms are three. One helps us toincrease the brute force performance of the system. It is composition. The second is used tocompensate the slow-down of the system due to excessive serial composition. It is pipelining.The last is used to add new features when they are asked by the application. It is about closingloops inside the system in order to improve the autonomous behaviors.

    The fourth chapter: The Taxonomy of Digital Systems A loop based taxonomy fordigital systems is proposed. It classies digital systems in orders, as follows:

    0-OS: zero-order systems - no-loop circuits - containing the combinational circuits;

    1-OS: 1-order systems - one-loop circuits - the memory circuits, with the autonomy of theinternal state; they are used mainly for storing

    2-OS: 2-order systems - two-loop circuits - the automata, with the behavioral autonomyin their own state space, performing mainly the function of sequencing

    3-OS: 3-order systems - three-loop circuits - the processors, with the autonomy in inter-preting their own internal states; they perform the function of controlling

    4-OS: 4-order systems - four-loop circuits - the computers, which interpret autonomouslythe programs according to the internal data

    : : :

    n-OS: n-order systems - n-loop circuits - systems in which the information is interpene-trated with the physical structures involved in processing it; the distinction between dataand programs is surpassed and the main novelty is the self-organizing behavior.

    The fth chapter: Our Final Target A small and simple programmable machine, calledtoyMachine is dened using a behavioral description. In the last chapter of the second part astructural design of this machine will be provided using the main digital structure introducedmeantime.

    PART II: Looping in Digital Domain

    The sixth chapter: Gates The combinational circuits (0-OS) are introduced using a func-tional approach. We start with the simplest functions and, using dierent compositions, thebasic simple functional modules are introduced. The distinction between simple and complexcombinational circuits is emphasized, presenting specic technics to deal with complexity.

  • 6The seventh chapter: Memories There are two ways to close a loop over the simplestfunctional combinational circuit: the one-input decoder. One of them oers the stable structureon which we ground the class of memory circuits (1-OS) containing: the elementary latches,the master-slave structures (the serial composition), the random access memory (the parallelcomposition) and the register (the serial-parallel composition). Few applications of storingcircuits (pipeline connection, register le, content addressable memory, associative memory) aredescribed.

    The eight chapter: Automata Automata (2-OS) are presented in the fourth chapter. Dueto the second loop the circuit is able to evolve, more or less, autonomously in its own statespace. This chapter begins presenting the simplest automata: the T ip-op and the JK ip-

    op. Continues with composed congurations of these simple structures: counters and relatedstructures. Further, our approach makes distinction between the big sized, but simple functionalautomata (with the loop closed through a simple, recursive dened combinational circuit thatcan have any size) and the random, complex nite automata (with the loop closed through arandom combinational circuit having the size in the same order with the size of its denition).The autonomy oered by the second loop is mainly used to generate or to recognize specicsequences of binary congurations.

    The ninth chapter: Processors The circuits having three loops (3-OS) are introduced. Thethird loop may be closed in three ways: through a 0-OS, through an 1-OS or through a 2-OS,each of them being meaningful in digital design. The rst, because of the segregation processinvolved in designing automata using JK ip-ops or counters as state register. The size ofthe random combinational circuits that compute the state transition function is reduced, in themost of case, due to the increased autonomy of the device playing the role of the register. Thesecond type of loop, through a memory circuit, is also useful because it increases the autonomyof the circuit so that the control exerted on it may be reduced (the circuit \knows more aboutitself"). The third type of loop, that interconnects two automata (an functional automaton anda control nite automaton), generates the most important digital circuits: the processor.

    The tenth chapter: Computers The eects of the fourth loop are shortly enumerated in thesixth chapter. The computer is the typical structure in 4-OS. It is also the support of the strongestsegregation between the simple physical structure of the machine and the complex structure ofthe program (a symbolic structure). Starting from the fourth order the main functional up-datesare made structuring the symbolic structures instead of restructuring circuits. Few new loopsare added in actual designs only for improving time or size performances, but not for addingnew basic functional capabilities. For this reason our systematic investigation concerning theloop induced hierarchy stops with the fourth loop. The toyMachine behavioral description isrevisited and substituted with a pure structural description.

    The eleventh chapter: Self-Organizing Structures ends the rst part of the book withsome special circuits which belongs to n-OSs. The cellular automata, the connex memory andthe eco-chip are n-loop structures that destroy the usual architectural thinking based on thedistinction between the physical support for symbolic structures and the circuits used for pro-cessing them. Each bit/byte has its own processing element in a system which performs thenest grained parallelism.

    The twelfth chapter: Global-Loop Systems Why not a hierarchy of hierarchies of loops?Having an n-order system how new features can be added? A possible answer: adding a

  • 7global loop. Thus, a new hierarchy of super-loops starts. It is not about science ction.ConnexArrayTM is an example. It is described, evaluated and some possible applicationsare presented.

    The thirteenth chapter: Designing a Simple Digital System All the techniques learnedin this second part of book are applied to design a real digital system. The presentation of thedesign methodology of this step { the logic design { on the long way from product denition tothe market is a very interesting story. It can be told in many form. One of them is presented inthis ending chapter of the second part of this book.

    The intention of the author in writing this second part of book was to emphasize the segrega-tion mechanism that separates the simple, recursive dened circuits, from the complex, randomcircuits, in designing optimal digital systems. The main supportive process for this segrega-tion is the autonomy, increased with each new loop closed in the system. The main eect ofthe segregation is the reducing of the complexity of digital system (sometimes the size is alsoreduced).

    PART III: Loop Based Morphisms

    The image of the digital systems domain gains new meanings when the own internal developingmechanism is faced with other related domains. Any classication system generates order whenapplied, but in the same time it may be used to better understand the main mechanisms insidethe approached domain. Thus, the second part of this book tries to explain more facts aboutcomputation, about formal languages and about information in the light of facts emphasized, inthe rst part, about digital circuits.

    The fourteenth chapter: Recursive Functions & Loops The rst co-investigated do-main is that of Kleene's recursive functions. The initial functions and the basic rules havecorrespondences with the orders emphasized in the proposed taxonomy for digital circuits. Thetwo hierarchies, one in the recursive functions domain and another in digital systems domain,correspond, motivating and supporting each other. The following correspondences are empha-sized:

    the initial functions (successor, clear, projection) have polynomial sized and log-time so-lution with circuits belonging to 0-OS

    the composition rule is eciently implemented with circuits in 1-OS using pipelined con-nections

    the primitive recursion rule supposes the sequencing ability involved by the circuits be-longing to 2-OS

    the minimalization rule uses the control capability of the third loop closed in 3-OS.

    The main result of this chapter is:

    an actual simple, recursive dened digital system that computes any par-tial recursive function must have at least three loops.

  • 8The fteenth chapter: Chomsky's Hierarchy & Loops The second investigated mor-phism is between the Chomsky's formal language hierarchy and the loop induced hierarchy indigital systems. Results:

    type 3 languages - two-loop machines type 2 languages - three-loop machines type 1 languages - four-loop machines.

    We end this chapter with a recursive dened no state Universal Turing Machine. This simplestUTM shows us that the maximal segregation between a recursive dened, simple machine andthe complex symbolic description of computation is possible. The price for the simplicity allowedby this strong segregation is the incompleteness of the algorithmic approach of computation.

    The sixteenth chapter: Loops & Functional Information One of the most used scienticterms is information, but we still don't know a widely accepted denition of it. There are manydenitions that oer quantitative or qualitative images about what the information can be. Ourapproach starts from the general information theory promoted by M. Draganescu and proposesthe concept of functional information which is the qualitative counterpart to the quantitativeaspects of the algorithmic information developed by G. Chaitin.

    The seventeenth chapter: Twenty Eight Final View Points There are a lot of informaladvises, warnings and suggestions related to the matter presented in this book. They changefaster than the rigorous content previously exposed in the rst 15 chapters. This last chaptercontains the most sensitive matter. It must be read carefully, many times and treated withsuspicion.

    The main stream of this book deals with the simple and the complex in digital systems, empha-sizing them in the segregation process that opposes simple structures of circuits to the complexstructures of symbols. The functional information oers the environment for segregating thesimple circuits from the complex binary congurations.

    When the simple is mixed up with the complex, the apparent complexity of the systemincreases over its actual complexity. We promote design methods which reduce the apparentcomplexity by segregating the simple from the complex. The best way to substitute the apparentcomplexity with the actual complexity is to drain out the chaos from order. One of the mostimportant conclusions of this book is that the main role of the loop in digital systems is tosegregate the simple from the complex, thus emphasizing and using the hidden resources ofautonomy.

    In the digital systems domain prevails the art of disclosing the simplicity because thereexists the symbolic domain of functional information in which we may ostracize the complexity.But, the complexity of the process of disclosing the simplicity exhausts huge resources of imagi-nation. This book oers only the starting point for the architectural thinking: the art of ndingthe right place of the interface between simple and complex in computing systems.

    Acknowledgments

  • Contents

    I DIGITAL SYSTEMS: A PLANE VIEW 1

    1 WHAT'S A DIGITAL SYSTEM? 3

    1.1 Framing the digital design domain . . . . . . . . . . . . . . . . . . . . . . . . . . 4

    1.2 Simple introductory examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7

    1.3 Dierent embodiment of digital systems . . . . . . . . . . . . . . . . . . . . . . . 16

    1.4 Correlated domains . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17

    1.5 Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19

    2 LET'S TALK DIGITAL CIRCUITS IN VERILOG! 21

    2.1 Pseudo-code languages & algorithms . . . . . . . . . . . . . . . . . . . . . . . . . 22

    2.2 Finite input vs. \innite" input algorithms . . . . . . . . . . . . . . . . . . . . . 23

    2.3 History free systems & combinational circuits . . . . . . . . . . . . . . . . . . . . 30

    2.4 History sensitive systems & sequential circuits . . . . . . . . . . . . . . . . . . . . 35

    2.5 Time restrictions in digital systems . . . . . . . . . . . . . . . . . . . . . . . . . . 43

    2.5.1 Pipelined connections . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46

    2.5.2 Fully buered connections . . . . . . . . . . . . . . . . . . . . . . . . . . . 49

    2.6 Concluding about Verilog & digital systems . . . . . . . . . . . . . . . . . . . . . 50

    2.7 Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51

    2.8 Projects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56

    3 GROWING & SPEEDING & FEATURING 57

    3.1 Size vs. Complexity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59

    3.2 Growing the size by composition . . . . . . . . . . . . . . . . . . . . . . . . . . . 61

    3.3 Speeding by pipelining . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66

    3.3.1 Register transfer level . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67

    3.3.2 Pipeline structures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67

    3.3.3 Data parallelism vs. time parallelism . . . . . . . . . . . . . . . . . . . . . 69

    3.4 Featuring by closing new loops . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71

    3.4.1 Data dependency . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 733.4.2 Speculating to avoid limitations imposed by data dependency . . . . . . 76

    3.5 Concluding about composing & pipelining & looping . . . . . . . . . . . . . . . . 77

    3.6 Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78

    3.7 Projects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79

    4 THE TAXONOMY OF DIGITAL SYSTEMS 81

    4.1 Loops & Autonomy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82

    4.2 Classifying Digital Systems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85

    4.3 Super Digital Systems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88

    4.4 Preliminary Remarks On Digital Systems . . . . . . . . . . . . . . . . . . . . . . 88

    4.5 Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89

    9

  • 10 CONTENTS

    4.6 Projects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90

    5 OUR FINAL TARGET 915.1 A small & simple machine: toyMachine . . . . . . . . . . . . . . . . . . . . . . . 925.2 How toyMachine works . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 985.3 Concluding about toyMachine . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1035.4 Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1045.5 Projects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104

    II LOOPING IN THE DIGITAL DOMAIN 105

    6 GATES:Zero order, no-loop digital systems 1076.1 Simple, Recursive Dened Circuits . . . . . . . . . . . . . . . . . . . . . . . . . . 108

    6.1.1 Decoders . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1096.1.2 Demultiplexors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1126.1.3 Multiplexors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1146.1.4 Shifters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1176.1.5 Priority encoder . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1196.1.6 Increment circuit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1206.1.7 Adders . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1216.1.8 Arithmetic and Logic Unit . . . . . . . . . . . . . . . . . . . . . . . . . . 1256.1.9 Comparator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1276.1.10 Sorting network . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1296.1.11 Prex computation network . . . . . . . . . . . . . . . . . . . . . . . . . 1306.1.12 First detection network . . . . . . . . . . . . . . . . . . . . . . . . . . . 132

    6.2 Complex, Randomly Dened Circuits . . . . . . . . . . . . . . . . . . . . . . . . . 1336.2.1 An Universal circuit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1336.2.2 Using the Universal circuit . . . . . . . . . . . . . . . . . . . . . . . . . . 1346.2.3 The many-output random circuit: Read Only Memory . . . . . . . . . . . 137

    6.3 Concluding about combinational circuits . . . . . . . . . . . . . . . . . . . . . . . 1426.4 Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1436.5 Projects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147

    7 MEMORIES:First order, 1-loop digital systems 1497.1 Stable/Unstable Loops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1517.2 Elementary Structures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152

    7.2.1 Elementary Latches . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1527.2.2 Clocked Elementary Latches . . . . . . . . . . . . . . . . . . . . . . . . . 1557.2.3 Data Latch . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 156

    7.3 The Serial Composition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1587.3.1 The master-slave principle . . . . . . . . . . . . . . . . . . . . . . . . . . . 1587.3.2 The D ip-op . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1607.3.3 The Serial Register . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 161

    7.4 The Parallel Composition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1627.4.1 The n-bit latch . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1627.4.2 The Random Access Memory . . . . . . . . . . . . . . . . . . . . . . . . . 162

    7.5 The Serial-Parallel Composition: the Register . . . . . . . . . . . . . . . . . . . . 1667.6 Applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 167

  • CONTENTS 11

    7.6.1 Register File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 167

    7.6.2 Field Programmable Gate Array { FPGA . . . . . . . . . . . . . . . . . . 168

    7.6.3 Content Addressable Memory . . . . . . . . . . . . . . . . . . . . . . . . 1727.6.4 An Associative Memory . . . . . . . . . . . . . . . . . . . . . . . . . . . 173

    7.7 Concluding about memory circuits . . . . . . . . . . . . . . . . . . . . . . . . . . 175

    7.8 Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 177

    7.9 Projects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 182

    8 AUTOMATA:Second order, 2-loop digital systems 183

    8.1 Two States Automata . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 185

    8.1.1 The Smallest Automaton: the T Flip-Flop . . . . . . . . . . . . . . . . . . 185

    8.1.2 The JK Automaton: the Greatest Flip-Flop . . . . . . . . . . . . . . . . . 186

    8.1.3 Serial Arithmetic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1878.1.4 Universal 2-input and 2-state automaton . . . . . . . . . . . . . . . . . 188

    8.2 Functional Automata: the Simple Automata . . . . . . . . . . . . . . . . . . . . . 188

    8.2.1 Counters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 188

    8.2.2 Accumulator Automaton . . . . . . . . . . . . . . . . . . . . . . . . . . 1918.2.3 \Bit-eater" automaton . . . . . . . . . . . . . . . . . . . . . . . . . . . . 191

    8.3 Composing with simple automata . . . . . . . . . . . . . . . . . . . . . . . . . . 1928.3.1 LIFO memory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1938.3.2 FIFO memory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1948.3.3 The Multiply-Accumulate Circuit . . . . . . . . . . . . . . . . . . . . . 196

    8.4 Finite Automata: the Complex Automata . . . . . . . . . . . . . . . . . . . . . . 198

    8.4.1 Basic Congurations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 198

    8.4.2 Designing Finite Automata . . . . . . . . . . . . . . . . . . . . . . . . . . 199

    8.4.3 Control Automata: the First \Turning Point" . . . . . . . . . . . . . . . 2058.5 Automata vs. Combinational Circuits . . . . . . . . . . . . . . . . . . . . . . . 2148.6 The Circuit Complexity of a Binary String . . . . . . . . . . . . . . . . . . . . 2178.7 Concluding about automata . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 219

    8.8 Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 220

    8.9 Projects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 225

    9 PROCESSORS:Third order, 3-loop digital systems 227

    9.1 Implementing nite automata with "intelligent registers" . . . . . . . . . . . . . . 229

    9.1.1 Automata with JK \registers" . . . . . . . . . . . . . . . . . . . . . . . . 229

    9.1.2 Automata using counters as registers . . . . . . . . . . . . . . . . . . . . 2329.2 Loops closed through memories . . . . . . . . . . . . . . . . . . . . . . . . . . . . 234

    9.3 Loop coupled automata: the second "turning point" . . . . . . . . . . . . . . . . 236

    9.3.1 Push-down automata . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2369.3.2 The elementary processor . . . . . . . . . . . . . . . . . . . . . . . . . . . 238

    9.3.3 Executing instructions vs. interpreting instructions . . . . . . . . . . . . . 242

    9.3.4 An executing processor . . . . . . . . . . . . . . . . . . . . . . . . . . . . 245

    9.3.5 An interpreting processor . . . . . . . . . . . . . . . . . . . . . . . . . . 2489.4 The assembly language: the lowest programming level . . . . . . . . . . . . . . 2639.5 Concluding about the third loop . . . . . . . . . . . . . . . . . . . . . . . . . . . 263

    9.6 Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 264

    9.7 Projects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 264

  • 12 CONTENTS

    10 COMPUTING MACHINES:4{loop digital systems 26510.1 Types of fourth order systems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 266

    10.1.1 The computer { support for the strongest segregation . . . . . . . . . . . 26810.2 The stack processor { a processor as 4-OS . . . . . . . . . . . . . . . . . . . . . 268

    10.2.1 The organization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26910.2.2 The micro-architecture . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27110.2.3 The instruction set architecture . . . . . . . . . . . . . . . . . . . . . . . 27410.2.4 Implementation: from micro-architecture to architecture . . . . . . . . . 27510.2.5 Time performances . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27910.2.6 Concluding about our Stack Processor . . . . . . . . . . . . . . . . . . . 280

    10.3 Embedded computation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28010.3.1 The structural description of toyMachine . . . . . . . . . . . . . . . . . . 28010.3.2 Interrupt automaton: the asynchronous version . . . . . . . . . . . . . . . 289

    10.4 Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29210.5 Projects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 292

    III ANNEXES 293

    A Pseudo-code language 295

    B Boolean functions 297B.1 Short History . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 297B.2 Elementary circuits: gates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 297

    B.2.1 Zero-input logic circuits . . . . . . . . . . . . . . . . . . . . . . . . . . . . 298B.2.2 One input logic circuits . . . . . . . . . . . . . . . . . . . . . . . . . . . . 298B.2.3 Two inputs logic circuits . . . . . . . . . . . . . . . . . . . . . . . . . . . . 298B.2.4 Many input logic circuits . . . . . . . . . . . . . . . . . . . . . . . . . . . 299

    B.3 How to Deal with Logic Functions . . . . . . . . . . . . . . . . . . . . . . . . . . 299B.4 Minimizing Boolean functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 301

    B.4.1 Canonical forms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 301B.4.2 Algebraic minimization . . . . . . . . . . . . . . . . . . . . . . . . . . . . 303B.4.3 Veitch-Karnaugh diagrams . . . . . . . . . . . . . . . . . . . . . . . . . . 305

    B.5 Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 309

    C Basic circuits 311C.1 Actual digital signals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 311C.2 CMOS switches . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 313C.3 The Inverter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 314

    C.3.1 The static behavior . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 314C.3.2 Dynamic behavior . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 315C.3.3 Buering . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 316C.3.4 Power dissipation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 317

    C.4 NAND & NOR gates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 318C.5 AND-NOR gates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 319C.6 Many-Input Gates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 319C.7 The Tristate Buers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 320C.8 The Transmission Gate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 320C.9 Memory Circuits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 321

    C.9.1 Flip-ops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 321

  • CONTENTS 13

    C.9.2 Static memory cell . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 321C.9.3 Array of cells . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 321C.9.4 Dynamic memory cell . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 321

    D Standard cell libraries 325D.1 Main parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 325D.2 Basic cells . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 327

    D.2.1 Gates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 327D.2.2 Flip-ops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 330

    E Finite Automata 331E.1 Basic denitions in automata theory . . . . . . . . . . . . . . . . . . . . . . . . . 331E.2 How behaves a nite automata . . . . . . . . . . . . . . . . . . . . . . . . . . . . 333E.3 Representing nite automata . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 334

    E.3.1 Flow-charts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 334E.3.2 Transition diagrams . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 337E.3.3 Procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 341

    E.4 State codding . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 343E.4.1 Minimal variation encoding . . . . . . . . . . . . . . . . . . . . . . . . . . 345E.4.2 Reduced dependency encoding . . . . . . . . . . . . . . . . . . . . . . . . 346E.4.3 Incremental codding . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 346E.4.4 One-hot state encoding . . . . . . . . . . . . . . . . . . . . . . . . . . . . 347

    E.5 Minimizing nite automata . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 347E.5.1 Minimizing the size by an appropriate state codding . . . . . . . . . . . . 347E.5.2 Minimizing the complexity by one-hot encoding . . . . . . . . . . . . . . . 348

    E.6 Parasitic eects in automata . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 351E.6.1 Asynchronous inputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 351E.6.2 The Hazard . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 353

    E.7 Fundamental limits in implementing automata . . . . . . . . . . . . . . . . . . . 356

    F Meta-stability 359

  • 14 CONTENTS

  • Part I

    DIGITAL SYSTEMS: A PLANEVIEW

    1

  • Chapter 1

    WHAT'S A DIGITAL SYSTEM?

    In the previous chapterwe can not nd anything because it does not exist, but we suppose the reader is familiarwith:

    fundamentals about what means computation

    basics about Boolean algebra and basic digital circuits (see Annexes Boolean Func-tions and Basic circuits for a short refresh)

    the usual functions supposed to be implemented by digital sub-systems in the currentaudio, video, communication, gaming, ... market products

    In this chaptergeneral denitions related with the digital domain are used to reach the following targets:

    to frame the digital system domain in the larger area of the information technologies

    to present dierent ways the digital approach is involved in the design of the realmarket products

    to enlist and shortly present the related domains, in order to integrate better theknowledge and skills acquired by studying the digital system design domain

    In the next chapteris a friendly introduction in both, digital systems and a HDLs (Hardware DescriptionLanguages) used to describe, simulate, and synthesized them. The HDL selected for thisbook is called Verilog. The main topics are:

    the distinction between combinational and sequential circuits

    the two ways to describe a circuit: behavioral or structural

    how digital circuits behave in time.

    3

  • 4 CHAPTER 1. WHAT'S A DIGITAL SYSTEM?

    Talking about Apple, Steve said, \The systemis there is no system." Then he added, \thatdoes't mean we don't have a process." Mak-ing the distinction between process and systemallows for a certain amount of uidity, spon-taneity, and risk, while in the same time itacknowledges the importance of dened rolesand discipline.

    J. Young & W. Simon1

    A process is a strange mixture of rationallyestablished rules, of imaginary driven chaos,and of integrative mystery.

    A possible good start in teaching about a complex domain is an informal one. The mainproblems are introduced friendly, using an easy approach. Then, little by little, a more rigorousstyle will be able to consolidate the knowledge and to oer formally grounded techniques. Thedigital domain will be disclosed here alternating informal \plane views" with simple, formalizedreal stu. Rather than imperatively presenting the digital domain we intend to disclose it instep by step using a project oriented approach.

    1.1 Framing the digital design domain

    The domain of digital systems is considered as part of computing science. This, possible viewpoint presents the digital systems as systems which compute their associated transfer functions.A digital system is seen as a sort of electronic system because of the technology used now toimplement it. But, from a functional view point it is simply a computational system, because fu-ture technologies will impose maybe dierent physical ways to implement it (using, for example,dierent kinds of nano-technologies, bio-technologies, photon-based devices, : : :.). Therefore,we decided to start our approach using a functionally oriented introduction in digital systems,considered as a sub-domain of computing science. Technology dependent knowledge is alwayspresented only as a supporting background for various design options.

    Where can be framed the domain of digital systems in the larger context of computingscience? A simple, informal denition of computing science oers the appropriate context forintroducing digital systems.

    Denition 1.1 Computer science (see also Figure 1.1) means to study:

    algorithms, their hardware embodiment and their linguistic expression

    with extensions toward

    hardware technologies and real applications. 1They co-authored iCon. Steve Jobs. The Greatest Second Act in the History of Business, an unauthorized

    portrait of the co-founder of Apple.

  • 1.1. FRAMING THE DIGITAL DESIGN DOMAIN 5

    ALGORITHMS

    HARDWARE LANGUAGES

    TECHNOLOGY APPLICATIONS

    R

    R

    abstract

    actual?

    digital systems

    R

    Figure 1.1: What is computer science? The domain of digital systems provides techniques fordesigning the hardware involved in computation.

    The initial and the most abstract level of computation is represented by the algorithmic level.Algorithms specify what are the steps to be executed in order to perform a computation. Themost actual level consists in two realms: (1) the huge and complex domain of the applicationsoftware and (2) the very tangible domain of the real machines implemented in a certain tech-nology. Both contribute to implement real functions (asked, or aggressively imposed, my theso called free market). An intermediate level provides the means to be used for allowing analgorithm to be embodied in a physical structure of a machine or in an informational structureof a program. It is about (1) the domain of the formal programming languages, and (2) thedomain of hardware architecture. Both of them are described using specic and rigorous formaltools.

    The hardware embodiment of computations is done in digital systems. What kind of for-mal tools are used to describe, in the most exible and ecient way, a complex digital system?Figure 1.2 presents the formal context in which the description tools are considered. Pseudo-code language is an easy to understand and easy to use way to express algorithms. Anythingabout computation can be expressed using this kind of languages. By the rule, in a pseudo-codelanguage we express, for our (human) mind, preliminary, not very well formally expressed, ideasabout an algorithm. The \main user" of this kind of language is only the human mind. But,for building complex applications or for accessing advanced technologies involved in building bigdigital systems, we need rened, rigorous formal languages and specic styles to express compu-tation. More, for a rigorous formal language we must take into account that the \main user" isa merciless machine, instead of a tolerant human mind. Elaborated programming languages(such as C++, Java, Prolog, Lisp) are needed for developing complex contexts for computationand to write using them real applications. Also, for complex hardware embodiments specichardware description languages, HDL, (such as Verilog, VHDL, SystemC) are proposed.

    Both, general purpose programming languages and HDLs are designed to describe somethingfor another program, mainly for a compiler. Therefore, they are more complex and rigorous thana simple pseudo-code language.

    The starting point in designing a digital system is to describe it using what we call a spec-ication, shortly, a spec. There are many ways to specify a digital system. In real life ahierarchy of specs are used, starting from high-level informal specs, and going down until themost detailed structural description is provided. In fact, de design process can be seen as astream of descriptions which starts from an idea about how the new object to be designed be-haves, and continues with more detailed descriptions, in each stage more behavioral descriptions

  • 6 CHAPTER 1. WHAT'S A DIGITAL SYSTEM?

    R

    PSEUDO-CODELANGUAGE

    PROGRAMMINGLANGUAGES

    HARDWARE DESCRIPTIONLANGUAGES

    Figure 1.2: The linguistic context in computer science. Human mind uses pseudo-codelanguages to express informally a computation. To describe the circuit associated with the computation

    a rigorous HDL (hardware description language) is needed, and to describe the program executing the

    computation rigorous programming languages are used.

    being converted in structural descriptions. At the end of the process a full structural descriptionis provided. The design process is the long way from a spec about what we intend to do toanother spec describing how our intention can be fullled.

    At one end of this process there are innovative minds driven by the will to change the world.In these imaginative minds there is no knowledge about \how", there is only willingness about\what". At the other end of this process there are very skilled entities \knowing" how to do veryeciently what the last description provides. They do not care to much about the functionalitythey implement. Usually, they are machines driven by complex programs.

    In between we need a mixture of skills provided by very well instructed and trained people.The role of the imagination and of the very specic knowledge are equally important.

    How can be organized optimally a designing system to manage the huge complexity of thisbig chain, leading from an idea to a product? There is no system able to manage such a complexprocess. No one can teach us about how to organize a company to be successful in introducing,for example, a new processor on the real market. The real process of designing and imposing anew product is trans-systemic. It is a rationally adjusted chaotic process for which no formalrules can ever provided.

    Designing a digital system means to be involved in the middle of this complex process,usually far away from its ends. A digital system designer starts his involvement when thespecs start to be almost rigorously dened, and ends its contribution before the technologicalborders are reached.

    However, a digital designer is faced in his work with few level of descriptions during theexecution of a project. More, the number of descriptions increases with the complexity of theproject. For a very simple project, it is enough to start from a spec and the structural descriptionof the circuit can be immediately provided. But for a very complex project, the spec must besplit in specs for sub-systems, each sub-system must be described rst by its behavior. Theprocess continue until enough simple sub-systems are dened. For them structural descriptionscan be provided. The entire system is simulated and tested. If it works synthesisable descriptionsare provided for each sub-system.

    A good digital designer must be well trained in providing various description using an HDL.She/he must have the ability to make, both behavioral and structural descriptions for circuitshaving any level of complexity. Playing with inspired partitioning of the system, a skilled

  • 1.2. SIMPLE INTRODUCTORY EXAMPLES 7

    designer is one who is able to use appropriate descriptions to manage the complexity of thedesign.

    1.2 Simple introductory examples

    Digital systems belong to the wider class of the discrete systems (systems having a countablenumber of states). Therefore, a general denition for digital system can be done as a specialcase of discrete system.

    Denition 1.2 A digital system, DS, in its most general form is dened by specifying the vecomponents of the following quintuple:

    DS = (X;Y; S; f; g)

    where: X f0; 1gn is the input set of n-bit binary congurations, Y f0; 1gm is the outputset of m-bit binary congurations, S f0; 1gq is the set of internal states of q-bit binarycongurations,

    f : (X S)! Sis the state transition function, and

    g : (X S)! Y

    is the output transition function.

    A digital system has two simultaneous evolutions:

    the evolution of its internal state which takes into account the current internal state andthe current input generating the next state of the system

    the evolution of its output which takes into account the current internal state and thecurrent input generating the current output.

    The internal state of the system determines the partial autonomy of the system. It responds onits outputs to the input variations taking into account both, the current input and the internalstate.

    Because all the sets involved in the previous denition have the form f0; 1gs, each of thes one-bit input, output, or state evolves in time switching between two values: 0 and 1. Theprevious denition denes a system having an n-bit input, an m-bit output and a q-bit internalstate. If xt 2 X, yt 2 Y , qt 2 Q are values on input, output, and of state at the discrete momentof time t, then the behavior of the system is described by:

    qt = f(qt1; xt1)

    yt = g(qt; xt)

    While the current output is computed from the current input and the current state, the cur-rent state was computed using the previous input and the previous state. The two functionsdescribing a discrete system belong to two distinct class of functions:

    sequential functions : used to generate a sequence of values each of them iterated from itspredecessor (an initial value is always provided, and the i-th value cannot be computedwithout computing all the previous i 1 values)

  • 8 CHAPTER 1. WHAT'S A DIGITAL SYSTEM?

    non-sequential functions : used to compute an output value starting only from the currentvalues applied on its inputs.

    Depending on how the functions f and g are dened results a hierarchy of digital systems.More on this in the next chapters.

    The variable time is essential for the sequential functions, but for the non-sequential onesit is meaningless.

    Results the following requests for implementing actual digital systems:

    the binary values { 0 and 1 { must be codded by two electric levels; the current technologieswork with 0 Volts for the value 0, and with a tension level in the range of 1-2 Volts for thevalue 1

    physical modules to compute functions like yt = g(qt; xt), which continuously follow bytheir output values { yt { any change on the inputs qt and xt

    a \master of the discrete time" must be provided, in order to make consistent the simpleideas as \was", \previous", \next"; it is about a specic signal having the period T whichswings between 0 ad 1, called clock, used to \tick" the discrete time with its active edge(see Figure 2.1 where a clock, active on its positive edge, is shown)

    a storing support to memorize the state between two successive discrete moments of timeis required; it is the register used to register, synchronized with the active edge of theclock signal, the state computed at the moment t 1 in order to be used at the moment tto compute a new state and a new output.

    -

    6

    clock

    time

    titi2 ti1

    6 6 6 6 6

    ti+1 ti+2

    -Tclock

    Figure 1.3: The clock. This clock signal is active on its positive edge (negative edge as active edge isalso possible). The time interval between two positive transitions is the period Tclock of the clock signal.

    Each positive transition marks a discrete moment of time.

    The most complex part of dening a digital system is the description of the two functions fand g. The complexity of dening how the system behaves is managed by using various HDLs.

    It's the time for few example using the simplest forms for the functions f and g. Let usconsider rst the simple case of a system with no internal state (S = ):

    DS = (X;Y; g)

    where: X f0; 1gn is the input set of n-bit binary congurations, Y f0; 1gm is the outputset of m-bit binary congurations

    g : X ! Y

  • 1.2. SIMPLE INTRODUCTORY EXAMPLES 9

    is the output transition function. Because the function g has the general form yt = g(qt; xt) thetime evolution is not important and the actual system will be a clockless one with no internalregisters to store the state. The following examples give us only a avor about what digitaldesign means.

    Example 1.1 Let us use the Verilog HDL to describe an adder for 4-bit numbers (see Figure1.4a). The description which follows is a behavioral one, because we know what we intend todesign, but we do not know yet how to design the internal structure of an adder.

    adder

    in0 in1

    out

    adder

    in0 in1

    out

    ?

    ? ?

    ?

    ?

    in0 in1 in2

    out

    sum

    threeAdder

    b.

    adder

    ?

    ? ?

    in0 in1

    out

    a.

    4 4

    4

    inAdder

    outAdder

    9

    Figure 1.4: The rst examples of digital systems. a. The two 4-bit numbers adder, calledadder. b. The structure of an adder for 3 4-bit numbers, called threeAdder.

    The Verilog code describing the module adder is:

    module adder(out, in0, in1);

    output [3:0] out ;

    input [3:0] in0 ;

    input [3:0] in1 ;

    assign out = in0 + in1;

    endmodule

    The story just told by the previous Verilog module is: \the 4-bit adder has two inputs, in0,in1, one output, out, and its output is continuously assigned to the value obtained by addingmodulo 16 the two input numbers".

    What we just learned from the previous rst simple example is summarized in the followingVerilogSummary.

    VerilogSummary 1 :

    module : keyword which indicates the beginning of the description of a circuit as a modulehaving the name which immediately follows (in our example, the name is: adder)

    endmodule : keyword which indicates the end of the module's description which started withthe previous keyword module

    output : keyword used to declare a terminal as an output (in our example the terminal out isdeclared as output)

  • 10 CHAPTER 1. WHAT'S A DIGITAL SYSTEM?

    input : keyword used to declare the terminal as an input (in our example the terminals in0and in1 are declared as inputs)

    assign : keyword called the continuous assignment, used here to specify the function performedby the module (the output out takes continuously the value computed by adding the twoinput numbers)

    (...) : delimiters used to delimit the list of terminals (external connections)

    , : delimiter to separate each terminal within a list of terminals

    ; : delimiter for end of line

    [ : : : ]: delimiters which contains the denition of the bits associated with a connection, forexample [3:0] dene the number of bits for the three connections in the previous example

    + : the operator add, the only one used in the previous example.

    The description of a digital system is a hierarchical construct starting from a top modulepopulated by modules, which are similarly dened. The process continues until very simplemodule are directly described. Thus, the functions f and g are specied by HDL programs (inour case, in the previous example by a Verilog program).

    The main characteristic of the digital design is modularity. A problem is decomposed inmany simpler problems, which are solved similarly, and so on until very simple problems areidentied. Modularity means also to dene as many as possible identical modules in each design.This allow to replicate many times the same module, already designed and validated. Many &simple modules! Is the main slogan of the digital designer. Let's take another example whichuses as module the one just dened in the previous example.

    Example 1.2 The previously exemplied module (adder) will be used to design a modulo 163-number adder, called threeAdder (see Figure 1.4b). It adds 3 4-bit numbers providing a 4-bitresult (modulo 16 sum). Follows the structural description:

    module threeAdder(output [3:0] out,

    input [3:0] in0,

    input [3:0] in1,

    input [3:0] in2);

    wire [3:0] sum;

    adder inAdder(.out(sum),

    .in0(in1),

    .in1(in2)),

    outAdder(.out(out),

    .in0(in0),

    .in1(sum));

    endmodule

    Two modules of adder type (dened in the previous example) are instantiated as inAdder,outAdder, they are interconnected using the wire sum, and are connected to the terminals of thethreeAdder module. The resulting structure computes the sum of three numbers.

    VerilogSummary 2 :

    Another way to specify the type of terminals, inside the list of terminals

  • 1.2. SIMPLE INTRODUCTORY EXAMPLES 11

    A new keyword: wire used to specify internal connections inside the current module (inour example: the 4-bit (numbered from 3 to 0) connection, sum, between the output of amodule and the input of another module (see also Figure 1.4b))

    How a previously dened module (in our example: adder) is two times instantiated usingtwo dierent names (inAdder and outAdder in our example)

    A \safe" way to allocate the terminals for a module previously dened and instantiatedinside the current module: each original terminal name is preceded by a dot, and followedby a parenthesis containing the name of the wire or of the terminal where it is connected(in our example, outAdder( ... .in1(sum)) means: the terminal in1 of the instanceoutAdder is connected to the wire sum)

    The successive instantiations of the same module can be separated by a \,".

    While the module adder is a behavioral description, the module threeAdder is a structuralone. The rst tells us what is the function of the module, and the second tells us how itsfunctionality is performed by using a structure containing two instantiation of a previouslydened subsystems, and an internal connection.

    Once the design completed we need to know if the resulting circuit works correctly. A simpletest must be provided in what we call a simulation environment. It is a Verilog modulewhich contains, besides the device under test (dut) a stimulus generator and an \outputdevice" used to monitor the behavior of dut. In Figure 1.5 this simple simulation environmentis presented.

    threeAdder&

    STIMULUS

    MONITOR

    ---

    in0

    in1

    in2

    out

    in0

    in1

    in2

    out

    threeAdderSim

    dut

    =

    Figure 1.5: Simulation environment: the module threeAdderSim. The device under test {threeAdder { is interconnected with a \module" which provides the inputs and monitors the output.

    Example 1.3 The simulation for the circuit designed in the previous example is done usingthe following Verilog module.

    module threeAdderSim;

    // STIMULUS & MONITOR SECTION

    reg [3:0] in0, in1, in2;

    wire [3:0] out;

    initial begin in0 = 4'b0011 ;

    in1 = 4'b0100 ;

  • 12 CHAPTER 1. WHAT'S A DIGITAL SYSTEM?

    in2 = 4'b1000 ;

    #2 in0 = in0 + 1 ;

    #2 in2 = in2 + in0 ;

    #2 in1 = 0 ;

    #2 $stop ;

    end

    initial

    $monitor

    ("time = %d, in0 = %d, in1 = %d, in2 = %d, out = %d, out = %b",

    $time, in0, in1, in2, out, out);

    // DEVICE UNDER TEST

    threeAdder dut(out, in0, in1, in2);

    endmodule

    The module threeAdderSim includes the device under test { threeAdder module {, and amodule which provides the \environment" for the module to be tested. The environment-modulecontains registers used to store the input variables in0, in1, in2, and a \monitor" used toprint the evolving values on the terminals of the device under test.

    The rst initial block describes the evolution of the three input variables, starting from thetime 0 until the end of simulation specied by $stop

    The second initial block displays the evolution on the terminals of dut. The output terminalout is twice displayed, once in decimal form and another time in binary form.

    The two initial blocks are executed in parallel starting from the time 0 of the simulation.The simulation provides the following result:

    # time = 0, in0 = 3, in1 = 4, in2 = 8, out = 15, out = 1111

    # time = 2, in0 = 4, in1 = 4, in2 = 8, out = 0, out = 0000

    # time = 4, in0 = 4, in1 = 4, in2 = 12, out = 4, out = 0100

    # time = 6, in0 = 4, in1 = 0, in2 = 12, out = 0, out = 0000

    VerilogSummary 3 :

    reg[n-1:0 ]: is an n-bit register used to store an n-bit state variable; it is usually loaded usingas trigger the active edge of clock

    test module is another circuit (usually without external connections), used to simulate thebehavior of a specic module, containing:

    registers, or other circuits, for providing the input variables of the tested circuit an instantiation of the tested circuit a monitor to display the behavior of the outputs of the tested circuit (or a signalinside the tested circuit)

    initial : initializes a block of commands executed only once, starting at the time 0 of thesimulation

    begin : used to delimit the beginning of a block of behavioral statements (equivalent with "f"in C programming language)

    end : used to delimit the end of a block of behavioral statements (equivalent with "g" in Cprogramming language)

  • 1.2. SIMPLE INTRODUCTORY EXAMPLES 13

    #< number > : species a delay of < number > time units (a time unit is an arbitrary unitof time), and is used in a description only for the purpose of simulating circuits, but notfor synthesizing them

    $stop : stops the process of simulation

    $monitor : starts the simulation task of monitoring the signals selected in the associated list

    $time : specify the time variable

    %d : the number is represented as a decimal one

    %b : the number is represented as a binary one

    // : it is used to delimit the comment, the text which follows until the end of the current line.

    The previous three examples represent a simple bottom-up approach in digital design. Therst example dened an elementary module, the adder. The second, uses the adder to build thestructure of a 3-number adder. The rst two examples oered a simple image about what a no-state circuit can be, and about what the simulation is and how it can be used for a preliminarytest for our design.

    Next step is to consider a simple example of a digital system having an internal state. Letus consider the case of adding numbers represented on multiple by 4 bits using circuits able toperform only 4-bit addition. As we know from elementary arithmetic the carry generated byeach 4-bit adder can be used to add numbers bigger than 15. Let say two 12-bit numbers mustbe added. First, the least signicant 4 bits are added resulting the least signicant 4 bits of theresult and a value for the one-bit signal carry. The next 4 signicant bits of the operands areadded and the result is added with the one bit number carry, resulting the next 4 signicantbits of the result and a new value for carry. The last step adds the most signicant 4 bits andthe value of carry, resulting the most signicant bits of the result. If the last value of carry isconsidered, then it is the 13th bit of the result. The digital engine able to perform the previouslydescribed operations uses its internal state to store the value of the carry signal in order to beconsidered in the next step of computation. It is described in the next example.

    Example 1.4 The digital system for the sequential addition has two 4-bit data inputs, in0,in1, one 2-bit command input, com, a clock input, clk, and the 4-bit output sum. The commandinput \tells" the system what to do in each clock cycle: if com[1] = 0, then the state of thesystem do not change, else the state of the system takes the value of the carry resulting fromadding the current values applied on the data inputs; if com[0] = 0, then the current additionignores the value of carry stored as the internal state of the system, else the addition takesinto account the state as the carry generated in the previous addition cycle. The Verilog codedescribing the system is the following:

    /*

    com = 00 : sum = in1 + in0 ;

    com = 01 : sum = in1 + in0 + carry ;

    com = 10 : {carry, sum} = in1 + in0 ;

    com = 11 : {carry, sum} = in1 + in0 + carry ;

    */

    module sequentialAdder(output [3:0] sum,

    input [3:0] in0,

    input [3:0] in1,

  • 14 CHAPTER 1. WHAT'S A DIGITAL SYSTEM?

    input [1:0] com,

    input clk);

    reg carry ; // the state register of the system

    wire cryOut;

    wire cry ;

    assign cry = com[0] ? carry : 0 ;

    assign {cryOut, sum} = in0 + in1 + cry ;

    always @(posedge clk) if (com[1]) carry = cryOut;

    endmodule

    The way this module is used is explained in the folowing simulation:

    module testSequentialAdder;

    reg [3:0] in0;

    reg [3:0] in1;

    reg [1:0] com;

    reg clk;

    wire [3:0] sum;

    initial begin clk = 0 ;

    forever #1 clk = ~clk;

    end

    initial begin com = 2'b10 ;

    in1 = 4'b1000;

    in0 = 4'b1001;

    #2 com = 2'b11 ;

    in1 = 4'b0000;

    in0 = 4'b0001;

    #2 com = 2'b11 ;

    in1 = 4'b0010;

    in0 = 4'b0011;

    #2 com = 2'b11 ;

    in1 = 4'b0010;

    in0 = 4'b0011;

    #2 com = 2'b00 ;

    $stop ;

    end

    sequentialAdder dut( sum,

    in0,

    in1,

    com,

    clk);

    initial $monitor("time = %d clk = %b in1 = %b in0 = %b com = %b sum = %b carry = %b",

    $time, clk, in1, in0, com, sum, dut.carry);

    endmodule

    The result of simulation is:

    # time = 0 clk = 0 in1 = 1000 in0 = 1001 com = 10 sum = 0001 carry = x

    # time = 1 clk = 1 in1 = 1000 in0 = 1001 com = 10 sum = 0001 carry = 1

    # time = 2 clk = 0 in1 = 0000 in0 = 0001 com = 11 sum = 0010 carry = 1

    # time = 3 clk = 1 in1 = 0000 in0 = 0001 com = 11 sum = 0001 carry = 0

    # time = 4 clk = 0 in1 = 0010 in0 = 0011 com = 11 sum = 0101 carry = 0

  • 1.2. SIMPLE INTRODUCTORY EXAMPLES 15

    # time = 5 clk = 1 in1 = 0010 in0 = 0011 com = 11 sum = 0101 carry = 0

    # time = 6 clk = 0 in1 = 0010 in0 = 0011 com = 11 sum = 0101 carry = 0

    # time = 7 clk = 1 in1 = 0010 in0 = 0011 com = 11 sum = 0101 carry = 0

    The result of synthesis is presented in Figure 1.6, where:

    the adder module adds two 4-bit numbers (in1[3:0], in2[3:0]) and the one-bit numbercin (carry-in) providing the 4-bit sum (out[3:0]) and the one bit number cout (carry-out)

    the one-bit register carry is used to store, synchronized with the positive edge of the clocksignal clk, the value of the carry signal, cout generated by the adder, only when the inputce (clock enable) is 1 (com[1] = 1) enabling the switch of the register

    the 2-input AND gate applies the output of the register to the cin only when com[0] = 1;when com[0] = 0, cin = 0

    addercin

    cout

    carryce

    in

    out

    ??-

    ? ?

    ?

    in1[3:0] in2[3:0]

    com[0]

    com[1]

    clk

    out[3:0]

    AND gate

    one-bit register

    1

    Y

    Figure 1.6:

    Both, simulation and sinthesis are performed using specic software tools (for example: Mod-elSim for simulations and Xilinx ISE for sinthesis)

    VerilogSummary 4 :

    cond ? a : b : is the well known a C construct which selects a if cond = 1, else selects b

    fa, bg : represent the concatenation of a with balways @( ) : is a Verilog construct activated whenever the condi-

    tion is fullled

    posedge : keyword used to specify the positive edge of the clock signal (negedge species thenegative edge of the clock signal)

    always @(posedge clock) : each positive transition of clock will trigger the action describedinside the body of the construct always

    if (cond) ... : used to specify the conditioned execution

    forever : keyword indicating an unending repetition of the subsequent action

  • 16 CHAPTER 1. WHAT'S A DIGITAL SYSTEM?

    name1.name2 : selects the signal name2 from the module name1

    The previous examples oered a avor about what the digital design is: using an HDL(Verilog, for example) two kinds of descriptions can be provided { behavioral and structural{ both, being used to simulate and/or to synthesize a digital system. Shortly: describe,simulate, synthesize is the main triad of the digital design.

    1.3 Dierent embodiment of digital systems

    The physical embodiment of a digital system evolved, in the second part of the previous century,from circuits built using vacuum tubes to now a day complex systems implemented on a singledie of silicon containing billions of components. We are here interested only by the actualstage of technology characterized by an evolutionary development and a possible revolutionarytransition.

    The evolutionary development is from the multi-chip systems approach to the system on achip (SoC) implementations.

    The revolutionary transition is from Application Specic Integrated Circuit (ASIC) approachto the fully programmable solutions for SoC.

    SoC means integrating on a die a big system which, sometimes, involve more than one tech-nology. Multi-chip approach was, and it is in many cases, necessary because of two reasons: (1)the big size of the system and, more important, (2) the need of use of few incompatible tech-nologies. For example, there are big technological dierences in implementing analog or digitalcircuits. If the circuit is analog, there is also a radio frequency sub-domain to be considered.The digital domain has also its specic sub-domain of the dynamic memories. Accommodatingon the same silicon die dierent technologies is possible but the price is sometimes too big. Thegood news is that there are continuous technological developments providing cheap solutions forintegrating previously incompatible technologies.

    An ASIC provides very ecient solutions for well dened functions and for big markets.The main concern with this approach is the lack of functional exibility on a very fast evolvingmarket. Another problem with the ASIC approach is related with the \reusability" of the siliconarea which is a very expensive resource in a digital system. For example, if the multiplicationfunction is used in few stages of the algorithm performed by an ASIC, then a multiplicationcircuit must be designed and placed on silicon few times even if the circuits stay some- or many-times unused. An alternative solution provides only one multiplier which is \shared" by dierentstages of the algorithm, if possible.

    There are dierent types of \programmable" digital systems:

    recongurable systems: are physical structures, having a set of useful features, canbe congured, to perform a specic function, by the binary content of some specic stor-age registers called conguring registers; the exibility of this approach is limited to thetargeted application domain

    programmable circuits: are general purpose structures whose interconnection and sim-ple functionality are both programmed providing any big and complex systems; but, oncethe functionality in place, the system performs a x function

    programmable systems: are designed using one or many programmable computingmachines able to provide any transfer function between its inputs and outputs.

  • 1.4. CORRELATED DOMAINS 17

    All these solutions must be evaluated takeing into account their exibility, speed perfor-mance, complexity, power consumption, and price. The exibility is minimal for congurablesystems and maximal for programmable circuits. Speed performance is easiest to be obtainedwith recongurable systems, while the programmable circuits are the laziest at big complexities.Complexity is maximal for programmable circuits and limited for recongurable systems. Powerconsumption is minimal for recongurable solutions, and maximal for programmable circuits.Price is minimal for recongurable systems, and maximal for programmable circuits. In all theprevious evaluations programmable systems are avoided. Maybe this is the reason for whichthey provide overall the best solution!

    Designing digital circuits is about the hardware support of programmable systems. This bookprovides knowledge on circuits, but the nal target is to teach how to build various programmablestructures. Optimizing a digital system means to have a good balance between the physicalstructure of circuits and the informational structure of programs running on them. Because thefuture of complex systems belongs to the programmable systems, the hardware support oeredby circuits must be oriented toward programmable structures, whose functionality is actualizedby the embedded information (program).

    Focusing on programmable structures does not mean we ignore the skills involved in designingASICs or recongurable systems. All we discuss about programmable structures applies also toany kind of digital structure. What will happen will be that at a certain level in the developmentof digital systems features for accepting program control will be added.

    1.4 Correlated domains

    Digital design must be preceded and followed by other disciplines. There are various prerequisitesfor attending a digital design course. These disciplines are requested for two reasons:

    the student must be prepared with an appropriate pool of knowledge

    the student must be motivated to acquire a new skill.

    In an ideal world, a student is prepared to attend digital design classes by having knowledgeabout: Boolean algebra (logic functions, canonic forms, minimizing logic expressions), Automatatheory (formal languages, nite automata, : : : Turing Machine), Electronic devices (MOS tran-sistor, switching theory), Switching circuits (CMOS structure, basic gates, transmission gate,static & dynamic behavior of the basic structures).

    In the same ideal world, a student can be motivated to approach the digital design domain ifhe payed attention to Theory of computation, Microprocessor architecture, Assembly languages.

    Attending the classes of Digital Systems is only a very important step on a long journeywhich suppose to attend a lot of other equally important disciplines. The most important arelisted bellow.

    Verication & testing For complex digital system verication and testing become very im-portant tasks. The design must be veried to be sure that the intended functionality is inplace. Then in each stage, on the way from the initial design to the fabrication of the actualchip, various tests are performed. Specic techniques are developed for verication and testingdepending on the complexity of the design. Specic design techniques are used to increase theeciency of testing. Design for testability is a well developed sub-domain which helps us withdesign tricks for increasing the accuracy and speed of testing.

  • 18 CHAPTER 1. WHAT'S A DIGITAL SYSTEM?

    Physical design The digital system designer provides only a description. It is a programwritten in a HDL. This description must be used to build accurately an actual chip containingmany hundred of million of circuits. It is a multi-stage process where after circuit design,simulation, synthesis, and functional verication, done by the digital design team, follow layoutdesign & verication, mask preparation, wafer fabrication, die test. During this longprocess a lot of additional technical problem must be solved. A partial enumeration of themfollows.

    Clock distribution: The clock signal is a pulse signal distributed almost uniformly on thewhole area of the chip. For a big circuit the clock distribution is a critical problem becauseof the power involved and because of the accuracy of the temporal relation imposed for it.

    Signal propagation: Besides clock there are a lot of other signals which can be criticalif they spread on big parts of the circuit area. The relation between these signals makesthe problem harder.

    Chip interface circuits: The electrical charge of an interface circuit is much bigger thanfor the internal one. The capacitance load on pins being hundred times bigger the usualinternal load, the output current for pin driver must be correspondingly.

    Powering: The switching energy is provided from a DC power supply. The main problemis to have enough energy right in time at the power connections of each circuit form thechip. Power distribution is made dicult by the inductive eect of the power connections.

    Cooling: The electrical energy introduced in circuit, through the power system, must bethen, unfortunately, extracted as caloric energy (heat) by cooling it.

    Packaging: The silicon die is mounted in a package which must full a lot of criteria. Itmust allow powering and cooling the die it contains. Also, it must provide hundreds oreven thousands external connections. Not to mention protection to cosmic rays, : : :.

    Board design: The chips are designed to be mounted on boards where they are intercon-nected with other electronic components. Because of the very high density of connections,designing a board is a very complex job involving knowledge from a lot of related domains(electromagnetism, mechanics, chemistry, : : :).

    System design: Actual applications are nalized as packaged systems containing one ormany boards, sometimes interconnected with electro-mechanical devices. Putting togethermany components, powering them, cooling them, protecting them from disturbing external(electromagnetic, chemical, mechanical, : : :) factors, adding esthetic qualities require multi-disciplinary skills.

    For all these problems specic knowledge must be acquired attending special classes, coursemodules, or full courses.

    Computer architecture Architectural thinking is a major tendency in the contemporaryword. It is a way to discuss about the functionality of an object ignoring its future actualimplementation. The architectural approach helps us to clarify rst what we intend to build,unrestricted by the implementation issues. Computer architecture is a very important sub-domain of computer science. It allow us to develop independently the hardware domain and thesoftware domain maintaining in the same time a high \communicating channel" between the twotechnologies: one referring to the physical structures and another involving the informationalstructure of programs.

  • 1.5. PROBLEMS 19

    Embedded systems In an advanced stage of development of digital system the physicalstructure of the circuits start to be interleaved with the informational structure of programs.Thus, the functional exibility of the system and its eciency is maximized. A digital systemtend to be more and more a computational system. The computation become embedded intothe core of a digital system. The discipline of embedded system or embedded computation2

    starts to be a nis coronat opus of digital domain.

    Project management Digital systems are complex systems. In order to nalize a real prod-uct a lot of activities must be correlated. Therefore, an ecient management is mandatory for asuccessful project. More, the management of the digital system project has some specic aspectsto be taken into account.

    Business & Marketing & Sales Digital systems are produced to be useful. Then, they mustspread in our human community in the most appropriate way. Additional, but very related skillsare needed to enforce on the market a new digital system. The knowledge about business, aboutmarketing and sales is crucial for imposing a new design. A good, even revolutionary idea isnecessary, but absolutely insucient. The pure technical skills must be complemented by skillshelping the access on the market, the only place where a design receives authentic recognition.

    1.5 Problems

    Problem 1.1 Let be the full 4-bit adder described in the following Verilog module:

    module fullAdder( output [3:0] out ,

    output crOut , // carry output

    input [3:0] in0 ,

    input [3:0] in1 ,

    input crIn ); // carry input

    wire [4:0] sum ;

    assign sum = in0 + in1 + crIn ;

    assign out = sum[3:0] ;

    assign crOut = sum[4] ;

    endmodule

    Use the module fullAdder to design the following 16-bit full adder:

    module bigAdder( output [15:0] out ,

    output crOut , // carry output

    input [15:0] in0 ,

    input [15:0] in1 ,

    input crIn ); // carry input

    // ???

    endmodule

    The resulting project will be simulated designing the appropriate test module.

    2In DCAE chair of the Electronics Faculty, in Politehnica University of Bucharest this topics is taught asFunctional Electronics, a course introduced in late 70s by the Professor Mihai Dr'ag'anescu.

  • 20 CHAPTER 1. WHAT'S A DIGITAL SYSTEM?

    Problem 1.2 Draw the block schematic of the following design:

    module topModule( output [7:0] out,

    input [7:0] in1,

    input [7:0] in2,

    input [7:0] in3);

    wire [7:0] wire1, wire2;

    bottomModule mod1( .out(wire1 ),

    .in1(in1 ),

    .in2(in2 )),

    mod2( .out(wire2 ),

    .in1(wire1 ),

    .in2(in3 )),

    mod3( .out(out ),

    .in1(in3 ),

    .in2(wire2 ));

    endmodule

    module bottomModule( output [7:0] out,

    input [7:0] in1,

    input [7:0] in2);

    // ...

    endmodule

    Synthesize it to test your solution.

    Problem 1.3 Let be the schematic representation of the design topSyst in Figure 1.7. Writethe Verilog description of what is described in Figure 1.7. Test the result by synthesizing it.

    syst1

    in1 in2

    out

    syst1

    in1 in2

    out

    in1

    syst2

    in2

    out1 out2

    syst4syst4

    in2in1

    out

    in2in1

    out

    ? ?

    ? ? ?

    ?

    syst3

    ?

    out

    ? ??

    ? in?

    ? ?

    ?

    syst2in1

    out1 out2

    8

    8

    8 8 8

    8 8

    8

    8

    8

    8

    8 8

    88 8

    8 8

    a. b.

    in1 in2

    out2

    in3

    out1

    topSyst

    in2

    Figure 1.7: The schematic of the design topSyst. a. The top module topSyst b. The structureof the module syst2.

  • Chapter 2

    LET'S TALK DIGITAL CIRCUITSIN VERILOG!

    In the previous chaptera general introduction in digital systems is done with the following emphasis:

    the digital domain is part of the computer science, providing the physical support forall the technologies involved in information processing

    a digital system has many ways and levels of implementation, starting from purecircuits and ending with fully programmable systems

    there are a lot of related activities supporting the actual implementation of a digitalsystem; the digital design is only one important stage on the way leading to realmarket products performing useful functions

    In this chaptera friendly introduction in Verilog HDL is provided. Meantime, generalities about digitalcircuits (not systems) are introduced discussing the following topics:

    how an algorithm can be converted into a digital circuit the distinction between combinational (history free) and sequential (history sensitive)circuits

    time aware design in order to reach the expected performance.

    In the next chaptera preliminary discussion about how a big, fast and featured digital system can be de-ned and implemented, starting from small and simple digital circuits is presented. Thefollowing mechanisms are introduced:

    the composition mechanism to show how a digital system scales the pipeline trick used to increase the speed of the system the loop closed inside a digital circuit or system which acts adding new functionalfeatures if it is appropriately used.

    21

  • 22 CHAPTER 2. LET'S TALK DIGITAL CIRCUITS IN VERILOG!

    When we gain the ability to share our under-standing of experiences with others, we are indanger of losing contact with direct experience.

    Arnold Mindell1

    Using a formal language the eort of design-ing digital circuits is shared with formal tools,but we face in the same time the danger ofless experiencing deep thoughts about digitalsystems.

    The HDL already adopted for this book is Verilog. It will be used to express rigorously ourthought about digital systems. Its similarity with the C language, one of the most common usedlanguage, recommends it for this purpose. Both, C and Verilog borrow from the pseudo-codelanguage the main mechanisms to express an algorithm.

    2.1 Pseudo-code languages & algorithms

    An algorithm can be expressed in many forms. Currently a pseudo-code language can be used asa primary form to manipulate ideas about a certain computation. Pseudo-code is any notationthat captures the ow of the circuit or of the program you are designing. It has its value inproviding a transition language situated between your ideas about how to solve a problem andthe corresponding program written in a programming language the machines can understand.It outlines the general ow of what you want to do and how you want to do it, but it won'trun on a computer. The idea of algorithm expressed in pseudo-code is a non-formal concept.

    Denition 2.1 Informally, an algorithm is:

    a syntactic correct sequence of eectively computable operations which produces a result in a nite amount of time.

    A rough idea about what a pseudo-language is can be obtained visiting Appendix Pseudo-code language, where we can learn how an algorithm, or a pseudo-program, is expressed as aprocedure having a name and acting on few variables using a nite sequence of operations.There are few kinds of operations. The input operations set the initial value of variables. Theoutput operation print, prints the value of the certain variables as intermediate or nal resultsof computation. The same operation can be used to print certain messages about the evolution ofthe computational process. There are simple operations used to modify the value of a variableaccording to a logic or arithmetic operation applied to one or many variables. Because thesequence of operations to be applied in a certain stage of computation depends, sometimes, bya partial result of the current computation, the conditional execution allows to apply a stringof operations or another, according to the value of a tested condition. Other times, the samesequence of operations must be executed a number of times given by the value of a variable(can be an input variable or a variable computed at a certain stage of the current computation).There are two kind of iterative executions. The rst tests the ending condition at the end ofthe sequence, and the second tests the condition before executing the sequence.

    1From [Mindell '00] pag. 41

  • 2.2. FINITE INPUT VS. \INFINITE" INPUT ALGORITHMS 23

    A pseudo-program is a procedure and it can calls other procedures. Thus, an algorithm isexpressed by one procedure or many hierarchical dened procedures.

    Example 2.1 The Euclid's algorithms for computing the greatest common divider of two num-bers is:

    procedure gcd(a, b);

    v = a;

    w = b;

    r = 0 // reminder

    loop r = v - (int(v/w) * w); // int(x) is integer part of x

    v = w;

    w = r;

    until (r = 0)

    print(v);

    end

    The previous algorithm is described in pseudo-code language only for the use of our mind,as an intermediary step for two dierent possible purposes. One can be to write a program ina formal programming language to be sent as input for a compiler which will generate code fora specic machine. Another can be to write the description of a circuit, using a HDL language,to be sent as input for a synthesis program which will generate a more or less detailed circuitrepresentation.

    Neither the computer program nor the circuit will behave performing exactly the operationsused in the previous description. For example, in a high level programming language or in a HDLthe reminder will be determined using a simpler operations than a division. The translation ofa pseudo-code procedure is always a creative process taking into account the specic featuresoered by the targeted language.

    2.2 Finite input vs. \innite" input algorithms

    Data used as input for an algorithm can be constant dimensioned or can have a undened dimen-sion. Depending on how the input variables are dimensioned there are two kind of algorithms:

    nite input algorithms: the input consists in a constant number of constant dimensionedvariables,

    \innite" input algorithms: the input consists in a stream of variables with unknown,usually big, length.

    For example, a nite input algorithm is the algorithm for computing ab where a and b are 4-bitsigned integers:

    procedure exp(a[3:0], b[3:0]);

    ...

    end

    The examples 2.1 (gcd(a,b)) and 2.2 (binary(x)) represent also nite input algorithms.An example of \innite" input algorithm