zoukankan      html  css  js  c++  java
  • 【深入理解计算机系统】 三:布尔逻辑与组合电路

    4.1. Boolean Expressions

    Today’s digital circuits are built so that they can perform very fast operations over data that is encoded in binary. The underlying operations are part of what is known as Boolean Algebra. This algebra consists of two values known as true and false, and three operations over those values: conjunction, disjunction and negation. When using digital circuits, the values are also known as 0 and 1, high and low, or on and off. The three operations are also known by the generic names andor and not respectively. These three operations receive a set of values that are either true or false, and produce another binary value and their definition is shown in the following table:

    Definition of the operations in Boolean Algebra
    OperationSymbolsResult
    Conjunction and, * true when both operands are one
    Disjunction or, + true when any operand is one
    Negation  x’, LaTeX: frac{ }{x}LaTeX: 
eg x
    The opposite of the operand

    Out of all the possible symbols to represent the negation operation, we will use the expression LaTeX: x'. The expressions in Boolean algebra are similar to regular mathematical expressions but with the difference that only Boolean operations are allowed. The following table shows some analogies and differences between expressions:

    Analogies and differences between algebraic expressions
    Regular AlgebraBoolean Algebra
    1+5=6 1 + 0 = 1
    3*2=6 1*1 = 1
    a+b a + b (disjunction)
    a*b a*b (conjunction)
      a' (negation)

    As you can see, the expressions are written representing the conjunction by the symbol *, the disjunction by the symbol +, and negation as an apostrophe following the symbol. In some cases, the conjunction is simply represented by concatenating together two symbols, and conjunction has precedence over disjunction. The following expressions are equivalent:

    LaTeX: left(aast bast c
ight)+left(dast bast e
ight)=left(abc
ight)+left(dbe
ight)

    LaTeX: a'b'c+db'=left(a'ast b'ast c
ight)+left(dast b'
ight)

    LaTeX: left(a'b'c
ight)'+db'=left(a'ast b'ast c
ight)'+left(dast b'
ight)

    Any symbol in Boolean algebra can only take the values true and false as opposed to the more familiar decimal algebraic expressions where symbols can take any number. Thus, we can easily enumerate all possible values of a simple expression. For example, the expression for the conjunction of two symbols, LaTeX: aast b, has four possible values for its symbols, and for each of them we can write the value of the expression:

    Values of symbols and expression
    Value of aValue of bValue of a*b
    0 0 0
    0 1 0
    1 0 0
    1 1 1

    This type of table containing all possible combination of values for the symbols that appear in an expression and the result of evaluating the expression is known as the truth table. Thus, the previous table is the truth table of the conjunction of two symbols. Analogously we can create the truth table of the disjunction:

    Truth table of the disjunction
    Value of aValue of bValue of a+b
    0 0 0
    0 1 1
    1 0 1
    1 1 1

    And for completeness, the truth table of the negation is:

    Truth table of negation
    Value of aValue of a'
    0 1
    1 0

    Boolean expressions can be arbitrarily complex and contain arbitrary operations among symbols, but only using the three operations: conjunction, disjunction and negation. For any Boolean expression, the truth table is obtained by creating a column for each symbol that appears in the expression, one final column with the evaluation of the expression, and for each row, one possible combination of the values of its symbols. Let us consider the following Boolean expression:

    LaTeX: ab+bcleft(b+c
ight)

    The truth table derived from this expression will contain four columns, one for each of the symbols LaTeX: a,:b, and LaTeX: c, an additional one for the result of the expression. There will be a row for any possible combination of values for the three variables. Since each of them can have two possible values, the table will contain eight rows:

    Truth table for ab + bc(b+c)
    abcResult
    0 0 0 0
    0 0 1 0
    0 1 0 0
    0 1 1 1
    1 0 0 0
    1 0 1 0
    1 1 0 1
    1 1 1 1

    The values of the fourth column are obtained by substituting each appearance of a symbol by its corresponding value in the row and applying the operation rules previously described. For example, in the third row, the values for the variables are LaTeX: a=0,:b=1,and LaTeX: c=0. If we replace these values in the expression, we obtain LaTeX: 01+10left(1+0
ight). We can start simplifying the expression by applying the operand rules:

    01 + 10(1 + 0) = 0*1 + 1*0*(1 + 0)
                   = 0 + 1*0*(1 + 0)
                   = 0 + 1*0*1
                   = 0 + 0
                   = 0

    And if we consider the values in the fourth row:

    01 + 11(1 + 1) = 0*1 + 1*1*(1 + 1)
                   = 0 + 1*1*(1 + 1)
                   = 0 + 1*1*1
                   = 0 + 1
                   = 1

    The process of substituting the symbols in an expression by a specific set of values is called evaluation. The last column of the truth table of a Boolean expression is then obtained by performing as many evaluations as possible combinations of values for its symbols.

    4.1.1. Identical Boolean Expressions

    Consider the two Boolean expressions

    LaTeX: e_1=xz'+y

    LaTeX: e_2=x'yz'+x'yz+xy'z'+xyz'+xyz

    Since both have the same symbols LaTeX: left(x,y,z
ight)we can write the truth table for both of them by simply adding two columns, one with the value of LaTeX: e_1 and another for LaTeX: e_2. A row of this table, then, will contain the values of each of the three symbols, and the result of each of the two expressions:

    Truth table for LaTeX: e_1 and LaTeX: e_2
    xyzLaTeX: e_1e 1LaTeX: e_2e 2
    0 0 0 0 0
    0 0 1 0 0
    0 1 0 1 1
    0 1 1 1 1
    1 0 0 1 1
    1 0 1 0 0
    1 1 0 1 1
    1 1 1 1 1

    As you can see, both columns are identical, or mathematically, LaTeX: e_1=e_2. In other words, the two expressions are equivalent. As a conclusion, given two Boolean expressions over the same set of symbols, the two expressions are equivalent if for every possible combination of values of its symbols, they produce the same results, or have identical truth table.

    But the previous result between an expression and its truth table can be interpreted also in the opposite direction. Given a truth table, there are several expressions that will correctly represent its values. In the previous example, the two expressions are equally valid representations of the truth table. If LaTeX: e_1 and LaTeX: e_2 are equivalent, which one would you prefer to manipulate in your calculations? The expression LaTeX: e_1 is definitively more compact than LaTeX: e_2 and therefore simpler to manipulate.

    Ideally, given a truth table, we would like to derive the most compact expression that represents the values on that table. Unfortunately, this procedure can only be done manually when the expressions have a small number of symbols (up to five). Remember that an expression with LaTeX: n symbols has LaTeX: 2^nrows in its truth table, and therefore, finding the most compact expression is prohibitive.

    4.1.2. Simplification of Boolean Expressions

    The reason why two Boolean expressions can be equivalent is because they have identical evaluation for each possible combination. The way the operations are defined in Boolean algebra makes some equivalences between simple expressions that can be used to simplify how an expression is written. The following eleven equivalences are called properties. Check that each one of them produce identical truth tables:

    Boolean identities
    Law NameExpression
    Identity 1*x = x,   0 + x = x
    Null 0*x = 0,   1 + x = 1
    Idempotent x*x = x,    x + x = x
    Inverse x*x' = 0,    x + x' = 1
    Commutative x*y = y*x,    x + y = y + x
    Redundancy x + x'y = x + y,    x(x'+y) = xy
    Associative (xy)z = x(yz),   (x+y) + z = x + (y+z)
    Distributive x + yz = (x+y)(x+z),    x(y+z) = xy + xz
    Absorption x(x+y) = x,    x + xy = x
    De Morgan (xy)' = x' + y',    (x+y)' = x'y'
    Double Complement (x')' = x

    These properties can be used to write Boolean expressions in ways that can be simplified. For example, let us consider the expression LaTeX: left(x+y
ight)left(x+y'
ight)left(xz'
ight)'. This three variable expression can be simplified with the following steps:

    LaTeX: left(x+y
ight)left(x+y'
ight)left(xz'
ight)'
    LaTeX: =left(x+y
ight)left(x+y'
ight)left(x'+z
ight)
    (De Morgan)
      LaTeX: =left(xx+xy'+xy+yy'
ight)left(x'+z
ight)
    (Distributive)
      LaTeX: =left(x+xy'+xy+0
ight)left(x'+z
ight)
    (Idempotent, Inverse)
      LaTeX: =left(x+xy'+xy
ight)left(x'+z
ight)
    (Identity)
      LaTeX: =xleft(x'+z
ight)
    (Absorption)
      LaTeX: =xx'+xz
    (Distributive)
      LaTeX: =xz
    (Inverse, Identity)

    This simplification process has transformed a three symbols LaTeX: left(x,y,z
ight) Boolean expression into a simpler expression with only two symbols LaTeX: left(x,z
ight). In this case, LaTeX: yy is said to be a redundant variable.

    Review questions for 4.1.2. Simplification of Boolean Expressions

    4.1.3. Canonical representations: sum of products, product of sums

    So far we have seen how to derive the truth table from an arbitrary Boolean expression. But, given a truth table, which expression should be derived from it if there are multiple equivalent ones? This problem is solved by defining what are known as canonical representations of a Boolean expression. Two of these representations are defined by the procedure to derive them from the truth table and are known as sum of products and product of sums.

    Sum of Products

    Given a truth table, the canonical Boolean expression as sum of products is obtained as follows:

    1. Select from the truth table only those rows that have the value in the last column equal to 1
    2. For each row selected in the previous step, write a product with as many symbols as they are in the function, and negate those with value 0 in the row (those with a value 1 are not negated).
    3. Add all these products together in a disjunction.

    Let us see this procedure with an example. Consider the following truth table:

    abcResult
    0 0 0 0
    0 0 1 0
    0 1 0 0
    0 1 1 1
    1 0 0 0
    1 0 1 0
    1 1 0 1
    1 1 1 1

    We first select only the three rows that have a value 1 in the last column. These rows have as values LaTeX: left(0,1,1,1
ight),:left(1,1,0,1
ight)and LaTeX: left(1,1,1,1
ight). For each of them we write the product following the convention that a one is replaced by a symbol, and a zero by a negated symbol (for this step, we ignore the value of the last column):

    LaTeX: left(0,1,1,1
ight):LaTeX: a'bc

    LaTeX: left(1,1,0,1
ight):LaTeX: abc'

    LaTeX: left(1,1,1,1
ight):LaTeX: abc

    And finally, the canonical representation as sum of products is obtained with the disjunction of all the products:

    LaTeX: a'bc+abc'+abc

     

    Product of Sums

    Given a truth table, the canonical Boolean expression as product of sums is obtained as follows:

    1. Select from the truth table only those rows that have the value in the last column equal to 0
    2. For each row selected in the previous step, write a sum with as many symbols as they are in the function, and negate those with value 1 in the row (those with value 0 are not negated).
    3. Multiply all these sums together in a conjunction.

    Let us see this procedure with the same truth table:

    abcResult
    0 0 0 0
    0 0 1 0
    0 1 0 0
    0 1 1 1
    1 0 0 0
    1 0 1 0
    1 1 0 1
    1 1 1 1

    We first select only the rows that have a value 0 in the last column: LaTeX: left(0,0,0,0
ight),:left(0,0,1,0
ight),:left(0,1,0,0
ight),:left(1,0,0,0
ight)and LaTeX: left(1,0,1,0
ight). For each of them we write the product following the convention that a one is replaced by a symbol, and a zero by a negated symbol (for this step, we ignore the value of the last column):

    LaTeX: left(0,0,0,0
ight):LaTeX: a+b+c

    LaTeX: left(0,0,1,0
ight) :LaTeX: a+b+c'

    LaTeX: left(0,1,0,0
ight):LaTeX: a+b'+c

    LaTeX: left(1,0,0,0
ight) :LaTeX: a'+b+c

    LaTeX: left(1,0,1,0
ight):LaTeX: a'+b+c'

    And finally, the canonical representation as product of sums is obtained with the conjunction of all the sums:

    LaTeX: left(a+b+c
ight)left(a+b+c'
ight)left(a+b'+c
ight)left(a'+b+c
ight)left(a'+b+c'
ight)

    By construction, the two canonical representations of the same function are equivalent.

    4.1.4. Boolean expressions as Boolean functions

    We have seen how Boolean expressions are obtained by combining a set of symbols (each of them can only take the values true and false) and three operations, conjunction, disjunction and negation. The truth table represents all possible values that the expression may take for every combination in the symbols. This table can be seen as the definition of a function that given the value for a set of symbols, returns 1 or 0.

    This is the reason why the terms Boolean expressions and Boolean functions are usually exchanged. In conventional algebra, a function is a relation between a set of inputs and a set of possible outputs. A Boolean expression defines such relation within the context of Boolean algebra.

    Boolean functions can be easily extended to have more than one result to what is known as a Multi-output Boolean Function. For example, consider the Boolean function defined by the following truth table:

    abcR1R2
    0 0 0 0 1
    0 0 1 0 1
    0 1 0 0 0
    0 1 1 1 0
    1 0 0 0 0
    1 0 1 0 1
    1 1 0 1 0
    1 1 1 1 1

    The truth table has simply been extended with an additional column representing the output of a second Boolean function. The overall structure can be considered as the definition of a Boolean function that receives the values of three symbols and produces two Boolean values.

    Analogously, each result column can be considered as an independent Boolean expression or function, and as such, any of its canonical representations or equivalent expressions can be derived.

    4.2. Logic Gates

    All digital circuits consist of 'building blocks' of units that manipulate bits following the Boolean algebraic rules. The reason is because current manufacturing procedures are capable of creating small circuits that detect only two possible values (high and low), and implement the operations of conjunction, disjunction and negation as described in Boolean algebra, using a few small devices called transistors.  Although each of these small circuits implements a simple operation, the combination of millions of them allow digital circuits to perform highly sophisticated operations at very high speeds (think of a circuit capable of reading a set of zeros and ones encoding a movie and playing it in a computer screen).

    The translation between Boolean algebra and digital logic requires only two definitions:

    • the correspondence between the values true and false and
    • how the operations of conjunction, disjunction and negation implemented by circuits.

    Mapping the values true and false to digital logic is trivial. At its basic level, digital circuits are only capable of detecting two values, or two levels of voltage: high and low. Thus, we decide to encode true as high, or 1, and false as low or zero.

    The circuits that implement Boolean algebra operations are commonly known as gates and are represented with the images shown in the following figure:

    Logic gates corresponding to conjunction, disjunction and negation

    Each gate behaves as the operations in the Boolean algebra previously described. Given the values at the inputs, they almost instantaneously produce the output value according to the operation. The truth table for the gates is identical to the truth table of the corresponding Boolean expressions.

    In digital logic, some basic combinations of these three operations are also considered basic gates and have their corresponding symbols. They are the NAND, NOR, XOR and XNOR gates. Their symbols, truth table and corresponding Boolean expressions are shown in the following figure.

    Additional basic logic gates: NAND, NOR, XOR, XNOR

    Download a PDF with the description of all the basic digital gates for your notesPreview the document.

    The number of inputs in these basic gates can also be extended to more than two. The same rules apply to obtain the value of the output. In reality, a gate with a large number of inputs requires a complex circuit and they are typically implemented using a combination of smaller gates.

    The gates also define implicitly a direction in which the operations are executed. The input signals are read, and then the output is produced. These gates can be connected so that the output of one gate becomes the input of another gate to create what is known as combinational circuits. The following figure shows an example of such circuit.

    Example of a 3 input combinational circuit

    Example of a 3 input combinational circuit

    The only restriction for a combinational circuit is that there cannot be a cycle from the output of a gate to the input of another gate that produced a signal that has been used previously. Another way of stating this property is that a combinational circuit only depends on the value of its inputs. The following figure shows two circuits that are not combinational because they contain cycles in some of it signals.

    Example of non-combinational circuits

    The following video describes various logic gates and how can they be connected to create a combinational circuit with the annotations produced during the video

    4.2.1. From a combinational circuit to a Boolean function

    The truth table of a combinational circuit is obtained similar to the case of a Boolean expression. The table will contain as many rows as the number of possible combinations in the inputs. Thus, for a circuit with LaTeX: n inputs, the corresponding truth table will have LaTeX: 2^nrows. The columns correspond with each of the inputs, and the last column corresponds to the output.

    For each row, the value of the last column is obtained applying the corresponding values to the input, and then propagating the signals through the gates applying their rules. Once the truth table has been obtained, the canonical representation as sum of products or products of sums can be derived as explained in the previous section.


     Example

    Consider the following circuit in the image given.

    Its corresponding truth table is

    xyzOutput
    0 0 0 0
    0 0 1 0
    0 1 0 1
    0 1 1 1
    1 0 0 0
    1 0 1 0
    1 1 0 1
    1 1 1 1

    The sum of products expression for this Boolean function is:

    LaTeX: left(x'yz'
ight)+left(x'yz
ight)+left(xyz'
ight)+left(xyz
ight)

    Analogously, the product of sums is:

    LaTeX: left(x+y+z
ight)left(x+y+z'
ight)left(x'+y+z
ight)left(x'+y+z'
ight)


    Review questions for 4.2.1 From a combinational circuit to a Boolean function

    4.2.2. From a Boolean Function to a Combinational Circuit

    One of the most important steps when designing a digital system is to derive a circuit from a Boolean function. Boolean algebra combined with encoding techniques allow us to translate decisions into operations over binary values (0 and 1), but ultimately, these operations need to be translated into gates and circuits. Searching the set of all possible implementations of a Boolean function and select the most appropriate is a highly complex problem commonly known as Logic Synthesis. The problem is so complex that there are numerous tools that support designers so that the process can be partially automated. These tools are part of the area known as Electronic Design Automation.

    Although finding the ideal set of logic gates implementing a Boolean function is complex, there are various techniques that can be applied to small circuits to illustrate the process. Let us consider the two canonical representations discussed in the previous sections: the sum of products, and the product of sums. We have seen how to obtain the truth table from a Boolean function. From the truth table we can derive the Boolean expression as a sum of products that is equivalent to the function. Each term in the sum of products can then be implemented as an AND gate using inverters for those inputs that are negated. We will require as many AND gates as products in the sum. The output of the digital circuit is then obtained by connecting the output of all the AND gates as inputs of a single OR gate.

    Let us illustrate the process with an example. Let us consider the function given by the expression LaTeX: xy+z''′. From the expression, the following truth table is derived:

    xyzOutput
    0 0 0 1
    0 0 1 0
    0 1 0 1
    0 1 1 0
    1 0 0 1
    1 0 1 0
    1 1 0 1
    1 1 1 1

    The sum of products derived from the table is:LaTeX: x'y'z'+x'yz'+xy'z'+xyz'+xyz

    Transforming each product into an AND gate, and combining them with an OR gate, the resulting circuit is in the given image:

    But even though the process to derive this implementation of the Boolean expression is correct, in other words, the resulting circuit has the derived truth table, are there any other possible implementations? Are there any other ways to connect gates so that the resulting circuit also has the same truth table?

    In this example the initial Boolean expression itself gives us an alternative. The expression can be directly translated into the circuit shown in the left side of the following figure.

    Two possible implementations of the same Boolean function

    Even though both circuits are equivalent (that is, they have exactly the same truth table), can you think of any criteria that would make you select one over the other?

    The following video illustrates how to create a combinational circuit from the Boolean expression by obtaining its sum of products form with the annotations produced during the videoPreview the document.

    4.3. Design Criteria for Digital Circuits

    Nowadays, the process to implement logic gates uses silicon, which is a semi-conductor component. Using different particles that are etched in a surface and applying certain voltages, a small area can either be isolated (no current goes across) or connected (a current traverses it). This technique is the basis to create transistors, and logic gates can be implemented connecting various transistors. The following figure shows how a NAND gate is implemented in a silicon chip.

    Physical layout of a 2-input NAND gate in a silicon chip

    As you can see, four types of components are used: metal (which can be laid out in various layers), poly, n-diffusion, and p-diffusion. The size of these connections determine the space occupied by a gate and the number of gates that can fit in a chip.

    The manufacturing technology over the last decades has successfully reduced the area required to implement a transistor (and therefore the area occupied by a gate) at a pace of half the space approximately every two years. In other words, the space occupied by a gate is approximately 1/1048576 of the space it occupied forty years ago. This is the reason why the circuits are known as integrated circuits or chips. One of the consequences of such a large scale of integration is the possibility of designing circuits that contain hundreds of millions of transistors. Some of these circuits are the microprocessors powering the digital devices in use these days.

    Some of the chips are encapsulated in a case with metallic pins for the connections. The following figure shows a simple chip containing 4 NAND gates. Note that in order for the gates to operate correctly, the pins number 14 and 7 must be connected to 5 volts and ground respectively.

    Chip with four NAND gates Dicklyon, Wikipedia

    There are two important facts derived from how the circuits are built: gates occupy an area in the silicon chip, and take some time to switch between the isolated and conducting stages. Various consequences affecting logic design can be derived from these facts:

    • Circuits with a larger number of gates will react slower than those with smaller number of gates.
    • Smaller circuits will occupy less space in the chip.
    • Signals have to travel between gates, the longer the connection, the larger the delay (even though it will be a small amount of time).
    • Larger gates, that is, those with a large number of inputs have a larger switching time.
    • Each gate consumes power while switching its value. The more gates in a circuit, the more power it consumes (think about the battery of your mobile phone).
    • Speed of transmission of signals

    These and other consequences is what it drives the logic design process. Circuits need to be as compact as possible (least number of gates), with those gates close to each other, and switch values as fast as possible.

    4.4. Examples of Combinational Circuits

    There are several digital circuits that implement very common Boolean operations such as addition, shifting, multiplexing, etc.

    4.4.1. Two Bit Adder with Carry-in and Carry-out

    One of the most useful arithmetic operation is to add two natural numbers. In Boolean algebra the addition of two numbers x and y has the following truth table:

    ABS
    0 0 0
    0 1 1
    1 0 1
    1 1 0

    The addition follows the same rules as conventional algebra. If we take a look at the last row of the table, if both numbers are one, the result of the sum is zero, but, if adding numbers with more bits, a carry value would be produced that should be added to the next digit. We can extend the truth table with a second Boolean expression telling us when such carry is produced. The resulting table is:

    ABSCarry
    0 0 0 0
    0 1 1 0
    1 0 1 0
    1 1 0 1

    Now imagine that you are performing the addition of numbers of various binary digits. For a pair of bits in the middle of the operation, we may have a carry bit produced by the previous bit addition, and propagate a carry bit for the next bit addition. The following figure shows this situation when adding the third bits of two numbers.

    Addition of two bits and its possible carry values

    The previous truth table can then be extended to include an additional input which is the carry produced by the previous addition. The resulting three input, two output truth table is:

    InputOutput
    A B Cin S Cout
    0 0 0 0 0
    0 0 1 1 0
    0 1 0 1 0
    0 1 1 0 1
    1 0 0 1 0
    1 0 1 0 1
    1 1 0 0 1
    1 1 1 1 1

    The translation of these two truth tables (one for each output) to digital gates can be done using the canonical representations (sum of products or product of sums) or with arbitrary gates. The following figure shows a compact implementation of these two functions with only 5 gates:

    2-bit full adder

    Copyright © The University of Sydney. Unless otherwise indicated, 3rd party material has been reproduced and communicated to you by or on behalf of the University of Sydney in accordance with section 113P of the Copyright Act 1968 (Act). The material in this communication may be subject to copyright under the Act. Any further reproduction or communication of this material by you may be the subject of copyright protection under the Act. Do not remove this notice.

  • 相关阅读:
    nginx系列11:负载均衡哈希算法ip_hash与hash模块
    nginx系列10:通过upstream模块选择上游服务器和负载均衡策略round-robin
    nginx系列9:HTTP反向代理请求处理流程
    css 滚动条样式
    Vue优化:常见会导致内存泄漏问题及优化
    vue自定义指令导致的内存泄漏问题解决
    vue动态绑定class的几种方式
    前端知识点回顾之重点篇——CSS中flex布局
    Javascript数组操作
    pc端常用电脑屏幕 ((响应式PC端媒体查询)电脑屏幕分辨率尺寸大全)
  • 原文地址:https://www.cnblogs.com/geeksongs/p/14118547.html
Copyright © 2011-2022 走看看